Conditions | 10 |
Paths | 14 |
Total Lines | 55 |
Code Lines | 30 |
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 |
||
86 | private function load(string $set): ?array |
||
87 | { |
||
88 | $metadatasetdir = $this->directory . $set . '.d'; |
||
89 | |||
90 | if (!$this->fileSystem->exists($metadatasetdir)) { |
||
91 | return null; |
||
92 | } |
||
93 | |||
94 | /** @psalm-var mixed $metadata We cannot be sure what the include below will do with this var */ |
||
95 | $metadata = []; |
||
96 | |||
97 | $dh = @opendir($metadatasetdir); |
||
98 | if ($dh === false) { |
||
99 | Logger::warning( |
||
100 | 'Directory metadata handler: Unable to open directory: ' . var_export($metadatasetdir, true), |
||
101 | ); |
||
102 | return $metadata; |
||
103 | } |
||
104 | |||
105 | while (($entry = readdir($dh)) !== false) { |
||
106 | if ($entry[0] === '.') { |
||
107 | // skip '..', '.' and hidden files |
||
108 | continue; |
||
109 | } |
||
110 | |||
111 | $path = $metadatasetdir . DIRECTORY_SEPARATOR . $entry; |
||
112 | if (is_dir($path)) { |
||
113 | Logger::warning( |
||
114 | 'Directory metadata handler: Metadata directory contained a directory where only files should ' . |
||
115 | 'exist: ' . var_export($path, true), |
||
116 | ); |
||
117 | continue; |
||
118 | } |
||
119 | |||
120 | if (str_ends_with($path, '.php') || str_ends_with($path, '.xml')) { |
||
121 | $type = 'flatfile'; |
||
122 | if (str_ends_with($path, '.xml')) { |
||
123 | $type = 'xml'; |
||
124 | } |
||
125 | Logger::info("loading set $set metadata file at $path"); |
||
126 | |||
127 | $config = [ 'type' => $type, 'file' => $path ]; |
||
128 | $source = MetaDataStorageSource::getSource($config); |
||
129 | $md = $source->getMetadataSet($set); |
||
130 | $metadata = array_merge($metadata, $md); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | |||
135 | |||
136 | |||
137 | if (!is_array($metadata)) { |
||
138 | throw new Exception('Could not load metadata set [' . $set . '] from file: ' . $metadatasetfile); |
||
139 | } |
||
140 | return $metadata; |
||
141 | } |
||
181 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.