| Conditions | 31 |
| Paths | 7058 |
| Total Lines | 163 |
| Code Lines | 100 |
| 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 |
||
| 129 | public function main() |
||
| 130 | { |
||
| 131 | if ((0 === count($this->sourceFileSets)) && (0 === count($this->sourceFileLists))) { |
||
| 132 | throw new BuildException( |
||
| 133 | 'At least one <srcfileset> or <srcfilelist>' |
||
| 134 | . ' element must be set' |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | if ((0 === count($this->targetFileSets)) && (0 === count($this->targetFileLists))) { |
||
| 138 | throw new BuildException( |
||
| 139 | 'At least one <targetfileset> or' |
||
| 140 | . ' <targetfilelist> element must be set' |
||
| 141 | ); |
||
| 142 | } |
||
| 143 | $now = (new DateTime())->getTimestamp(); |
||
| 144 | /* |
||
| 145 | We have to munge the time to allow for the filesystem time |
||
| 146 | granularity. |
||
| 147 | */ |
||
| 148 | // $now += FILE_UTILS . getFileTimestampGranularity(); |
||
| 149 | |||
| 150 | // Grab all the target files specified via filesets: |
||
| 151 | $allTargets = []; |
||
| 152 | $oldestTargetTime = 0; |
||
| 153 | $oldestTarget = null; |
||
| 154 | foreach ($this->targetFileSets as $targetFS) { |
||
| 155 | if (!$targetFS->getDir($this->getProject())->exists()) { |
||
| 156 | // this is the same as if it was empty, no target files found |
||
| 157 | continue; |
||
| 158 | } |
||
| 159 | $targetDS = $targetFS->getDirectoryScanner($this->getProject()); |
||
| 160 | $targetFiles = $targetDS->getIncludedFiles(); |
||
| 161 | |||
| 162 | foreach ($targetFiles as $targetFile) { |
||
| 163 | $dest = new File($targetFS->getDir($this->getProject()), $targetFile); |
||
| 164 | $allTargets[] = $dest; |
||
| 165 | |||
| 166 | if ($dest->lastModified() > $now) { |
||
| 167 | $this->log( |
||
| 168 | 'Warning: ' . $targetFile . ' modified in the future.', |
||
| 169 | Project::MSG_WARN |
||
| 170 | ); |
||
| 171 | } |
||
| 172 | if ( |
||
| 173 | null === $oldestTarget |
||
| 174 | || $dest->lastModified() < $oldestTargetTime |
||
| 175 | ) { |
||
| 176 | $oldestTargetTime = $dest->lastModified(); |
||
| 177 | $oldestTarget = $dest; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | // Grab all the target files specified via filelists: |
||
| 182 | $upToDate = true; |
||
| 183 | foreach ($this->targetFileLists as $targetFL) { |
||
| 184 | $targetFiles = $targetFL->getFiles($this->getProject()); |
||
| 185 | |||
| 186 | foreach ($targetFiles as $targetFile) { |
||
| 187 | $dest = new File($targetFL->getDir($this->getProject()), $targetFile); |
||
| 188 | if (!$dest->exists()) { |
||
| 189 | $this->log($targetFile . ' does not exist.', Project::MSG_VERBOSE); |
||
| 190 | $upToDate = false; |
||
| 191 | |||
| 192 | continue; |
||
| 193 | } |
||
| 194 | |||
| 195 | $allTargets[] = $dest; |
||
| 196 | if ($dest->lastModified() > $now) { |
||
| 197 | $this->log( |
||
| 198 | 'Warning: ' . $targetFile . ' modified in the future.', |
||
| 199 | Project::MSG_WARN |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | if ( |
||
| 203 | null === $oldestTarget |
||
| 204 | || $dest->lastModified() < $oldestTargetTime |
||
| 205 | ) { |
||
| 206 | $oldestTargetTime = $dest->lastModified(); |
||
| 207 | $oldestTarget = $dest; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | if (null !== $oldestTarget) { |
||
| 212 | $this->log($oldestTarget . ' is oldest target file', Project::MSG_VERBOSE); |
||
| 213 | } else { |
||
| 214 | // no target files, then we cannot remove any target files and |
||
| 215 | // skip the following tests right away |
||
| 216 | $upToDate = false; |
||
| 217 | } |
||
| 218 | // Check targets vs source files specified via filelists: |
||
| 219 | if ($upToDate) { |
||
| 220 | foreach ($this->sourceFileLists as $sourceFL) { |
||
| 221 | $sourceFiles = $sourceFL->getFiles($this->getProject()); |
||
| 222 | |||
| 223 | foreach ($sourceFiles as $sourceFile) { |
||
| 224 | $src = new File($sourceFL->getDir($this->getProject()), $sourceFile); |
||
| 225 | |||
| 226 | if ($src->lastModified() > $now) { |
||
| 227 | $this->log( |
||
| 228 | 'Warning: ' . $sourceFile |
||
| 229 | . ' modified in the future.', |
||
| 230 | Project::MSG_WARN |
||
| 231 | ); |
||
| 232 | } |
||
| 233 | if (!$src->exists()) { |
||
| 234 | $this->log( |
||
| 235 | $sourceFile . ' does not exist.', |
||
| 236 | Project::MSG_VERBOSE |
||
| 237 | ); |
||
| 238 | $upToDate = false; |
||
| 239 | |||
| 240 | break 2; |
||
| 241 | } |
||
| 242 | if ($src->lastModified() > $oldestTargetTime) { |
||
| 243 | $upToDate = false; |
||
| 244 | $this->log( |
||
| 245 | $oldestTarget . ' is out of date with respect to ' |
||
| 246 | . $sourceFile, |
||
| 247 | Project::MSG_VERBOSE |
||
| 248 | ); |
||
| 249 | |||
| 250 | break 2; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | } |
||
| 254 | } |
||
| 255 | // Check targets vs source files specified via filesets: |
||
| 256 | if ($upToDate) { |
||
| 257 | foreach ($this->sourceFileSets as $sourceFS) { |
||
| 258 | $sourceDS = $sourceFS->getDirectoryScanner($this->getProject()); |
||
| 259 | $sourceFiles = $sourceDS->getIncludedFiles(); |
||
| 260 | |||
| 261 | foreach ($sourceFiles as $sourceFile) { |
||
| 262 | $src = new File($sourceFS->getDir($this->getProject()), $sourceFile); |
||
| 263 | |||
| 264 | if ($src->lastModified() > $now) { |
||
| 265 | $this->log( |
||
| 266 | 'Warning: ' . $sourceFile |
||
| 267 | . ' modified in the future.', |
||
| 268 | Project::MSG_WARN |
||
| 269 | ); |
||
| 270 | } |
||
| 271 | if ($src->lastModified() > $oldestTargetTime) { |
||
| 272 | $upToDate = false; |
||
| 273 | $this->log( |
||
| 274 | $oldestTarget . ' is out of date with respect to ' |
||
| 275 | . $sourceFile, |
||
| 276 | Project::MSG_VERBOSE |
||
| 277 | ); |
||
| 278 | |||
| 279 | break 2; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | } |
||
| 284 | if (!$upToDate) { |
||
| 285 | $this->log('Deleting all target files. ', Project::MSG_VERBOSE); |
||
| 286 | foreach ($allTargets as $fileToRemove) { |
||
| 287 | $this->log( |
||
| 288 | 'Deleting file ' . $fileToRemove->getAbsolutePath(), |
||
| 289 | Project::MSG_VERBOSE |
||
| 290 | ); |
||
| 291 | $fileToRemove->delete(); |
||
| 292 | } |
||
| 296 |