| Conditions | 5 |
| Paths | 7 |
| Total Lines | 51 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 72 | private function registerService($serviceName, $serviceProviderKey, callable $callable) { |
||
| 73 | if (!$this->compiler->has($serviceName)) { |
||
| 74 | $definition = $this->getServiceDefinitionFromCallable($serviceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition()); |
||
| 75 | |||
| 76 | $this->compiler->addDumpableDefinition($definition); |
||
| 77 | } else { |
||
| 78 | // The new service will be created under the name 'xxx_decorated_y' |
||
| 79 | // The old service will be moved to the name 'xxx_decorated_y.inner' |
||
| 80 | // This old service will be accessible through a callback represented by 'xxx_decorated_y.callbackwrapper' |
||
| 81 | // The $servicename becomes an alias pointing to 'xxx_decorated_y' |
||
| 82 | |||
| 83 | $previousDefinition = $this->compiler->getDumpableDefinition($serviceName); |
||
| 84 | /*while ($previousDefinition instanceof Reference) { |
||
| 85 | $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias()); |
||
| 86 | }*/ |
||
| 87 | |||
| 88 | while ($previousDefinition instanceof AliasDefinition) { |
||
| 89 | $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias()); |
||
| 90 | } |
||
| 91 | |||
| 92 | $oldServiceName = $serviceName; |
||
| 93 | $decoratedServiceName = $this->getDecoratedServiceName($serviceName); |
||
| 94 | $innerName = $decoratedServiceName.'.inner'; |
||
| 95 | $callbackWrapperName = $decoratedServiceName.'.callbackwrapper'; |
||
| 96 | |||
| 97 | // TODO: it would be way easier if we could simply rename a definition!!! |
||
| 98 | if ($previousDefinition instanceof FactoryCallDefinition) { |
||
| 99 | $innerDefinition = new FactoryCallDefinition($innerName, $previousDefinition->getFactory(), $previousDefinition->getMethodName(), $previousDefinition->getMethodArguments()); |
||
| 100 | // @codeCoverageIgnoreStart |
||
| 101 | } elseif ($previousDefinition instanceof ServiceFromRegistryDefinition) { |
||
| 102 | // @codeCoverageIgnoreEnd |
||
| 103 | $innerDefinition = new ServiceFromRegistryDefinition($innerName, $previousDefinition->getServiceName(), $previousDefinition->getServiceProviderKey(), $previousDefinition->getCallbackWrapperDefinition()); |
||
| 104 | } else { |
||
| 105 | // @codeCoverageIgnoreStart |
||
| 106 | throw new CompilerException('Unable to rename definition from class '.get_class($previousDefinition)); |
||
| 107 | // @codeCoverageIgnoreEnd |
||
| 108 | } |
||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | $callbackWrapperDefinition = new CallbackWrapperDefinition($callbackWrapperName, $innerDefinition); |
||
| 113 | |||
| 114 | $definition = $this->getServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition(), $callbackWrapperDefinition); |
||
| 115 | |||
| 116 | $this->compiler->addDumpableDefinition($definition); |
||
| 117 | $this->compiler->addDumpableDefinition($innerDefinition); |
||
| 118 | $this->compiler->addDumpableDefinition($callbackWrapperDefinition); |
||
| 119 | $this->compiler->addDumpableDefinition(new AliasDefinition($oldServiceName, $decoratedServiceName)); |
||
| 120 | } |
||
| 121 | |||
| 122 | } |
||
| 123 | |||
| 168 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.