1 | <?php |
||
18 | class Array2Object |
||
19 | { |
||
20 | /** |
||
21 | * @var Array2ObjectContext |
||
22 | */ |
||
23 | private $context; |
||
24 | |||
25 | /** |
||
26 | * Array2Object constructor. |
||
27 | */ |
||
28 | public function __construct(Array2ObjectContext $context) |
||
32 | |||
33 | /** |
||
34 | * @return Array2ObjectContext |
||
35 | */ |
||
36 | public function getContext() |
||
40 | |||
41 | /** |
||
42 | * @param Array2ObjectContext $context |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | public function setContext(Array2ObjectContext $context) |
||
52 | |||
53 | /** |
||
54 | * createObject |
||
55 | * |
||
56 | * @param string $class class to create object or instance |
||
57 | * @param array $data array of data |
||
58 | * |
||
59 | * @return mixed |
||
60 | * |
||
61 | * @throws \InvalidArgumentException |
||
62 | */ |
||
63 | public function createObject($class, array $data) |
||
75 | |||
76 | /** |
||
77 | * @param object $object object instance to populate |
||
78 | * @param array $data array of data to apply |
||
79 | * |
||
80 | * @throws \InvalidArgumentException |
||
81 | */ |
||
82 | public function populate($object, array $data) |
||
106 | |||
107 | /** |
||
108 | * Get array of class properties including parents private properties |
||
109 | * |
||
110 | * @param \ReflectionClass $refClass |
||
111 | * |
||
112 | * @return array|\ReflectionProperty[] |
||
113 | */ |
||
114 | private function getClassProperties(\ReflectionClass $refClass) |
||
132 | |||
133 | /** |
||
134 | * Parse a value using given types |
||
135 | * |
||
136 | * @param mixed $value |
||
137 | * @param array $types |
||
138 | * @param \ReflectionProperty $property |
||
139 | * @param object $object |
||
140 | * |
||
141 | * @return array|bool|float|int|string |
||
142 | */ |
||
143 | private function parseValue($value, $types, \ReflectionProperty $property, $object) |
||
164 | |||
165 | /** |
||
166 | * @param \ReflectionProperty $property |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | private function getPropertyTypes(\ReflectionProperty $property) |
||
181 | } |
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.