| Conditions | 5 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 37 | public function process(ContainerBuilder $container): void |
||
| 38 | { |
||
| 39 | /** @var AnnotationReader $annotationReader */ |
||
| 40 | $annotationReader = $container->get('annotation_reader'); |
||
| 41 | |||
| 42 | $files = $this->findFiles( |
||
| 43 | $container->getParameter('sonata_annotation.directory') |
||
| 44 | ); |
||
| 45 | |||
| 46 | foreach ($files as $file) { |
||
| 47 | if (!($className = $this->getFullyQualifiedClassName($file))) { |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (!class_exists($className)) { |
||
| 52 | continue; |
||
| 53 | } |
||
| 54 | |||
| 55 | if (!($annotation = $annotationReader->getClassAnnotation( |
||
| 56 | new ReflectionClass($className), |
||
| 57 | Admin::class |
||
| 58 | ))) { |
||
| 59 | continue; |
||
| 60 | } |
||
| 61 | |||
| 62 | $definition = new Definition( |
||
| 63 | $annotation->admin, |
||
| 64 | [ |
||
| 65 | new Reference('sonata.annotation.reader.action_button'), |
||
| 66 | new Reference('sonata.annotation.reader.datagrid'), |
||
| 67 | new Reference('sonata.annotation.reader.datagrid_values'), |
||
| 68 | new Reference('sonata.annotation.reader.dashboard_action'), |
||
| 69 | new Reference('sonata.annotation.reader.export'), |
||
| 70 | new Reference('sonata.annotation.reader.form'), |
||
| 71 | new Reference('sonata.annotation.reader.list'), |
||
| 72 | new Reference('sonata.annotation.reader.route'), |
||
| 73 | new Reference('sonata.annotation.reader.show'), |
||
| 74 | ] |
||
| 75 | ); |
||
| 76 | |||
| 77 | $definition->addTag( |
||
| 78 | 'sonata.admin', |
||
| 79 | array_merge( |
||
| 80 | $annotation->getTagOptions(), |
||
| 81 | ['model_class' => $className], |
||
| 82 | ) |
||
| 83 | ); |
||
| 84 | |||
| 85 | $container->setDefinition( |
||
| 86 | $annotation->serviceId ?? $this->getServiceId($file), |
||
| 87 | $definition |
||
| 88 | ); |
||
| 170 |