| Conditions | 12 |
| Paths | 7 |
| Total Lines | 83 |
| Code Lines | 56 |
| 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 |
||
| 91 | public function check() |
||
| 92 | { |
||
| 93 | $origStage = Versioned::get_reading_mode(); |
||
| 94 | Versioned::set_reading_mode(Versioned::LIVE); |
||
| 95 | |||
| 96 | $files = $this->getFiles(); |
||
| 97 | if ($files) { |
||
| 98 | $fileTypeValidateFunc = $this->fileTypeValidateFunc; |
||
| 99 | if (method_exists($this, $fileTypeValidateFunc)) { |
||
| 100 | $invalidFiles = []; |
||
| 101 | $validFiles = []; |
||
| 102 | |||
| 103 | foreach ($files as $file) { |
||
| 104 | if ($this->$fileTypeValidateFunc($file)) { |
||
| 105 | $validFiles[] = $file; |
||
| 106 | } else { |
||
| 107 | $invalidFiles[] = $file; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | // If at least one file was valid, count as passed |
||
| 112 | if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) { |
||
| 113 | $validFileList = PHP_EOL; |
||
| 114 | foreach ($validFiles as $vf) { |
||
| 115 | $validFileList .= $vf . PHP_EOL; |
||
| 116 | } |
||
| 117 | if ($fileTypeValidateFunc == 'noVidation') { |
||
| 118 | $checkReturn = [ |
||
| 119 | EnvironmentCheck::OK, |
||
| 120 | sprintf('At least these file(s) accessible: %s', $validFileList) |
||
| 121 | ]; |
||
| 122 | } else { |
||
| 123 | $checkReturn = [ |
||
| 124 | EnvironmentCheck::OK, |
||
| 125 | sprintf( |
||
| 126 | 'At least these file(s) passed file type validate function "%s": %s', |
||
| 127 | $fileTypeValidateFunc, |
||
| 128 | $validFileList |
||
| 129 | ) |
||
| 130 | ]; |
||
| 131 | } |
||
| 132 | } else { |
||
| 133 | if (count($invalidFiles) == 0) { |
||
| 134 | $checkReturn = [EnvironmentCheck::OK, 'All files valideted']; |
||
| 135 | } else { |
||
| 136 | $invalidFileList = PHP_EOL; |
||
| 137 | foreach ($invalidFiles as $vf) { |
||
| 138 | $invalidFileList .= $vf . PHP_EOL; |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($fileTypeValidateFunc == 'noVidation') { |
||
| 142 | $checkReturn = [ |
||
| 143 | EnvironmentCheck::ERROR, |
||
| 144 | sprintf('File(s) not accessible: %s', $invalidFileList) |
||
| 145 | ]; |
||
| 146 | } else { |
||
| 147 | $checkReturn = [ |
||
| 148 | EnvironmentCheck::ERROR, |
||
| 149 | sprintf( |
||
| 150 | 'File(s) not passing the file type validate function "%s": %s', |
||
| 151 | $fileTypeValidateFunc, |
||
| 152 | $invalidFileList |
||
| 153 | ) |
||
| 154 | ]; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } else { |
||
| 159 | $checkReturn = array( |
||
| 160 | EnvironmentCheck::ERROR, |
||
| 161 | sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc) |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | } else { |
||
| 165 | $checkReturn = array( |
||
| 166 | EnvironmentCheck::ERROR, |
||
| 167 | sprintf("No files accessible at path %s", $this->path) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | |||
| 171 | Versioned::set_reading_mode($origStage); |
||
| 172 | |||
| 173 | return $checkReturn; |
||
| 174 | } |
||
| 210 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.