| Conditions | 12 |
| Paths | 402 |
| Total Lines | 51 |
| Code Lines | 30 |
| 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 |
||
| 131 | private function doImport(mixed $resource, ?string $type = null, bool $ignoreErrors = false, ?string $sourceResource = null): mixed |
||
| 132 | { |
||
| 133 | try { |
||
| 134 | $loader = $this->resolve($resource, $type); |
||
| 135 | |||
| 136 | if ($loader instanceof DirectoryAwareLoaderInterface) { |
||
| 137 | $loader = $loader->forDirectory($this->currentDir); |
||
| 138 | } |
||
| 139 | |||
| 140 | if (!$loader instanceof self) { |
||
| 141 | return $loader->load($resource, $type); |
||
| 142 | } |
||
| 143 | |||
| 144 | if (null !== $this->currentDir) { |
||
| 145 | $resource = $loader->getLocator()->locate($resource, $this->currentDir, false); |
||
| 146 | } |
||
| 147 | |||
| 148 | $resources = \is_array($resource) ? $resource : [$resource]; |
||
| 149 | for ($i = 0; $i < $resourcesCount = \count($resources); ++$i) { |
||
| 150 | if (isset(self::$loading[$resources[$i]])) { |
||
| 151 | if ($i == $resourcesCount - 1) { |
||
| 152 | throw new FileLoaderImportCircularReferenceException(array_keys(self::$loading)); |
||
| 153 | } |
||
| 154 | } else { |
||
| 155 | $resource = $resources[$i]; |
||
| 156 | break; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | self::$loading[$resource] = true; |
||
| 160 | |||
| 161 | try { |
||
| 162 | $ret = $loader->load($resource, $type); |
||
| 163 | } finally { |
||
| 164 | unset(self::$loading[$resource]); |
||
| 165 | } |
||
| 166 | |||
| 167 | return $ret; |
||
| 168 | } catch (FileLoaderImportCircularReferenceException $e) { |
||
| 169 | throw $e; |
||
| 170 | } catch (\Exception $e) { |
||
| 171 | if (!$ignoreErrors) { |
||
| 172 | // prevent embedded imports from nesting multiple exceptions |
||
| 173 | if ($e instanceof LoaderLoadException) { |
||
| 174 | throw $e; |
||
| 175 | } |
||
| 176 | |||
| 177 | throw new LoaderLoadException($resource, $sourceResource, 0, $e, $type); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | return null; |
||
| 182 | } |
||
| 184 |