Conditions | 12 |
Paths | 7 |
Total Lines | 84 |
Code Lines | 57 |
Lines | 30 |
Ratio | 35.71 % |
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 |
||
79 | public function check() |
||
80 | { |
||
81 | $origStage = Versioned::get_reading_mode(); |
||
82 | Versioned::set_reading_mode(Versioned::LIVE); |
||
83 | |||
84 | $files = $this->getFiles(); |
||
85 | if ($files) { |
||
86 | $fileTypeValidateFunc = $this->fileTypeValidateFunc; |
||
87 | if (method_exists($this, $fileTypeValidateFunc)) { |
||
88 | $invalidFiles = []; |
||
89 | $validFiles = []; |
||
90 | |||
91 | foreach ($files as $file) { |
||
92 | if ($this->$fileTypeValidateFunc($file)) { |
||
93 | $validFiles[] = $file; |
||
94 | } else { |
||
95 | $invalidFiles[] = $file; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | // If at least one file was valid, count as passed |
||
100 | if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) { |
||
101 | $validFileList = PHP_EOL; |
||
102 | foreach ($validFiles as $vf) { |
||
103 | $validFileList .= $vf . PHP_EOL; |
||
104 | } |
||
105 | View Code Duplication | if ($fileTypeValidateFunc == 'noVidation') { |
|
106 | $checkReturn = [ |
||
107 | EnvironmentCheck::OK, |
||
108 | sprintf('At least these file(s) accessible: %s', $validFileList) |
||
109 | ]; |
||
110 | } else { |
||
111 | $checkReturn = [ |
||
112 | EnvironmentCheck::OK, |
||
113 | sprintf( |
||
114 | 'At least these file(s) passed file type validate function "%s": %s', |
||
115 | $fileTypeValidateFunc, |
||
116 | $validFileList |
||
117 | ) |
||
118 | ]; |
||
119 | } |
||
120 | } else { |
||
121 | if (count($invalidFiles) == 0) { |
||
122 | $checkReturn = [EnvironmentCheck::OK, 'All files valideted']; |
||
123 | } else { |
||
124 | $invalidFileList = PHP_EOL; |
||
125 | foreach ($invalidFiles as $vf) { |
||
126 | $invalidFileList .= $vf . PHP_EOL; |
||
127 | } |
||
128 | |||
129 | View Code Duplication | if ($fileTypeValidateFunc == 'noVidation') { |
|
130 | $checkReturn = [ |
||
131 | EnvironmentCheck::ERROR, |
||
132 | sprintf('File(s) not accessible: %s', $invalidFileList) |
||
133 | ]; |
||
134 | } else { |
||
135 | $checkReturn = [ |
||
136 | EnvironmentCheck::ERROR, |
||
137 | sprintf( |
||
138 | 'File(s) not passing the file type validate function "%s": %s', |
||
139 | $fileTypeValidateFunc, |
||
140 | $invalidFileList |
||
141 | ) |
||
142 | ]; |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | } else { |
||
147 | $checkReturn = array( |
||
148 | EnvironmentCheck::ERROR, |
||
149 | sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc) |
||
150 | ); |
||
151 | } |
||
152 | } else { |
||
153 | $checkReturn = array( |
||
154 | EnvironmentCheck::ERROR, |
||
155 | sprintf("No files accessible at path %s", $this->path) |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | Versioned::set_reading_mode($origStage); |
||
160 | |||
161 | return $checkReturn; |
||
162 | } |
||
163 | |||
198 |
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.