| Conditions | 4 |
| Paths | 2 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public function generate(object $object, array $methods = []): object |
||
| 21 | { |
||
| 22 | $objectManager = $this->configuration->objectManagerFor(\get_class($object)); |
||
| 23 | $interceptor = function (object $proxy, object $model) use ($objectManager): void { |
||
| 24 | $objectManager->refresh($model); |
||
| 25 | }; |
||
| 26 | |||
| 27 | $objectMethods = get_class_methods($object); |
||
| 28 | $interceptMethods = []; |
||
| 29 | if (!$methods) { |
||
|
|
|||
| 30 | $interceptMethods = $objectMethods; |
||
| 31 | } else { |
||
| 32 | foreach ($methods as $methodName) { |
||
| 33 | if (false === strpos($methodName, '*')){ |
||
| 34 | $interceptMethods[] = $methodName; |
||
| 35 | continue; |
||
| 36 | } |
||
| 37 | |||
| 38 | $methodNameRegex = '/^'.str_replace('*', '[[:alnum:]]+', $methodName).'$/'; |
||
| 39 | $interceptMethods = array_merge($interceptMethods, array_filter($objectMethods, function ($objectMethod) use ($methodNameRegex) { |
||
| 40 | return 1 !== preg_match($methodNameRegex, $objectMethod); |
||
| 41 | })); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | return $this->factory->createProxy($object, array_fill_keys(array_unique($interceptMethods), $interceptor)); |
||
| 46 | } |
||
| 48 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.