@@ -25,7 +25,7 @@ |
||
| 25 | 25 | /** |
| 26 | 26 | * Checks if the given class is equal to this one |
| 27 | 27 | * |
| 28 | - * @param Type $oject |
|
| 28 | + * @param Type $object |
|
| 29 | 29 | * @return boolean |
| 30 | 30 | */ |
| 31 | 31 | public function equals($object) : bool; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->initParams(); |
| 98 | 98 | |
| 99 | 99 | $this->accessor->setRawValue('visibility', |
| 100 | - ($this->reflector->isPublic() ? 'public' |
|
| 100 | + ($this->reflector->isPublic() ? 'public' |
|
| 101 | 101 | : ($this->reflector->isProtected() ? 'protected' |
| 102 | 102 | : ($this->reflector->isPrivate() ? 'private' |
| 103 | 103 | : ('')))) |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | throw new \Exception |
| 156 | 156 | ( |
| 157 | - 'Tried to set param annotation for non existant ' |
|
| 157 | + 'Tried to set param annotation for non existant ' |
|
| 158 | 158 | . 'parameter: ' . $param |
| 159 | 159 | ); |
| 160 | 160 | } |
@@ -63,8 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function fromName(string $class, string $method) |
| 65 | 65 | { |
| 66 | - return new static(new PHPNativeReflectionMethod |
|
| 67 | - ( |
|
| 66 | + return new static(new PHPNativeReflectionMethod( |
|
| 68 | 67 | $class, $method |
| 69 | 68 | )); |
| 70 | 69 | } |
@@ -84,12 +83,11 @@ discard block |
||
| 84 | 83 | * this method belongs to |
| 85 | 84 | * @return ReflectionMethod |
| 86 | 85 | */ |
| 87 | - public function build(?ReflectionComposite $parent = null) |
|
| 86 | + public function build(? ReflectionComposite $parent = null) |
|
| 88 | 87 | { |
| 89 | 88 | $this->typeParser = new TypeParser($parent); |
| 90 | 89 | $this->accessor->setRawValue('owner', $parent); |
| 91 | - $this->accessor->setRawValue |
|
| 92 | - ( |
|
| 90 | + $this->accessor->setRawValue( |
|
| 93 | 91 | 'name', |
| 94 | 92 | $this->reflector->getName() |
| 95 | 93 | ); |
@@ -125,13 +123,11 @@ discard block |
||
| 125 | 123 | */ |
| 126 | 124 | protected function initParams() |
| 127 | 125 | { |
| 128 | - $this->accessor->setRawValue |
|
| 129 | - ( |
|
| 126 | + $this->accessor->setRawValue( |
|
| 130 | 127 | 'parameters', |
| 131 | 128 | new FixedList(count($this->reflector->getParameters())) |
| 132 | 129 | ); |
| 133 | - $this->accessor->setRawValue |
|
| 134 | - ( |
|
| 130 | + $this->accessor->setRawValue( |
|
| 135 | 131 | 'nativeParameters', |
| 136 | 132 | new FixedList(count($this->reflector->getParameters())) |
| 137 | 133 | ); |
@@ -152,8 +148,7 @@ discard block |
||
| 152 | 148 | |
| 153 | 149 | if (!$this->parameters->containsKey($param)) |
| 154 | 150 | { |
| 155 | - throw new \Exception |
|
| 156 | - ( |
|
| 151 | + throw new \Exception( |
|
| 157 | 152 | 'Tried to set param annotation for non existant ' |
| 158 | 153 | . 'parameter: ' . $param |
| 159 | 154 | ); |
@@ -178,8 +173,7 @@ discard block |
||
| 178 | 173 | * |
| 179 | 174 | * @param PHPNativeReflectionParameter $reflect |
| 180 | 175 | */ |
| 181 | - protected function addParameter |
|
| 182 | - ( |
|
| 176 | + protected function addParameter( |
|
| 183 | 177 | PHPNativeReflectionParameter $reflect |
| 184 | 178 | ) |
| 185 | 179 | : void |
@@ -17,7 +17,6 @@ |
||
| 17 | 17 | use Spaark\CompositeUtils\Model\Reflection\Type\AbstractType; |
| 18 | 18 | use Spaark\CompositeUtils\Model\Reflection\Type\ObjectType; |
| 19 | 19 | use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite; |
| 20 | -use Spaark\CompositeUtils\Traits\AllReadableTrait; |
|
| 21 | 20 | use Spaark\CompositeUtils\Traits\AutoConstructTrait; |
| 22 | 21 | |
| 23 | 22 | /** |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | { |
| 36 | 36 | parent::__construct |
| 37 | 37 | ( |
| 38 | - 'Cannot serialize object containing generics without ' |
|
| 38 | + 'Cannot serialize object containing generics without ' |
|
| 39 | 39 | . 'context', |
| 40 | 40 | 0, |
| 41 | 41 | $previous |
@@ -28,13 +28,11 @@ |
||
| 28 | 28 | * |
| 29 | 29 | * @param Throwable $previous The exception which caused this |
| 30 | 30 | */ |
| 31 | - public function __construct |
|
| 32 | - ( |
|
| 31 | + public function __construct( |
|
| 33 | 32 | Throwable $previous = null |
| 34 | 33 | ) |
| 35 | 34 | { |
| 36 | - parent::__construct |
|
| 37 | - ( |
|
| 35 | + parent::__construct( |
|
| 38 | 36 | 'Cannot serialize object containing generics without ' |
| 39 | 37 | . 'context', |
| 40 | 38 | 0, |
@@ -73,8 +73,7 @@ |
||
| 73 | 73 | public function generateClassCode(...$generics) : string |
| 74 | 74 | { |
| 75 | 75 | $object = $this->createObject(...$generics); |
| 76 | - $this->nameProvider = new GenericNameProvider |
|
| 77 | - ( |
|
| 76 | + $this->nameProvider = new GenericNameProvider( |
|
| 78 | 77 | new GenericContext($object, $this->reflect) |
| 79 | 78 | ); |
| 80 | 79 | $class = $this->nameProvider->inferName($object); |
@@ -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 | |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @param ReflectionCompositeProviderInterface $default |
| 56 | 56 | */ |
| 57 | - public static function setDefault |
|
| 58 | - ( |
|
| 57 | + public static function setDefault( |
|
| 59 | 58 | ReflectionCompositeProviderInterface $default |
| 60 | 59 | ) |
| 61 | 60 | { |
@@ -90,8 +89,7 @@ discard block |
||
| 90 | 89 | { |
| 91 | 90 | $this->cache[$classname] = |
| 92 | 91 | ( |
| 93 | - ReflectionCompositeFactory::fromClassName |
|
| 94 | - ( |
|
| 92 | + ReflectionCompositeFactory::fromClassName( |
|
| 95 | 93 | $classname |
| 96 | 94 | ) |
| 97 | 95 | ) |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | /** |
| 44 | 44 | * Creates this ObjectType with the given classname |
| 45 | 45 | * |
| 46 | - * @param mixed $class The name of the class this must be an |
|
| 46 | + * @param string $classname The name of the class this must be an |
|
| 47 | 47 | * instance of |
| 48 | 48 | */ |
| 49 | 49 | public function __construct($classname) |
@@ -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() |
@@ -46,8 +46,7 @@ |
||
| 46 | 46 | if (!$matches) |
| 47 | 47 | { |
| 48 | 48 | $this->classname = $classname; |
| 49 | - } |
|
| 50 | - else |
|
| 49 | + } else |
|
| 51 | 50 | { |
| 52 | 51 | $this->classname = $matches[2]; |
| 53 | 52 | $this->namespace = $matches[1]; |
@@ -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 | |
@@ -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 | } |