| Conditions | 16 |
| Paths | 482 |
| Total Lines | 78 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 210.3806 |
| Changes | 4 | ||
| Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | 2 | public function process(ContainerBuilder $container) |
|
| 24 | { |
||
| 25 | 2 | $loaderTags = $container->findTaggedServiceIds('majora.loader'); |
|
| 26 | |||
| 27 | 2 | foreach ($loaderTags as $loaderId => $tags) { |
|
| 28 | $loaderDefinition = $container->getDefinition($loaderId); |
||
| 29 | $loaderReflection = new \ReflectionClass($loaderDefinition->getClass()); |
||
| 30 | |||
| 31 | foreach ($tags as $attributes) { |
||
| 32 | $method = $loaderReflection->implementsInterface(LoaderInterface::class) ? |
||
| 33 | 'configureMetadata' : ($loaderReflection->hasMethod('setUp') ? |
||
| 34 | 'setUp' : '' |
||
| 35 | ) |
||
| 36 | ; |
||
| 37 | if (isset($attributes['entityClass']) || isset($attributes['entityCollection'])) { |
||
| 38 | @trigger_error('"entityClass" and "entityCollection" attributes for tag "majora.loader" are deprecated and will be removed in 2.0. Please "entity" and "collection" instead.', E_USER_DEPRECATED); |
||
|
1 ignored issue
–
show
|
|||
| 39 | } |
||
| 40 | $entityClass = isset($attributes['entity']) ? $attributes['entity'] : $attributes['entityClass']; |
||
| 41 | $collectionClass = isset($attributes['collection']) ? $attributes['collection'] : $attributes['entityCollection']; |
||
| 42 | $entityReflection = new \ReflectionClass($entityClass); |
||
| 43 | |||
| 44 | // configureMetadata() call configuration |
||
| 45 | if ($method) { |
||
| 46 | if (!$entityReflection->implementsInterface(CollectionableInterface::class)) { |
||
| 47 | throw new \InvalidArgumentException(sprintf( |
||
| 48 | 'Cannot support "%s" class into "%s" : managed items have to be %s.', |
||
| 49 | $entityClass, |
||
| 50 | $loaderDefinition->getClass(), |
||
| 51 | CollectionableInterface::class |
||
| 52 | )); |
||
| 53 | } |
||
| 54 | $arguments = array( |
||
| 55 | $entityClass, |
||
| 56 | array_map( |
||
| 57 | function ($property) { return $property->getName(); }, |
||
| 58 | $entityReflection->getProperties() |
||
| 59 | ), |
||
| 60 | $collectionClass, |
||
| 61 | ); |
||
| 62 | |||
| 63 | $loaderDefinition->addMethodCall($method, $arguments); |
||
| 64 | } |
||
| 65 | |||
| 66 | // Doctrine case |
||
| 67 | if ($loaderReflection->isSubclassOf(AbstractDoctrineLoader::class)) { |
||
| 68 | |||
| 69 | // "repository" attribute key only supported for doctrine loaders |
||
| 70 | // Repository is injected through mutator to avoid circular references |
||
| 71 | // with Doctrine events and connection |
||
| 72 | if (isset($attributes['repository'])) { |
||
| 73 | $loaderDefinition->addMethodCall( |
||
| 74 | 'setEntityRepository', |
||
| 75 | array(new Reference($attributes['repository'])) |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | |||
| 79 | // for Doctrine, loaders cannot self enable objects lazy loading |
||
| 80 | // due to general event trigger into all listener for each entites |
||
| 81 | // so we have to check class / attribute and register service into event proxy |
||
| 82 | if ($container->hasDefinition('majora.doctrine.event_proxy') && !empty($attributes['lazy'])) { |
||
| 83 | if (!$entityReflection->implementsInterface(LazyPropertiesInterface::class)) { |
||
| 84 | throw new \InvalidArgumentException(sprintf( |
||
| 85 | 'Class %s has to implement %s to be able to lazy load her properties.', |
||
| 86 | $entityClass, |
||
| 87 | LazyPropertiesInterface::class |
||
| 88 | )); |
||
| 89 | } |
||
| 90 | $container->getDefinition('majora.doctrine.event_proxy') |
||
| 91 | ->addMethodCall('registerDoctrineLazyLoader', array( |
||
| 92 | $entityClass, |
||
| 93 | new Reference($loaderId), |
||
| 94 | )) |
||
| 95 | ; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | 1 | } |
|
| 100 | 2 | } |
|
| 101 | } |
||
| 102 |
If you suppress an error, we recommend checking for the error condition explicitly: