| Conditions | 14 |
| Paths | 53 |
| Total Lines | 72 |
| Code Lines | 40 |
| 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 |
||
| 60 | public function process(ContainerBuilder $container) |
||
| 61 | { |
||
| 62 | if (!class_exists('Symfony\Component\Finder\Finder')) { |
||
| 63 | throw new RuntimeException('You need the symfony/finder component to register enums.'); |
||
| 64 | } |
||
| 65 | |||
| 66 | $enumDir = $this->bundleDir . '/Enum'; |
||
| 67 | |||
| 68 | if (!is_dir($enumDir)) { |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | $finder = new Finder(); |
||
| 73 | $finder->files()->name('*Enum.php')->in($enumDir); |
||
| 74 | |||
| 75 | foreach ($finder as $file) { |
||
| 76 | /** @var SplFileInfo $file */ |
||
| 77 | $enumNamespace = $this->bundleNamespace . '\\Enum'; |
||
| 78 | if ($relativePath = $file->getRelativePath()) { |
||
| 79 | $enumNamespace .= '\\' . strtr($relativePath, '/', '\\'); |
||
| 80 | } |
||
| 81 | |||
| 82 | $enumClass = $enumNamespace . '\\' . $file->getBasename('.php'); |
||
| 83 | $enumReflection = new ReflectionClass($enumClass); |
||
| 84 | |||
| 85 | if (!$enumReflection->isSubclassOf(EnumInterface::class) || $enumReflection->isAbstract()) { |
||
| 86 | continue; //Not an enum or abstract enum |
||
| 87 | } |
||
| 88 | |||
| 89 | $definition = null; |
||
| 90 | $requiredParameters = 0; |
||
| 91 | if ($enumReflection->getConstructor()) { |
||
| 92 | $requiredParameters = $enumReflection->getConstructor()->getNumberOfRequiredParameters(); |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($requiredParameters === 0) { |
||
| 96 | $definition = new Definition($enumClass); |
||
| 97 | } elseif ($requiredParameters === 2 && $enumReflection->isSubclassOf(AbstractTranslatedEnum::class)) { |
||
| 98 | if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { |
||
| 99 | // ChildDefinition was introduced as Symfony 3.3 |
||
| 100 | $definition = new ChildDefinition('enum.abstract_translated'); |
||
| 101 | } else { |
||
| 102 | // DefinitionDecorator was deprecated as Symfony 3.3 |
||
| 103 | $definition = new DefinitionDecorator('enum.abstract_translated'); |
||
| 104 | } |
||
| 105 | $definition->setClass($enumClass); |
||
| 106 | $definition->addArgument( |
||
| 107 | $this->getTransPattern($enumClass) |
||
| 108 | ); |
||
| 109 | |||
| 110 | if ($this->transDomain) { |
||
| 111 | $definition->addMethodCall( |
||
| 112 | 'setTransDomain', |
||
| 113 | [ |
||
| 114 | $this->transDomain |
||
| 115 | ] |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | if (!$definition) { |
||
| 121 | continue; //Could not determine how to create definition for the enum |
||
| 122 | } |
||
| 123 | |||
| 124 | $definition->addTag('enum'); |
||
| 125 | |||
| 126 | $container->setDefinition( |
||
| 127 | $this->getServiceId($enumClass), |
||
| 128 | $definition |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 205 |