1 | <?php |
||
27 | class Array2Object |
||
28 | { |
||
29 | /** |
||
30 | * @var array|ValueParserInterface |
||
31 | */ |
||
32 | private static $parsers; |
||
33 | |||
34 | /** |
||
35 | * @var PropertyMatcherInterface |
||
36 | */ |
||
37 | private static $propertyMatcher; |
||
38 | |||
39 | /** |
||
40 | * registerParser |
||
41 | * |
||
42 | * @param ValueParserInterface|array $parsers |
||
43 | */ |
||
44 | static public function registerParser($parsers) |
||
54 | |||
55 | /** |
||
56 | * @param PropertyMatcherInterface $propertyMatcher |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public static function setPropertyMatcher(PropertyMatcherInterface $propertyMatcher) |
||
64 | |||
65 | /** |
||
66 | * createObject |
||
67 | * |
||
68 | * @param string $class class to create object or instance |
||
69 | * @param array $data array of data |
||
70 | * |
||
71 | * @return mixed |
||
72 | * |
||
73 | * @throws \InvalidArgumentException |
||
74 | */ |
||
75 | static public function createObject($class, array $data) |
||
87 | |||
88 | /** |
||
89 | * @param object $object object instance to populate |
||
90 | * @param array $data array of data to apply |
||
91 | * |
||
92 | * @throws \InvalidArgumentException |
||
93 | */ |
||
94 | static public function populate($object, array $data) |
||
116 | |||
117 | /** |
||
118 | * setup |
||
119 | */ |
||
120 | static private function setup() |
||
137 | |||
138 | /** |
||
139 | * Get array of class properties including parents private properties |
||
140 | * |
||
141 | * @param \ReflectionClass $refClass |
||
142 | * |
||
143 | * @return array|\ReflectionProperty[] |
||
144 | */ |
||
145 | static private function getClassProperties(\ReflectionClass $refClass) |
||
163 | |||
164 | /** |
||
165 | * Parse a value using given types |
||
166 | * |
||
167 | * @param mixed $value |
||
168 | * @param array $types |
||
169 | * @param \ReflectionProperty $property |
||
170 | * @param object $object |
||
171 | * |
||
172 | * @return array|bool|float|int|string |
||
173 | */ |
||
174 | static private function parseValue($value, $types, \ReflectionProperty $property, $object) |
||
195 | |||
196 | /** |
||
197 | * @param \ReflectionProperty $property |
||
198 | * |
||
199 | * @return array |
||
200 | */ |
||
201 | static private function getPropertyTypes(\ReflectionProperty $property) |
||
212 | } |
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.