Conditions | 10 |
Paths | 21 |
Total Lines | 50 |
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 |
||
27 | public function buildIndex(string $path, array $excludedPathsRegexp = []): Index |
||
28 | { |
||
29 | $this->logger->info(sprintf("Building index using %s for path '%s' (excluded: %s)...", static::class, $path, implode(',', $excludedPathsRegexp) ?: '-')); |
||
30 | |||
31 | if (!file_exists($path)) |
||
32 | { |
||
33 | throw new \InvalidArgumentException("Given path '{$path}' does not exist."); |
||
34 | } |
||
35 | elseif (!is_dir($path)) |
||
36 | { |
||
37 | throw new \InvalidArgumentException("Given path '{$path}' is not a directory."); |
||
38 | } |
||
39 | elseif (!is_readable($path)) |
||
40 | { |
||
41 | throw new \InvalidArgumentException("Given directory '{$path}' is not readable.'"); |
||
42 | } |
||
43 | |||
44 | $finder = new Finder(); |
||
45 | $finder->in($path); |
||
46 | $finder->ignoreDotFiles(false); |
||
47 | |||
48 | foreach ($excludedPathsRegexp as $excludedPathRegexp) |
||
49 | { |
||
50 | $finder->notPath($excludedPathRegexp); |
||
51 | } |
||
52 | |||
53 | $index = new Index(); |
||
54 | |||
55 | foreach ($finder->directories() as $fileInfo) |
||
56 | { |
||
57 | /** @var SplFileInfo $fileInfo */ |
||
58 | |||
59 | if ($indexObject = $this->buildIndexObject($path, $fileInfo->getRelativePathname())) |
||
|
|||
60 | { |
||
61 | $index->addObject($indexObject); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | foreach ($finder->files() as $fileInfo) |
||
66 | { |
||
67 | /** @var SplFileInfo $fileInfo */ |
||
68 | |||
69 | if ($indexObject = $this->buildIndexObject($path, $fileInfo->getRelativePathname())) |
||
70 | { |
||
71 | $index->addObject($indexObject); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | return $index; |
||
76 | } |
||
77 | |||
134 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.