Conditions | 2 |
Paths | 1 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
27 | public function __construct(ReflectionClass $originalClass) |
||
28 | 2 | { |
|
29 | parent::__construct('staticProxyConstructor', [], self::FLAG_PUBLIC | self::FLAG_STATIC); |
||
30 | 2 | ||
31 | $nullableProperties = array_map( |
||
32 | 2 | static function (ReflectionProperty $publicProperty) : string { |
|
33 | return '$instance->' . $publicProperty->getName() . ' = null;'; |
||
34 | 1 | }, |
|
35 | 2 | Properties::fromReflectionClass($originalClass) |
|
36 | 2 | ->onlyNullableProperties() |
|
37 | ->getPublicProperties() |
||
38 | ); |
||
39 | 2 | ||
40 | 2 | $this->setReturnType($originalClass->getName()); |
|
41 | 2 | $this->setDocBlock('Constructor for null object initialization'); |
|
42 | $this->setBody( |
||
43 | 'static $reflection;' . "\n\n" |
||
44 | . '$reflection = $reflection ?? new \ReflectionClass(__CLASS__);' . "\n" |
||
45 | 2 | . '$instance = $reflection->newInstanceWithoutConstructor();' . "\n\n" |
|
46 | 2 | . ($nullableProperties ? implode("\n", $nullableProperties) . "\n\n" : '') |
|
47 | . 'return $instance;' |
||
48 | 2 | ); |
|
49 | } |
||
50 | } |
||
51 |