| Conditions | 10 |
| Paths | 27 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 24.1991 |
| 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 |
||
| 13 | 21 | function __construct($fileName){ |
|
|
|
|||
| 14 | 21 | $fileNames = array(); |
|
| 15 | 21 | if(is_string($fileName)){ |
|
| 16 | $fileNames[]=$fileName; |
||
| 17 | }else{ |
||
| 18 | 21 | is_array($fileName) or \PhpBoot\abort(new \InvalidArgumentException("string or array is required by param 0")); |
|
| 19 | 21 | $fileNames = $fileName; |
|
| 20 | } |
||
| 21 | 21 | foreach ($fileNames as $fileName){ |
|
| 22 | 21 | if(is_file($fileName)){ |
|
| 23 | 21 | $this->fileName[$fileName] = @filemtime($fileName); |
|
| 24 | 21 | }else { |
|
| 25 | $this->fileName[$fileName] = @filemtime($fileName); |
||
| 26 | if(!is_dir($fileName)){ |
||
| 27 | continue; |
||
| 28 | } |
||
| 29 | $files = @dir($fileName) or \PhpBoot\abort("open dir $fileName failed"); |
||
| 30 | while (!!($file = $files->read())){ |
||
| 31 | if($file == '.' || $file == '..') { |
||
| 32 | continue; |
||
| 33 | } |
||
| 34 | $this->fileName[$fileName.'/'.$file] = @filemtime($fileName.'/'.$file); |
||
| 35 | } |
||
| 36 | $files->close(); |
||
| 37 | } |
||
| 38 | 21 | } |
|
| 39 | 21 | } |
|
| 40 | /** |
||
| 56 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.