@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Spaark\CompositeUtils\Factory\Reflection; |
| 4 | 4 | |
| 5 | -use Spaark\CompositeUtils\Factory\BaseFactory; |
|
| 6 | 5 | use Spaark\CompositeUtils\Model\Reflection\ReflectionFile; |
| 7 | 6 | use Spaark\CompositeUtils\Model\Reflection\NamespaceBlock; |
| 8 | 7 | use Spaark\CompositeUtils\Model\Reflection\UseStatement; |
@@ -93,8 +93,7 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $as .= $token[1]; |
| 95 | 95 | } |
| 96 | - } |
|
| 97 | - elseif ($matching) |
|
| 96 | + } elseif ($matching) |
|
| 98 | 97 | { |
| 99 | 98 | switch ($token[0]) |
| 100 | 99 | { |
@@ -105,8 +104,7 @@ discard block |
||
| 105 | 104 | case T_AS: |
| 106 | 105 | $matching = T_AS; |
| 107 | 106 | } |
| 108 | - } |
|
| 109 | - else |
|
| 107 | + } else |
|
| 110 | 108 | { |
| 111 | 109 | switch ($token[0]) |
| 112 | 110 | { |
@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | case T_NAMESPACE: |
| 61 | 61 | $ns = new NamespaceBlock($classname); |
| 62 | 62 | $currentNS = new RawPropertyAccessor($ns); |
| 63 | - $this->accessor->getRawValue |
|
| 64 | - ( |
|
| 63 | + $this->accessor->getRawValue( |
|
| 65 | 64 | 'namespaces' |
| 66 | 65 | ) |
| 67 | 66 | ->add($classname, $ns); |
@@ -76,8 +75,7 @@ discard block |
||
| 76 | 75 | $as = end($as); |
| 77 | 76 | } |
| 78 | 77 | |
| 79 | - $currentNS->getRawValue |
|
| 80 | - ( |
|
| 78 | + $currentNS->getRawValue( |
|
| 81 | 79 | 'useStatements' |
| 82 | 80 | ) |
| 83 | 81 | ->add($as, new UseStatement($classname, $as)); |
@@ -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,14 +36,12 @@ 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 | } |
| 44 | 43 | |
| 45 | - $this->setAnyValue |
|
| 46 | - ( |
|
| 44 | + $this->setAnyValue( |
|
| 47 | 45 | $this->reflect->properties[$property], |
| 48 | 46 | $value |
| 49 | 47 | ); |
@@ -57,8 +55,7 @@ discard block |
||
| 57 | 55 | } |
| 58 | 56 | else |
| 59 | 57 | { |
| 60 | - $this->setNonNullValue |
|
| 61 | - ( |
|
| 58 | + $this->setNonNullValue( |
|
| 62 | 59 | $property->name, |
| 63 | 60 | $value, |
| 64 | 61 | $property->type |
@@ -125,8 +122,7 @@ discard block |
||
| 125 | 122 | } |
| 126 | 123 | elseif (is_object($value) && method_exists([$value, $method])) |
| 127 | 124 | { |
| 128 | - $this->setScalarValue |
|
| 129 | - ( |
|
| 125 | + $this->setScalarValue( |
|
| 130 | 126 | $property, |
| 131 | 127 | $value->$method(), |
| 132 | 128 | $method, |
@@ -165,8 +161,7 @@ discard block |
||
| 165 | 161 | |
| 166 | 162 | private function throwError($property, $expected, $value) |
| 167 | 163 | { |
| 168 | - throw new IllegalPropertyTypeException |
|
| 169 | - ( |
|
| 164 | + throw new IllegalPropertyTypeException( |
|
| 170 | 165 | get_class($this->object), |
| 171 | 166 | $property, |
| 172 | 167 | $expected, |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | if (is_null($value)) |
| 55 | 55 | { |
| 56 | 56 | $this->setNullValue($property->name, $property->type); |
| 57 | - } |
|
| 58 | - else |
|
| 57 | + } else |
|
| 59 | 58 | { |
| 60 | 59 | $this->setNonNullValue |
| 61 | 60 | ( |
@@ -71,8 +70,7 @@ discard block |
||
| 71 | 70 | if ($type->nullable) |
| 72 | 71 | { |
| 73 | 72 | $this->setRawValue($property, null); |
| 74 | - } |
|
| 75 | - else |
|
| 73 | + } else |
|
| 76 | 74 | { |
| 77 | 75 | $this->throwError($property, 'NonNull', null); |
| 78 | 76 | } |
@@ -122,8 +120,7 @@ discard block |
||
| 122 | 120 | if (is_scalar($value)) |
| 123 | 121 | { |
| 124 | 122 | $this->setRawValue($property, $cast($value)); |
| 125 | - } |
|
| 126 | - elseif (is_object($value) && method_exists([$value, $method])) |
|
| 123 | + } elseif (is_object($value) && method_exists([$value, $method])) |
|
| 127 | 124 | { |
| 128 | 125 | $this->setScalarValue |
| 129 | 126 | ( |
@@ -132,8 +129,7 @@ discard block |
||
| 132 | 129 | $method, |
| 133 | 130 | $cast |
| 134 | 131 | ); |
| 135 | - } |
|
| 136 | - else |
|
| 132 | + } else |
|
| 137 | 133 | { |
| 138 | 134 | $this->throwError($property, $name, $value); |
| 139 | 135 | } |
@@ -144,8 +140,7 @@ discard block |
||
| 144 | 140 | if (is_a($value, $type->classname)) |
| 145 | 141 | { |
| 146 | 142 | $this->setRawValue($property, $value); |
| 147 | - } |
|
| 148 | - else |
|
| 143 | + } else |
|
| 149 | 144 | { |
| 150 | 145 | $this->throwError($property, $type->classname, $value); |
| 151 | 146 | } |
@@ -156,8 +151,7 @@ discard block |
||
| 156 | 151 | if (is_a($value, \ArrayAccess::class) || is_array($value)) |
| 157 | 152 | { |
| 158 | 153 | $this->setRawValue($property, $value); |
| 159 | - } |
|
| 160 | - else |
|
| 154 | + } else |
|
| 161 | 155 | { |
| 162 | 156 | $this->throwError($property, 'Collection', $value); |
| 163 | 157 | } |
@@ -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 |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | parent::__construct |
| 12 | 12 | ( |
| 13 | - 'Tried to read unreadable property ' |
|
| 13 | + 'Tried to read unreadable property ' |
|
| 14 | 14 | . $class . '::$' . $property, |
| 15 | 15 | 0, |
| 16 | 16 | $previous |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct($class, $property, $previous = null) |
| 10 | 10 | { |
| 11 | - parent::__construct |
|
| 12 | - ( |
|
| 11 | + parent::__construct( |
|
| 13 | 12 | 'Tried to read unreadable property ' |
| 14 | 13 | . $class . '::$' . $property, |
| 15 | 14 | 0, |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | parent::__construct |
| 12 | 12 | ( |
| 13 | - 'Tried to write to unwritable property ' |
|
| 13 | + 'Tried to write to unwritable property ' |
|
| 14 | 14 | . $class . '::$' . $property, |
| 15 | 15 | 0, |
| 16 | 16 | $previous |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct($class, $property, $previous = null) |
| 10 | 10 | { |
| 11 | - parent::__construct |
|
| 12 | - ( |
|
| 11 | + parent::__construct( |
|
| 13 | 12 | 'Tried to write to unwritable property ' |
| 14 | 13 | . $class . '::$' . $property, |
| 15 | 14 | 0, |
@@ -15,8 +15,7 @@ discard block |
||
| 15 | 15 | } |
| 16 | 16 | else |
| 17 | 17 | { |
| 18 | - throw new PropertyNotWritableException |
|
| 19 | - ( |
|
| 18 | + throw new PropertyNotWritableException( |
|
| 20 | 19 | get_class($this->object), |
| 21 | 20 | $property->name |
| 22 | 21 | ); |
@@ -27,16 +26,14 @@ discard block |
||
| 27 | 26 | { |
| 28 | 27 | if (!$this->reflect->properties->contains($property)) |
| 29 | 28 | { |
| 30 | - throw new CannotReadPropertyException |
|
| 31 | - ( |
|
| 29 | + throw new CannotReadPropertyException( |
|
| 32 | 30 | get_class($this->object), |
| 33 | 31 | $property |
| 34 | 32 | ); |
| 35 | 33 | } |
| 36 | 34 | elseif (!$this->reflect->properties[$property]->readable) |
| 37 | 35 | { |
| 38 | - throw new PropertyNotReadableException |
|
| 39 | - ( |
|
| 36 | + throw new PropertyNotReadableException( |
|
| 40 | 37 | get_class($this->object), |
| 41 | 38 | $property |
| 42 | 39 | ); |
@@ -12,8 +12,7 @@ discard block |
||
| 12 | 12 | if ($property->writable) |
| 13 | 13 | { |
| 14 | 14 | parent::setAnyValue($property, $value); |
| 15 | - } |
|
| 16 | - else |
|
| 15 | + } else |
|
| 17 | 16 | { |
| 18 | 17 | throw new PropertyNotWritableException |
| 19 | 18 | ( |
@@ -32,8 +31,7 @@ discard block |
||
| 32 | 31 | get_class($this->object), |
| 33 | 32 | $property |
| 34 | 33 | ); |
| 35 | - } |
|
| 36 | - elseif (!$this->reflect->properties[$property]->readable) |
|
| 34 | + } elseif (!$this->reflect->properties[$property]->readable) |
|
| 37 | 35 | { |
| 38 | 36 | throw new PropertyNotReadableException |
| 39 | 37 | ( |