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 |
||
38 | public function buildIndex(string $path, array $excludedPathsRegexp = []): Index |
||
39 | { |
||
40 | $this->logger->info(sprintf("Building index using %s for path '%s' (excluded: %s)...", static::class, $path, implode(',', $excludedPathsRegexp) ?: '-')); |
||
41 | |||
42 | if (!file_exists($path)) |
||
43 | { |
||
44 | throw new \InvalidArgumentException("Given path '{$path}' does not exist."); |
||
45 | } |
||
46 | elseif (!is_dir($path)) |
||
47 | { |
||
48 | throw new \InvalidArgumentException("Given path '{$path}' is not a directory."); |
||
49 | } |
||
50 | elseif (!is_readable($path)) |
||
51 | { |
||
52 | throw new \InvalidArgumentException("Given directory '{$path}' is not readable.'"); |
||
53 | } |
||
54 | |||
55 | $finder = new Finder(); |
||
56 | $finder->in($path); |
||
57 | $finder->ignoreDotFiles(false); |
||
58 | |||
59 | foreach ($excludedPathsRegexp as $excludedPathRegexp) |
||
60 | { |
||
61 | $finder->notPath($excludedPathRegexp); |
||
62 | } |
||
63 | |||
64 | $index = new Index(); |
||
65 | |||
66 | foreach ($finder->directories() as $fileInfo) |
||
67 | { |
||
68 | /** @var SplFileInfo $fileInfo */ |
||
69 | |||
70 | if ($indexObject = $this->buildIndexObject($path, $fileInfo->getRelativePathname())) |
||
|
|||
71 | { |
||
72 | $index->addObject($indexObject); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | foreach ($finder->files() as $fileInfo) |
||
77 | { |
||
78 | /** @var SplFileInfo $fileInfo */ |
||
79 | |||
80 | if ($indexObject = $this->buildIndexObject($path, $fileInfo->getRelativePathname())) |
||
81 | { |
||
82 | $index->addObject($indexObject); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return $index; |
||
87 | } |
||
88 | |||
145 |
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.