Conditions | 3 |
Paths | 1 |
Total Lines | 22 |
Lines | 7 |
Ratio | 31.82 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
31 | public function getLazyServiceDefinition(string $className, callable $definition): VirtualProxyInterface |
||
32 | { |
||
33 | return $this->lazyLoadingFactory->createProxy( |
||
34 | $className, |
||
35 | // this fancy method signature is required by lazy loading factory |
||
36 | static function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use ($className, $definition) { |
||
37 | $wrappedObject = $definition(); |
||
38 | $initializer = null; |
||
39 | |||
40 | // extra defensive programming in action |
||
41 | View Code Duplication | if (!$wrappedObject instanceof $className) { |
|
|
|||
42 | throw new \InvalidArgumentException(sprintf( |
||
43 | 'Object "%s" is not instance of "%s"', |
||
44 | \is_object($wrappedObject) ? \get_class($wrappedObject) : \gettype($wrappedObject), |
||
45 | $className |
||
46 | )); |
||
47 | } |
||
48 | |||
49 | return true; |
||
50 | } |
||
51 | ); |
||
52 | } |
||
53 | } |
||
54 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.