| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 15 | private function createInternal(\ReflectionClass $class) |
|
| 35 | { |
||
| 36 | 15 | $constructor = $class->getConstructor(); |
|
| 37 | |||
| 38 | // If there is no c'tor defined we can create be using default creation method. |
||
| 39 | 15 | if ($constructor === null) { |
|
| 40 | 10 | return new CreateWithDefaultConstructor($class); |
|
| 41 | } |
||
| 42 | |||
| 43 | // Is the constructor free of required parameters ? |
||
| 44 | 5 | if ($constructor->getNumberOfRequiredParameters() === 0) { |
|
| 45 | |||
| 46 | // If the constructor is public and has no required parameters we can use the default creation method. |
||
| 47 | 4 | if ($constructor->isPublic()) { |
|
| 48 | 3 | return new CreateWithDefaultConstructor($class); |
|
| 49 | } |
||
| 50 | |||
| 51 | // Otherwise we are using the protected/private creation method. |
||
| 52 | 1 | return new CreateWithNonPublicConstructor($class); |
|
| 53 | } |
||
| 54 | |||
| 55 | // Last resort: create without the constructor |
||
| 56 | 1 | return new CreateWithoutConstructor($class); |
|
| 57 | } |
||
| 59 |