| Conditions | 10 |
| Paths | 10 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 19 | public function validate($filePaths) : array |
||
| 20 | { |
||
| 21 | |||
| 22 | if (is_array($filePaths) === false) { |
||
| 23 | $filePaths = [$filePaths]; |
||
| 24 | } |
||
| 25 | |||
| 26 | foreach ($filePaths as $filePath) { |
||
| 27 | |||
| 28 | if (is_string($filePath) === false || |
||
| 29 | file_exists($filePath) === false || |
||
|
|
|||
| 30 | is_readable($filePath) === false || |
||
| 31 | is_file($filePath) === false |
||
| 32 | ) { |
||
| 33 | return ["Invalid file path"]; |
||
| 34 | } |
||
| 35 | |||
| 36 | $fileSystem = new Filesystem; |
||
| 37 | $fileMimeType = $fileSystem->mimeType($filePath); |
||
| 38 | if ($fileMimeType !== "text/plain") { |
||
| 39 | return ["Invalid file type"]; |
||
| 40 | } |
||
| 41 | |||
| 42 | if (file($filePath) === false || |
||
| 43 | count(file($filePath)) === 0) { |
||
| 44 | return ["Empty file"]; |
||
| 45 | } |
||
| 46 | |||
| 47 | } |
||
| 48 | |||
| 49 | return []; |
||
| 50 | |||
| 88 |