| Conditions | 17 |
| Paths | 514 |
| Total Lines | 80 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 235.2849 |
| Changes | 4 | ||
| Bugs | 0 | Features | 3 |
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 | $loaderCollectionDefinition = $container->findDefinition('majora.loader.collection'); |
|
| 26 | $loaderTags = $container->findTaggedServiceIds('majora.loader'); |
||
| 27 | 2 | ||
| 28 | foreach ($loaderTags as $loaderId => $tags) { |
||
| 29 | $loaderDefinition = $container->getDefinition($loaderId); |
||
| 30 | $loaderReflection = new \ReflectionClass($loaderDefinition->getClass()); |
||
| 31 | |||
| 32 | foreach ($tags as $attributes) { |
||
| 33 | $method = $loaderReflection->implementsInterface(LoaderInterface::class) ? |
||
| 34 | 'configureMetadata' : ($loaderReflection->hasMethod('setUp') ? |
||
| 35 | 'setUp' : '' |
||
| 36 | ) |
||
| 37 | ; |
||
| 38 | if (isset($attributes['entityClass']) || isset($attributes['entityCollection'])) { |
||
| 39 | @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
|
|||
| 40 | } |
||
| 41 | $entityClass = isset($attributes['entity']) ? $attributes['entity'] : $attributes['entityClass']; |
||
| 42 | $collectionClass = isset($attributes['collection']) ? $attributes['collection'] : $attributes['entityCollection']; |
||
| 43 | $entityReflection = new \ReflectionClass($entityClass); |
||
| 44 | |||
| 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 | if (isset($attributes['repository'])) { |
||
| 64 | @trigger_error('Repository injection tag "majora.loader" is deprecated and will be removed in 2.0. Please inject it by constructor.', E_USER_DEPRECATED); |
||
| 65 | $arguments[] = new Reference($attributes['repository']); |
||
| 66 | } |
||
| 67 | |||
| 68 | $loaderDefinition->addMethodCall($method, $arguments); |
||
| 69 | } |
||
| 70 | |||
| 71 | // for doctrine, loaders cannot self enable objects lazy loading |
||
| 72 | // so we have to check class / attribute and register service into event proxy |
||
| 73 | if ($container->hasDefinition('majora.doctrine.event_proxy') |
||
| 74 | && !empty($attributes['lazy']) |
||
| 75 | && $loaderReflection->isSubclassOf(AbstractDoctrineLoader::class) |
||
| 76 | ) { |
||
| 77 | if (!$entityReflection->implementsInterface(LazyPropertiesInterface::class)) { |
||
| 78 | throw new \InvalidArgumentException(sprintf( |
||
| 79 | 'Class %s has to implement %s to be able to lazy load her properties.', |
||
| 80 | $entityClass, |
||
| 81 | LazyPropertiesInterface::class |
||
| 82 | )); |
||
| 83 | } |
||
| 84 | $container->getDefinition('majora.doctrine.event_proxy') |
||
| 85 | ->addMethodCall('registerDoctrineLazyLoader', array( |
||
| 86 | $entityClass, |
||
| 87 | new Reference($loaderId), |
||
| 88 | )) |
||
| 89 | ; |
||
| 90 | } |
||
| 91 | 1 | ||
| 92 | 2 | if (!isset($attributes['alias'])) { |
|
| 93 | throw new \InvalidArgumentException(sprintf('Alias not define for "%s" loader.', $loaderId)); |
||
| 94 | } |
||
| 95 | |||
| 96 | $loaderCollectionDefinition->addMethodCall( |
||
| 97 | 'add', |
||
| 98 | array($attributes['alias'], new Reference($loaderId)) |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 |
If you suppress an error, we recommend checking for the error condition explicitly: