Debian Codegraph @

lib/3rdParty/composer/symfony/property-info/PropertyWriteInfo.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\PropertyInfo;
13
14 /**
15 * The write mutator defines how a property can be written.
16 *
17 * @author Joel Wurtz <[email protected]>
18 */
19 final class PropertyWriteInfo
20 {
21 public const TYPE_NONE = 'none';
22 public const TYPE_METHOD = 'method';
23 public const TYPE_PROPERTY = 'property';
24 public const TYPE_ADDER_AND_REMOVER = 'adder_and_remover';
25 public const TYPE_CONSTRUCTOR = 'constructor';
26
27 public const VISIBILITY_PUBLIC = 'public';
28 public const VISIBILITY_PROTECTED = 'protected';
29 public const VISIBILITY_PRIVATE = 'private';
30
31 private ?self $adderInfo = null;
32 private ?self $removerInfo = null;
33 private array $errors = [];
34
35 public function __construct(
36 private readonly string $type = self::TYPE_NONE,
37 private readonly ?string $name = null,
38 private readonly ?string $visibility = null,
39 private readonly ?bool $static = null,
40 ) {
41 }
42
43 public function getType(): string
44 {
45 return $this->type;
46 }
47
48 public function getName(): string
49 {
50 if (null === $this->name) {
51 throw new \LogicException("Calling getName() when having a mutator of type {$this->type} is not tolerated.");
52 }
53
54 return $this->name;
55 }
56
57 public function setAdderInfo(self $adderInfo): void
58 {
59 $this->adderInfo = $adderInfo;
60 }
61
62 public function getAdderInfo(): self
63 {
64 if (null === $this->adderInfo) {
65 throw new \LogicException("Calling getAdderInfo() when having a mutator of type {$this->type} is not tolerated.");
66 }
67
68 return $this->adderInfo;
69 }
70
71 public function setRemoverInfo(self $removerInfo): void
72 {
73 $this->removerInfo = $removerInfo;
74 }
75
76 public function getRemoverInfo(): self
77 {
78 if (null === $this->removerInfo) {
79 throw new \LogicException("Calling getRemoverInfo() when having a mutator of type {$this->type} is not tolerated.");
80 }
81
82 return $this->removerInfo;
83 }
84
85 public function getVisibility(): string
86 {
87 if (null === $this->visibility) {
88 throw new \LogicException("Calling getVisibility() when having a mutator of type {$this->type} is not tolerated.");
89 }
90
91 return $this->visibility;
92 }
93
94 public function isStatic(): bool
95 {
96 if (null === $this->static) {
97 throw new \LogicException("Calling isStatic() when having a mutator of type {$this->type} is not tolerated.");
98 }
99
100 return $this->static;
101 }
102
103 public function setErrors(array $errors): void
104 {
105 $this->errors = $errors;
106 }
107
108 public function getErrors(): array
109 {
110 return $this->errors;
111 }
112
113 public function hasErrors(): bool
114 {
115 return (bool) \count($this->errors);
116 }
117 }