| Conditions | 7 |
| Paths | 11 |
| Total Lines | 53 |
| Code Lines | 28 |
| 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 |
||
| 96 | public function load(ConfigurationInterface $configuration) |
||
| 97 | { |
||
| 98 | |||
| 99 | // initialize the default loader and load the DI configuration for the this library |
||
| 100 | $defaultLoader = new XmlFileLoader($this->getContainer(), new FileLocator($this->getVendorDir())); |
||
|
|
|||
| 101 | |||
| 102 | // load the DI configuration for all the extension libraries |
||
| 103 | foreach ($configuration->getExtensionLibraries() as $library) { |
||
| 104 | if (file_exists($diConfiguration = sprintf('%s/%s/symfony/Resources/config/services.xml', $this->getVendorDir(), $library))) { |
||
| 105 | $defaultLoader->load($diConfiguration); |
||
| 106 | } else { |
||
| 107 | throw new \Exception( |
||
| 108 | sprintf( |
||
| 109 | 'Can\'t load DI configuration for library "%s"', |
||
| 110 | $diConfiguration |
||
| 111 | ) |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // register autoloaders for additional vendor directories |
||
| 117 | $customLoader = new XmlFileLoader($this->getContainer(), new FileLocator()); |
||
| 118 | foreach ($configuration->getAdditionalVendorDirs() as $additionalVendorDir) { |
||
| 119 | // load the vendor directory's auto loader |
||
| 120 | if (file_exists($autoLoader = $additionalVendorDir->getVendorDir() . '/autoload.php')) { |
||
| 121 | require $autoLoader; |
||
| 122 | } else { |
||
| 123 | throw new \Exception( |
||
| 124 | sprintf( |
||
| 125 | 'Can\'t find autoloader in configured additional vendor directory "%s"', |
||
| 126 | $additionalVendorDir->getVendorDir() |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | } |
||
| 130 | |||
| 131 | // try to load the DI configuration for the configured extension libraries |
||
| 132 | foreach ($additionalVendorDir->getLibraries() as $library) { |
||
| 133 | // prepare the DI configuration filename |
||
| 134 | $diConfiguration = realpath(sprintf('%s/%s/symfony/Resources/config/services.xml', $additionalVendorDir->getVendorDir(), $library)); |
||
| 135 | // try to load the filename |
||
| 136 | if (file_exists($diConfiguration)) { |
||
| 137 | $customLoader->load($diConfiguration); |
||
| 138 | } else { |
||
| 139 | throw new \Exception( |
||
| 140 | sprintf( |
||
| 141 | 'Can\'t load DI configuration for library "%s"', |
||
| 142 | $diConfiguration |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.