| 1 | <?php |
||
| 2 | |||
| 3 | namespace Sf4\Populator; |
||
| 4 | |||
| 5 | class PropertyMetadata |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Setter |
||
| 9 | * @var string |
||
| 10 | */ |
||
| 11 | protected $setter; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Aliases |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | protected $aliases = array(); |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Context |
||
| 21 | * @var HydratorContext |
||
| 22 | */ |
||
| 23 | protected $context; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Ignored |
||
| 27 | * @var boolean |
||
| 28 | */ |
||
| 29 | protected $ignored = false; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Property name |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $name; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Constructor |
||
| 39 | * |
||
| 40 | * @param string $name Property name |
||
| 41 | */ |
||
| 42 | 3 | public function __construct($name) |
|
| 43 | { |
||
| 44 | 3 | $this->name = $name; |
|
| 45 | 3 | $this->setter = sprintf("set%s", $name); |
|
| 46 | 3 | } |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Get Name |
||
| 50 | * |
||
| 51 | * @return string Property name |
||
| 52 | */ |
||
| 53 | 3 | public function getName() |
|
| 54 | { |
||
| 55 | 3 | return $this->name; |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Set Name |
||
| 60 | * |
||
| 61 | * @param string $name Property name |
||
| 62 | * @return PropertyMetadata |
||
| 63 | */ |
||
| 64 | public function setName($name) |
||
| 65 | { |
||
| 66 | $this->name = $name; |
||
| 67 | |||
| 68 | return $this; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Get Setter |
||
| 73 | * |
||
| 74 | * @return string Setter name |
||
| 75 | */ |
||
| 76 | 3 | public function getSetter() |
|
| 77 | { |
||
| 78 | 3 | return $this->setter; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Set Setter |
||
| 83 | * |
||
| 84 | * @param string $setter Setter name |
||
| 85 | * @return PropertyMetadata |
||
| 86 | */ |
||
| 87 | public function setSetter($setter) |
||
| 88 | { |
||
| 89 | $this->setter = $setter; |
||
| 90 | |||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get Aliases |
||
| 96 | * |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | public function getAliases() |
||
| 100 | { |
||
| 101 | return $this->aliases; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Set Aliases |
||
| 106 | * |
||
| 107 | * @param array $aliases An array of alias |
||
| 108 | */ |
||
| 109 | public function setAliases(array $aliases) |
||
| 110 | { |
||
| 111 | $this->aliases = $aliases; |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Add Alias |
||
| 116 | * |
||
| 117 | * @param string $alias Alias |
||
| 118 | */ |
||
| 119 | public function addAlias($alias) |
||
| 120 | { |
||
| 121 | $this->aliases[] = $alias; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Has Alias |
||
| 126 | * |
||
| 127 | * @param string $alias Alias name |
||
| 128 | * |
||
| 129 | * @return boolean |
||
| 130 | */ |
||
| 131 | 3 | public function hasAlias($alias) |
|
| 132 | { |
||
| 133 | 3 | return in_array($alias, $this->aliases); |
|
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Get Context |
||
| 138 | * |
||
| 139 | * @return HydratorContextInterface Context |
||
| 140 | */ |
||
| 141 | 3 | public function getContext() |
|
| 142 | { |
||
| 143 | 3 | return $this->context; |
|
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Set Context |
||
| 148 | * |
||
| 149 | * @param HydratorContextInterface $context Context |
||
| 150 | */ |
||
| 151 | public function setContext(HydratorContextInterface $context) |
||
| 152 | { |
||
| 153 | $this->context = $context; |
||
|
0 ignored issues
–
show
|
|||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Is Ignored |
||
| 158 | * |
||
| 159 | * @return boolean |
||
| 160 | */ |
||
| 161 | 3 | public function isIgnored() |
|
| 162 | { |
||
| 163 | 3 | return $this->ignored; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Set Ignored |
||
| 168 | * |
||
| 169 | * @param boolean $ignored Whether to ignore the property |
||
| 170 | */ |
||
| 171 | public function setIgnored($ignored) |
||
| 172 | { |
||
| 173 | $this->ignored = !!$ignored; |
||
| 174 | } |
||
| 175 | } |
||
| 176 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.