1 | <?php |
||
25 | class Array2Object |
||
26 | { |
||
27 | /** |
||
28 | * @var array|ValueParserInterface |
||
29 | */ |
||
30 | private static $parsers; |
||
31 | |||
32 | /** |
||
33 | * registerParser |
||
34 | * |
||
35 | * @param ValueParserInterface|array $parsers |
||
36 | */ |
||
37 | static public function registerParser($parsers) |
||
47 | |||
48 | /** |
||
49 | * createObject |
||
50 | * |
||
51 | * @param string $class class to create object or instance |
||
52 | * @param array $data array of data |
||
53 | * |
||
54 | * @return mixed |
||
55 | * |
||
56 | * @throws \InvalidArgumentException |
||
57 | */ |
||
58 | static public function createObject($class, array $data) |
||
70 | |||
71 | /** |
||
72 | * @param object $object object instance to populate |
||
73 | * @param array $data array of data to apply |
||
74 | * |
||
75 | * @throws \InvalidArgumentException |
||
76 | */ |
||
77 | static public function populate($object, array $data) |
||
99 | |||
100 | /** |
||
101 | * setup |
||
102 | */ |
||
103 | static private function setup() |
||
116 | |||
117 | /** |
||
118 | * Get array of class properties including parents private properties |
||
119 | * |
||
120 | * @param \ReflectionClass $refClass |
||
121 | * |
||
122 | * @return array|\ReflectionProperty[] |
||
123 | */ |
||
124 | static private function getClassProperties(\ReflectionClass $refClass) |
||
142 | |||
143 | /** |
||
144 | * @param $propertyName |
||
145 | * @param $givenName |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | static private function isSameProperty($propertyName, $givenName) |
||
162 | |||
163 | /** |
||
164 | * Parse a value using given types |
||
165 | * |
||
166 | * @param mixed $value |
||
167 | * @param array $types |
||
168 | * @param \ReflectionProperty $property |
||
169 | * @param object $object |
||
170 | * |
||
171 | * @return array|bool|float|int|string |
||
172 | */ |
||
173 | static private function parseValue($value, $types, \ReflectionProperty $property, $object) |
||
194 | |||
195 | /** |
||
196 | * @param $name |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | static private function camelize($name) |
||
204 | |||
205 | /** |
||
206 | * @param \ReflectionProperty $property |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | static private function getPropertyTypes(\ReflectionProperty $property) |
||
221 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.