| @@ -16,15 +16,8 @@ | ||
| 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 | -use Spaark\CompositeUtils\Service\RawPropertyAccessor; | |
| 28 | 21 | use Spaark\CompositeUtils\Service\GenericNameProvider; | 
| 29 | 22 | use Spaark\CompositeUtils\Traits\AutoConstructTrait; | 
| 30 | 23 | |
| @@ -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 | - '<?php namespace ' . $class->namespace . ';' | |
| 85 | + '<?php 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 | 
| @@ -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 | /** | 
| @@ -20,7 +20,6 @@ | ||
| 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 | 25 | use Spaark\CompositeUtils\Model\Generic\GenericContext; | 
| @@ -99,7 +99,7 @@ | ||
| 99 | 99 | * Infers the serialized name of the given ObjectType | 
| 100 | 100 | * | 
| 101 | 101 | * @param ObjectType $reflect | 
| 102 | - * @return string | |
| 102 | + * @return ClassName | |
| 103 | 103 | */ | 
| 104 | 104 | protected function inferObjectName(ObjectType $reflect) | 
| 105 | 105 |      { | 
| @@ -117,7 +117,7 @@ | ||
| 117 | 117 | |
| 118 | 118 | return new ClassName | 
| 119 | 119 | ( | 
| 120 | - self::BASE . $reflect->classname | |
| 120 | + self::BASE . $reflect->classname | |
| 121 | 121 |                  . '_g' . implode('_c', $items) . '_e' | 
| 122 | 122 | ); | 
| 123 | 123 | } | 
| @@ -69,8 +69,7 @@ discard block | ||
| 69 | 69 | return $this->inferGenericName($reflect); | 
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | - throw new \DomainException | |
| 73 | - ( | |
| 72 | + throw new \DomainException( | |
| 74 | 73 | 'Unknown type: ' . get_class($reflect) | 
| 75 | 74 | ); | 
| 76 | 75 | } | 
| @@ -89,8 +88,7 @@ discard block | ||
| 89 | 88 | throw new MissingContextException(); | 
| 90 | 89 | } | 
| 91 | 90 | |
| 92 | - return $this->inferName | |
| 93 | - ( | |
| 91 | + return $this->inferName( | |
| 94 | 92 | $this->context->getGenericType($reflect->name) | 
| 95 | 93 | ); | 
| 96 | 94 | } | 
| @@ -115,8 +113,7 @@ discard block | ||
| 115 | 113 | $items[] = $this->inferName($generic); | 
| 116 | 114 | } | 
| 117 | 115 | |
| 118 | - return new ClassName | |
| 119 | - ( | |
| 116 | + return new ClassName( | |
| 120 | 117 | self::BASE . $reflect->classname | 
| 121 | 118 |                  . '_g' . implode('_c', $items) . '_e' | 
| 122 | 119 | ); | 
| @@ -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, | 
| @@ -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) | 
| @@ -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 | } | 
| @@ -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]; | 
| @@ -31,8 +31,7 @@ discard block | ||
| 31 | 31 | * @param AbstractType $child | 
| 32 | 32 | * @return boolean | 
| 33 | 33 | */ | 
| 34 | - public function compatible | |
| 35 | - ( | |
| 34 | + public function compatible( | |
| 36 | 35 | AbstractType $parent, | 
| 37 | 36 | AbstractType $child | 
| 38 | 37 | ) | 
| @@ -50,16 +49,14 @@ discard block | ||
| 50 | 49 |          { | 
| 51 | 50 | return | 
| 52 | 51 | $child instanceof ObjectType && | 
| 53 | - is_a | |
| 54 | - ( | |
| 52 | + is_a( | |
| 55 | 53 | $child->classname->__toString(), | 
| 56 | 54 | $parent->classname->__toString(), | 
| 57 | 55 | true | 
| 58 | 56 | ); | 
| 59 | 57 | } | 
| 60 | 58 | |
| 61 | - throw new \DomainException | |
| 62 | - ( | |
| 59 | + throw new \DomainException( | |
| 63 | 60 | 'Unknown type: ' . get_class($parent) | 
| 64 | 61 | ); | 
| 65 | 62 | } | 
| @@ -83,15 +83,13 @@ discard block | ||
| 83 | 83 | if ($building) | 
| 84 | 84 |              { | 
| 85 | 85 | $this->buildProperty($property); | 
| 86 | - } | |
| 87 | - else | |
| 86 | + } else | |
| 88 | 87 |              { | 
| 89 | 88 | if (isset($args[$i])) | 
| 90 | 89 |                  { | 
| 91 | 90 | $this->setAnyValue($property, $args[$i]); | 
| 92 | 91 | $i++; | 
| 93 | - } | |
| 94 | - else | |
| 92 | + } else | |
| 95 | 93 |                  { | 
| 96 | 94 | $building = true; | 
| 97 | 95 | $this->buildProperty($property); | 
| @@ -115,8 +113,7 @@ discard block | ||
| 115 | 113 | if (!$property->type instanceof ObjectType) | 
| 116 | 114 |          { | 
| 117 | 115 | $this->setAnyValue($property, 0); | 
| 118 | - } | |
| 119 | - elseif ($property->builtInConstructor) | |
| 116 | + } elseif ($property->builtInConstructor) | |
| 120 | 117 |          { | 
| 121 | 118 | $class = (string)$property->type->classname; | 
| 122 | 119 | $this->setRawValue($property->name, new $class()); | 
| @@ -168,8 +165,7 @@ discard block | ||
| 168 | 165 | if (is_null($value)) | 
| 169 | 166 |          { | 
| 170 | 167 | $this->setNullValue($property); | 
| 171 | - } | |
| 172 | - else | |
| 168 | + } else | |
| 173 | 169 |          { | 
| 174 | 170 | $this->setNonNullValue($property, $value); | 
| 175 | 171 | } | 
| @@ -185,8 +181,7 @@ discard block | ||
| 185 | 181 | if ($property->type->nullable) | 
| 186 | 182 |          { | 
| 187 | 183 | $this->setRawValue($property->name, null); | 
| 188 | - } | |
| 189 | - else | |
| 184 | + } else | |
| 190 | 185 |          { | 
| 191 | 186 | $this->throwError($property, 'NonNull', null); | 
| 192 | 187 | } | 
| @@ -261,8 +256,7 @@ discard block | ||
| 261 | 256 | if (is_scalar($value)) | 
| 262 | 257 |          { | 
| 263 | 258 | $this->setRawValue($property->name, $cast($value)); | 
| 264 | - } | |
| 265 | - elseif (is_object($value) && method_exists([$value, $method])) | |
| 259 | + } elseif (is_object($value) && method_exists([$value, $method])) | |
| 266 | 260 |          { | 
| 267 | 261 | $this->setScalarValue | 
| 268 | 262 | ( | 
| @@ -271,8 +265,7 @@ discard block | ||
| 271 | 265 | $method, | 
| 272 | 266 | $cast | 
| 273 | 267 | ); | 
| 274 | - } | |
| 275 | - else | |
| 268 | + } else | |
| 276 | 269 |          { | 
| 277 | 270 | $this->throwError($property, $name, $value); | 
| 278 | 271 | } | 
| @@ -293,8 +286,7 @@ discard block | ||
| 293 | 286 | if (is_a($value, $property->type->classname)) | 
| 294 | 287 |          { | 
| 295 | 288 | $this->setRawValue($property->name, $value); | 
| 296 | - } | |
| 297 | - else | |
| 289 | + } else | |
| 298 | 290 |          { | 
| 299 | 291 | $this->throwError | 
| 300 | 292 | ( | 
| @@ -320,8 +312,7 @@ discard block | ||
| 320 | 312 | if (is_a($value, \ArrayAccess::class) || is_array($value)) | 
| 321 | 313 |          { | 
| 322 | 314 | $this->setRawValue($property->name, $value); | 
| 323 | - } | |
| 324 | - else | |
| 315 | + } else | |
| 325 | 316 |          { | 
| 326 | 317 | $this->throwError($property, 'Collection', $value); | 
| 327 | 318 | } |