@@ -225,6 +225,9 @@ |
||
225 | 225 | : new ObjectType($context); |
226 | 226 | } |
227 | 227 | |
228 | + /** |
|
229 | + * @param string $var |
|
230 | + */ |
|
228 | 231 | public function scalarToType($var) : ?AbstractType |
229 | 232 | { |
230 | 233 | switch (strtolower($var)) |
@@ -89,8 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function parseObjectName($var) : ObjectType |
91 | 91 | { |
92 | - return $this->parse(str_replace |
|
93 | - ( |
|
92 | + return $this->parse(str_replace( |
|
94 | 93 | [GenericNameProvider::BASE, '_g', '_e', '_c'], |
95 | 94 | ['', '<', '>', ','], |
96 | 95 | get_class($var) |
@@ -135,7 +134,7 @@ discard block |
||
135 | 134 | $item = $stack->pop(); |
136 | 135 | if ($value{$i - 1} !== '>') |
137 | 136 | { |
138 | - $item->generics[] =$this->resolveName(); |
|
137 | + $item->generics[] = $this->resolveName(); |
|
139 | 138 | } |
140 | 139 | |
141 | 140 | if ($i + 1 !== strlen($value) && $value{$i + 1} === '[') |
@@ -183,7 +182,7 @@ discard block |
||
183 | 182 | } |
184 | 183 | elseif ($i + 2 !== strlen($value)) |
185 | 184 | { |
186 | - if (!in_array($value{$i + 2}, ['>',','])) |
|
185 | + if (!in_array($value{$i + 2}, ['>', ','])) |
|
187 | 186 | { |
188 | 187 | throw new \Exception('Unexpected char after collection'); |
189 | 188 | } |
@@ -226,7 +225,7 @@ discard block |
||
226 | 225 | : new ObjectType($context); |
227 | 226 | } |
228 | 227 | |
229 | - public function scalarToType($var) : ?AbstractType |
|
228 | + public function scalarToType($var) : ? AbstractType |
|
230 | 229 | { |
231 | 230 | switch (strtolower($var)) |
232 | 231 | { |
@@ -20,10 +20,8 @@ |
||
20 | 20 | use Spaark\CompositeUtils\Model\Reflection\Type\FloatType; |
21 | 21 | use Spaark\CompositeUtils\Model\Reflection\Type\MixedType; |
22 | 22 | use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType; |
23 | -use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType; |
|
24 | 23 | use Spaark\CompositeUtils\Model\Reflection\Type\StringType; |
25 | 24 | use Spaark\CompositeUtils\Model\Reflection\Type\GenericType; |
26 | -use Spaark\CompositeUtils\Model\Generic\GenericContext; |
|
27 | 25 | use Spaark\CompositeUtils\Exception\MissingContextException; |
28 | 26 | use Spaark\CompositeUtils\Traits\HasGenericContextTrait; |
29 | 27 | use Spaark\CompositeUtils\Model\ClassName; |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | return $this->inferGenericName($reflect); |
64 | 64 | } |
65 | 65 | |
66 | - throw new \DomainException |
|
67 | - ( |
|
66 | + throw new \DomainException( |
|
68 | 67 | 'Unknown type: ' . get_class($reflect) |
69 | 68 | ); |
70 | 69 | } |
@@ -101,8 +100,7 @@ discard block |
||
101 | 100 | $items[] = $this->inferName($generic); |
102 | 101 | } |
103 | 102 | |
104 | - return new ClassName |
|
105 | - ( |
|
103 | + return new ClassName( |
|
106 | 104 | self::BASE . $reflect->classname |
107 | 105 | . '_g' . implode('_c', $items) . '_e' |
108 | 106 | ); |
@@ -17,11 +17,6 @@ |
||
17 | 17 | use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite; |
18 | 18 | use Spaark\CompositeUtils\Model\Reflection\ReflectionProperty; |
19 | 19 | use Spaark\CompositeUtils\Model\Reflection\Type\ObjectType; |
20 | -use Spaark\CompositeUtils\Model\Reflection\Type\MixedType; |
|
21 | -use Spaark\CompositeUtils\Model\Reflection\Type\StringType; |
|
22 | -use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType; |
|
23 | -use Spaark\CompositeUtils\Model\Reflection\Type\BooleanType; |
|
24 | -use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType; |
|
25 | 20 | use Spaark\CompositeUtils\Model\Reflection\Type\ScalarType; |
26 | 21 | use Spaark\CompositeUtils\Model\Reflection\Type\AbstractType; |
27 | 22 | use Spaark\CompositeUtils\Exception\CannotWritePropertyException; |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | if (!isset($args[$i])) |
71 | 71 | { |
72 | - throw new MissingRequiredParameterException |
|
73 | - ( |
|
72 | + throw new MissingRequiredParameterException( |
|
74 | 73 | get_class($this->object), |
75 | 74 | $property->name |
76 | 75 | ); |
@@ -148,14 +147,12 @@ discard block |
||
148 | 147 | { |
149 | 148 | if (!$this->reflect->properties->containsKey($property)) |
150 | 149 | { |
151 | - throw new CannotWritePropertyException |
|
152 | - ( |
|
150 | + throw new CannotWritePropertyException( |
|
153 | 151 | get_class($this->object), $property |
154 | 152 | ); |
155 | 153 | } |
156 | 154 | |
157 | - $this->setAnyValue |
|
158 | - ( |
|
155 | + $this->setAnyValue( |
|
159 | 156 | $this->reflect->properties[$property], |
160 | 157 | $value |
161 | 158 | ); |
@@ -193,8 +190,7 @@ discard block |
||
193 | 190 | * @param ScalarType $valueType The scalar type |
194 | 191 | * @param mixed $value The value to set |
195 | 192 | */ |
196 | - private function setScalarValue |
|
197 | - ( |
|
193 | + private function setScalarValue( |
|
198 | 194 | ReflectionProperty $property, |
199 | 195 | ScalarType $valueType, |
200 | 196 | $value |
@@ -204,16 +200,14 @@ discard block |
||
204 | 200 | |
205 | 201 | if (is_scalar($value)) |
206 | 202 | { |
207 | - $this->setRawValue |
|
208 | - ( |
|
203 | + $this->setRawValue( |
|
209 | 204 | $property->name, |
210 | 205 | $property->type->cast($value) |
211 | 206 | ); |
212 | 207 | } |
213 | 208 | elseif (is_object($value) && method_exists([$value, $method])) |
214 | 209 | { |
215 | - $this->setScalarValue |
|
216 | - ( |
|
210 | + $this->setScalarValue( |
|
217 | 211 | $property, |
218 | 212 | $valueType, |
219 | 213 | $value->$method() |
@@ -231,14 +225,12 @@ discard block |
||
231 | 225 | * @param ReflectionProperty $property The property being set |
232 | 226 | * @param AbstractType $valueType The value being set |
233 | 227 | */ |
234 | - private function throwError |
|
235 | - ( |
|
228 | + private function throwError( |
|
236 | 229 | ReflectionProperty $property, |
237 | 230 | AbstractType $valueType |
238 | 231 | ) |
239 | 232 | { |
240 | - throw new IllegalPropertyTypeException |
|
241 | - ( |
|
233 | + throw new IllegalPropertyTypeException( |
|
242 | 234 | get_class($this->object), |
243 | 235 | $property->name, |
244 | 236 | $property->type, |
@@ -87,15 +87,13 @@ discard block |
||
87 | 87 | if ($building) |
88 | 88 | { |
89 | 89 | $this->buildProperty($property); |
90 | - } |
|
91 | - else |
|
90 | + } else |
|
92 | 91 | { |
93 | 92 | if (isset($args[$i])) |
94 | 93 | { |
95 | 94 | $this->setAnyValue($property, $args[$i]); |
96 | 95 | $i++; |
97 | - } |
|
98 | - else |
|
96 | + } else |
|
99 | 97 | { |
100 | 98 | $building = true; |
101 | 99 | $this->buildProperty($property); |
@@ -119,8 +117,7 @@ discard block |
||
119 | 117 | if (!$property->type instanceof ObjectType) |
120 | 118 | { |
121 | 119 | $this->setAnyValue($property, 0); |
122 | - } |
|
123 | - elseif ($property->builtInConstructor) |
|
120 | + } elseif ($property->builtInConstructor) |
|
124 | 121 | { |
125 | 122 | $class = (string)$property->type->classname; |
126 | 123 | $this->setRawValue($property->name, new $class()); |
@@ -175,12 +172,10 @@ discard block |
||
175 | 172 | if ($comparator->compatible($property->type, $valueType)) |
176 | 173 | { |
177 | 174 | $this->setRawValue($property->name, $value); |
178 | - } |
|
179 | - elseif ($property->type instanceof ScalarType) |
|
175 | + } elseif ($property->type instanceof ScalarType) |
|
180 | 176 | { |
181 | 177 | $this->setScalarValue($property, $valueType, $value); |
182 | - } |
|
183 | - else |
|
178 | + } else |
|
184 | 179 | { |
185 | 180 | $this->throwError($property, $valueType); |
186 | 181 | } |
@@ -209,8 +204,7 @@ discard block |
||
209 | 204 | $property->name, |
210 | 205 | $property->type->cast($value) |
211 | 206 | ); |
212 | - } |
|
213 | - elseif (is_object($value) && method_exists([$value, $method])) |
|
207 | + } elseif (is_object($value) && method_exists([$value, $method])) |
|
214 | 208 | { |
215 | 209 | $this->setScalarValue |
216 | 210 | ( |
@@ -218,8 +212,7 @@ discard block |
||
218 | 212 | $valueType, |
219 | 213 | $value->$method() |
220 | 214 | ); |
221 | - } |
|
222 | - else |
|
215 | + } else |
|
223 | 216 | { |
224 | 217 | $this->throwError($property, $valueType); |
225 | 218 | } |
@@ -46,12 +46,10 @@ |
||
46 | 46 | ) |
47 | 47 | { |
48 | 48 | return true; |
49 | - } |
|
50 | - elseif ($parent instanceof ScalarType) |
|
49 | + } elseif ($parent instanceof ScalarType) |
|
51 | 50 | { |
52 | 51 | return get_class($parent) === get_class($child); |
53 | - } |
|
54 | - elseif ($parent instanceof ObjectType) |
|
52 | + } elseif ($parent instanceof ObjectType) |
|
55 | 53 | { |
56 | 54 | if |
57 | 55 | ( |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | * @param AbstractType $child |
36 | 36 | * @return boolean |
37 | 37 | */ |
38 | - public function compatible |
|
39 | - ( |
|
38 | + public function compatible( |
|
40 | 39 | AbstractType $parent, |
41 | 40 | AbstractType $child |
42 | 41 | ) |
@@ -47,8 +46,7 @@ discard block |
||
47 | 46 | $parent = $this->getGenericType($parent); |
48 | 47 | } |
49 | 48 | |
50 | - if |
|
51 | - ( |
|
49 | + if ( |
|
52 | 50 | ($child instanceof NullType && $parent->nullable) || |
53 | 51 | ($parent instanceof MixedType) |
54 | 52 | ) |
@@ -61,11 +59,9 @@ discard block |
||
61 | 59 | } |
62 | 60 | elseif ($parent instanceof ObjectType) |
63 | 61 | { |
64 | - if |
|
65 | - ( |
|
62 | + if ( |
|
66 | 63 | $child instanceof ObjectType && |
67 | - is_a |
|
68 | - ( |
|
64 | + is_a( |
|
69 | 65 | $child->classname->__toString(), |
70 | 66 | $parent->classname->__toString(), |
71 | 67 | true |
@@ -74,8 +70,7 @@ discard block |
||
74 | 70 | { |
75 | 71 | foreach ($child->generics as $i => $generic) |
76 | 72 | { |
77 | - $compare = $this->compatible |
|
78 | - ( |
|
73 | + $compare = $this->compatible( |
|
79 | 74 | $parent->generics[$i], |
80 | 75 | $generic |
81 | 76 | ); |
@@ -92,8 +87,7 @@ discard block |
||
92 | 87 | return false; |
93 | 88 | } |
94 | 89 | |
95 | - throw new \DomainException |
|
96 | - ( |
|
90 | + throw new \DomainException( |
|
97 | 91 | 'Unknown type: ' . get_class($parent) |
98 | 92 | ); |
99 | 93 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $i = 0; |
83 | 83 | |
84 | 84 | $code = |
85 | - 'namespace ' . $class->namespace . ';' |
|
85 | + 'namespace ' . $class->namespace . ';' |
|
86 | 86 | . 'class ' . $class->classname . ' ' |
87 | 87 | . 'extends \\' . $originalClass |
88 | 88 | . '{'; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | return |
121 | - ($method->scope === 'static' ? 'static ' : '') |
|
121 | + ($method->scope === 'static' ? 'static ' : '') |
|
122 | 122 | . 'function ' . $method->name |
123 | 123 | . '(' . implode(',', $params) . '){' |
124 | 124 | . '__generic_' . $method->name |
@@ -16,16 +16,9 @@ |
||
16 | 16 | |
17 | 17 | use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite; |
18 | 18 | use Spaark\CompositeUtils\Model\Reflection\ReflectionMethod; |
19 | -use Spaark\CompositeUtils\Model\Reflection\Type\BooleanType; |
|
20 | -use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType; |
|
21 | -use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType; |
|
22 | -use Spaark\CompositeUtils\Model\Reflection\Type\MixedType; |
|
23 | 19 | use Spaark\CompositeUtils\Model\Reflection\Type\ObjectType; |
24 | -use Spaark\CompositeUtils\Model\Reflection\Type\StringType; |
|
25 | -use Spaark\CompositeUtils\Model\Reflection\Type\GenericType; |
|
26 | 20 | use Spaark\CompositeUtils\Model\Generic\GenericContext; |
27 | 21 | use Spaark\CompositeUtils\Model\ClassName; |
28 | -use Spaark\CompositeUtils\Service\RawPropertyAccessor; |
|
29 | 22 | use Spaark\CompositeUtils\Service\GenericNameProvider; |
30 | 23 | use Spaark\CompositeUtils\Traits\AutoConstructPropertyAccessTrait; |
31 | 24 |
@@ -62,7 +62,7 @@ |
||
62 | 62 | public function __toString() |
63 | 63 | { |
64 | 64 | return |
65 | - ($this->namespace ? $this->namespace . '\\' : '') |
|
65 | + ($this->namespace ? $this->namespace . '\\' : '') |
|
66 | 66 | . $this->classname; |
67 | 67 | } |
68 | 68 |
@@ -59,8 +59,7 @@ |
||
59 | 59 | */ |
60 | 60 | public function equals($type) : bool |
61 | 61 | { |
62 | - if |
|
63 | - ( |
|
62 | + if ( |
|
64 | 63 | $type instanceof ObjectType && |
65 | 64 | $type->classname->equals($this->classname) && |
66 | 65 | $type->generics->size() === $this->generics->size() |