| Conditions | 14 |
| Paths | 13 |
| Total Lines | 46 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 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 |
||
| 52 | final public function loadPlugin(EnvironmentInterface $environment): void |
||
| 53 | { |
||
| 54 | foreach ($this->objects as $item) { |
||
| 55 | switch (true) { |
||
| 56 | case $item instanceof ApiVersionConstraint: |
||
| 57 | $environment->assertApiVersion($item); |
||
| 58 | $this->pluginName = $item->getName(); |
||
| 59 | break; |
||
| 60 | case $item instanceof DriverFactoryInterface: |
||
| 61 | $environment->registerDatabaseDriver($item); |
||
| 62 | break; |
||
| 63 | case $item instanceof ConsoleInterface: |
||
| 64 | $environment->registerConsoleCommand($item); |
||
| 65 | break; |
||
| 66 | case $item instanceof ListenerInterface: |
||
| 67 | if (!is_callable($item)) { |
||
| 68 | throw new \LogicException(sprintf( |
||
| 69 | 'Class %s implements the ListenerInterface but is not callable', |
||
| 70 | get_class($item) |
||
| 71 | )); |
||
| 72 | } |
||
| 73 | $environment->registerListener($item); |
||
| 74 | break; |
||
| 75 | case $item instanceof ListenerProviderInterface: |
||
| 76 | $environment->registerListenerProvider($item); |
||
| 77 | break; |
||
| 78 | case $item instanceof FilterInterface: |
||
| 79 | $environment->registerDonorFilter($item); |
||
| 80 | break; |
||
| 81 | case $item instanceof FormatterInterface: |
||
| 82 | $environment->registerDonorFormatter($item); |
||
| 83 | break; |
||
| 84 | case $item instanceof SorterInterface: |
||
| 85 | $environment->registerDonorSorter($item); |
||
| 86 | break; |
||
| 87 | case $item instanceof StatisticInterface: |
||
| 88 | $environment->registerStatistic($item); |
||
| 89 | break; |
||
| 90 | case $item instanceof CompilerPassInterface: |
||
| 91 | $environment->registerXmlMandateCompilerPass($item); |
||
| 92 | break; |
||
| 93 | default: |
||
| 94 | throw new \InvalidArgumentException(sprintf( |
||
| 95 | "Unknown item type '%s' in plugin '%s'", |
||
| 96 | is_object($item) ? get_class($item) : gettype($item), |
||
| 97 | $this->pluginName |
||
| 98 | )); |
||
| 103 |