@@ -103,6 +103,10 @@ |
||
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | + /** |
|
107 | + * @param string $name |
|
108 | + * @param \Closure $cast |
|
109 | + */ |
|
106 | 110 | private function setScalarValue($property, $value, $name, $cast) |
107 | 111 | { |
108 | 112 | $method = '__to' . $name; |
@@ -8,7 +8,6 @@ |
||
8 | 8 | use Spaark\CompositeUtils\Model\Reflection\Type\StringType; |
9 | 9 | use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType; |
10 | 10 | use Spaark\CompositeUtils\Model\Reflection\Type\BooleanType; |
11 | -use Spaark\CompositeUtils\Model\Reflection\Type\FloatType; |
|
12 | 11 | use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType; |
13 | 12 | use Spaark\CompositeUtils\Exception\CannotWritePropertyException; |
14 | 13 | use Spaark\CompositeUtils\Exception\IllegalPropertyTypeException; |
@@ -36,8 +36,7 @@ discard block |
||
36 | 36 | { |
37 | 37 | if (!$this->reflect->properties->contains($property)) |
38 | 38 | { |
39 | - throw new CannotWritePropertyException |
|
40 | - ( |
|
39 | + throw new CannotWritePropertyException( |
|
41 | 40 | get_class($this->object), $property |
42 | 41 | ); |
43 | 42 | } |
@@ -113,8 +112,7 @@ discard block |
||
113 | 112 | } |
114 | 113 | elseif (is_object($value) && method_exists([$value, $method])) |
115 | 114 | { |
116 | - $this->setScalarValue |
|
117 | - ( |
|
115 | + $this->setScalarValue( |
|
118 | 116 | $property, |
119 | 117 | $value->$method(), |
120 | 118 | $method, |
@@ -153,8 +151,7 @@ discard block |
||
153 | 151 | |
154 | 152 | private function throwError($property, $expected, $value) |
155 | 153 | { |
156 | - throw new IllegalPropertyTypeException |
|
157 | - ( |
|
154 | + throw new IllegalPropertyTypeException( |
|
158 | 155 | get_class($this->object), |
159 | 156 | $property, |
160 | 157 | $expected, |
@@ -47,8 +47,7 @@ discard block |
||
47 | 47 | if (is_null($value)) |
48 | 48 | { |
49 | 49 | $this->setNullValue($property, $type); |
50 | - } |
|
51 | - else |
|
50 | + } else |
|
52 | 51 | { |
53 | 52 | $this->setNonNullValue($property, $value, $type); |
54 | 53 | } |
@@ -59,8 +58,7 @@ discard block |
||
59 | 58 | if ($type->nullable) |
60 | 59 | { |
61 | 60 | $this->setRawValue($property, null); |
62 | - } |
|
63 | - else |
|
61 | + } else |
|
64 | 62 | { |
65 | 63 | $this->throwError($property, 'NonNull', null); |
66 | 64 | } |
@@ -110,8 +108,7 @@ discard block |
||
110 | 108 | if (is_scalar($value)) |
111 | 109 | { |
112 | 110 | $this->setRawValue($property, $cast($value)); |
113 | - } |
|
114 | - elseif (is_object($value) && method_exists([$value, $method])) |
|
111 | + } elseif (is_object($value) && method_exists([$value, $method])) |
|
115 | 112 | { |
116 | 113 | $this->setScalarValue |
117 | 114 | ( |
@@ -120,8 +117,7 @@ discard block |
||
120 | 117 | $method, |
121 | 118 | $cast |
122 | 119 | ); |
123 | - } |
|
124 | - else |
|
120 | + } else |
|
125 | 121 | { |
126 | 122 | $this->throwError($property, $name, $value); |
127 | 123 | } |
@@ -132,8 +128,7 @@ discard block |
||
132 | 128 | if (is_a($value, $type->classname)) |
133 | 129 | { |
134 | 130 | $this->setRawValue($property, $value); |
135 | - } |
|
136 | - else |
|
131 | + } else |
|
137 | 132 | { |
138 | 133 | $this->throwError($property, $type->classname, $value); |
139 | 134 | } |
@@ -144,8 +139,7 @@ discard block |
||
144 | 139 | if (is_a($value, \ArrayAccess::class) || is_array($value)) |
145 | 140 | { |
146 | 141 | $this->setRawValue($property, $value); |
147 | - } |
|
148 | - else |
|
142 | + } else |
|
149 | 143 | { |
150 | 144 | $this->throwError($property, 'Collection', $value); |
151 | 145 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | { |
18 | 18 | parent::__construct |
19 | 19 | ( |
20 | - 'Tried to set an illegal property type for ' |
|
20 | + 'Tried to set an illegal property type for ' |
|
21 | 21 | . $class .'::$' . $property . '. Excpected ' . $expected |
22 | 22 | . ', got ' . $got, |
23 | 23 | 0, |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | class IllegalPropertyTypeException extends Exception |
8 | 8 | { |
9 | - public function __construct |
|
10 | - ( |
|
9 | + public function __construct( |
|
11 | 10 | string $class, |
12 | 11 | string $property, |
13 | 12 | string $expected, |
@@ -15,10 +14,9 @@ discard block |
||
15 | 14 | Exception $previous = null |
16 | 15 | ) |
17 | 16 | { |
18 | - parent::__construct |
|
19 | - ( |
|
17 | + parent::__construct( |
|
20 | 18 | 'Tried to set an illegal property type for ' |
21 | - . $class .'::$' . $property . '. Excpected ' . $expected |
|
19 | + . $class . '::$' . $property . '. Excpected ' . $expected |
|
22 | 20 | . ', got ' . $got, |
23 | 21 | 0, |
24 | 22 | $previous |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | (new ReflectionFileFactory($this->reflector->getFileName())) |
22 | 22 | ->build(); |
23 | 23 | $this->accessor->setRawValue('file', $file); |
24 | - $this->accessor->setRawValue |
|
25 | - ( |
|
24 | + $this->accessor->setRawValue( |
|
26 | 25 | 'namespace', |
27 | 26 | $file->namespaces[$this->reflector->getNamespaceName()] |
28 | 27 | ); |
@@ -48,15 +47,13 @@ discard block |
||
48 | 47 | |
49 | 48 | protected function buildProperty($reflect) |
50 | 49 | { |
51 | - $properties = $this->accessor->getRawValue |
|
52 | - ( |
|
50 | + $properties = $this->accessor->getRawValue( |
|
53 | 51 | 'properties' |
54 | 52 | ); |
55 | 53 | |
56 | 54 | $properties[$reflect->getName()] = |
57 | 55 | (new ReflectionPropertyFactory($reflect)) |
58 | - ->build |
|
59 | - ( |
|
56 | + ->build( |
|
60 | 57 | $this->object, |
61 | 58 | $this->reflector |
62 | 59 | ->getDefaultProperties()[$reflect->getName()] |
@@ -65,8 +62,7 @@ discard block |
||
65 | 62 | |
66 | 63 | protected function buildMethod($reflect) |
67 | 64 | { |
68 | - $this->accessor->rawAddToValue |
|
69 | - ( |
|
65 | + $this->accessor->rawAddToValue( |
|
70 | 66 | 'methods', |
71 | 67 | (new ReflectionMethodFactory($reflect)) |
72 | 68 | ->build($this->object) |