Conditions | 7 |
Paths | 8 |
Total Lines | 55 |
Code Lines | 33 |
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 |
||
57 | private function getChangedFiles($buildPath, $packages) |
||
58 | { |
||
59 | $modifiedFiles = $deletedFiles = $packageZips = []; |
||
60 | |||
61 | foreach ($packages as $package) { |
||
62 | $zip = new \ZipArchive(); |
||
63 | if (!$zip->open($package)) { |
||
64 | throw new \RuntimeException(sprintf('Can\'t open zip archive: %s', $package)); |
||
65 | } |
||
66 | |||
67 | $packageZips[$package] = $zip; |
||
68 | |||
69 | eval(str_replace(['<?php', '<?', '?>'], '', $zip->getFromName(basename($package, '.zip') . DS . 'files.md5'))); |
||
70 | $packageModifiedFiles = array_keys($md5_string); |
||
71 | |||
72 | if ($filesToRemove = $zip->getFromName('filesToRemove.txt')) { |
||
73 | $packageDeletedFiles = explode(PHP_EOL, str_replace(["\r\n", "\r", "\n"], PHP_EOL, $filesToRemove)); |
||
74 | } else if ($filesToRemove = $zip->getFromName('filesToRemove.json')) { |
||
75 | $packageDeletedFiles = json_decode($filesToRemove); |
||
76 | } else { |
||
77 | throw new \RuntimeException('Can\'t open filesToRemove'); |
||
78 | } |
||
79 | |||
80 | $modifiedFiles = array_merge($modifiedFiles, array_combine($packageModifiedFiles, array_fill(0, count($packageModifiedFiles), $package))); |
||
81 | $deletedFiles = array_diff(array_merge($deletedFiles, $packageDeletedFiles), $packageModifiedFiles); |
||
82 | } |
||
83 | |||
84 | $modifiedFiles = array_keys(array_filter($modifiedFiles, function ($package, $changedFile) use ($buildPath, $packageZips) { |
||
85 | if (($buildFile = @file_get_contents($buildPath . DS . $changedFile)) === false) { |
||
86 | return false; |
||
87 | } |
||
88 | $packageFile = $packageZips[$package]->getFromName(basename($package, '.zip') . DS . $changedFile); |
||
89 | |||
90 | return $this->getCheckSum($buildFile) != $this->getCheckSum($packageFile); |
||
91 | }, ARRAY_FILTER_USE_BOTH)); |
||
92 | |||
93 | $deletedFiles = array_values(array_filter($deletedFiles)); |
||
94 | |||
95 | foreach ($packageZips as $zip) { |
||
96 | $zip->close(); |
||
97 | } |
||
98 | |||
99 | $modifiedFiles = array_values(array_filter($modifiedFiles, function ($file) use ($buildPath) { |
||
100 | return file_exists($buildPath . '/custom/' . $file); |
||
101 | })); |
||
102 | |||
103 | $deletedFiles = array_values(array_filter($deletedFiles, function ($file) use ($buildPath) { |
||
104 | return file_exists($buildPath . '/custom/' . $file); |
||
105 | })); |
||
106 | |||
107 | natsort($modifiedFiles); |
||
108 | natsort($deletedFiles); |
||
109 | |||
110 | return ['modified_files' => $modifiedFiles, 'deleted_files' => $deletedFiles]; |
||
111 | } |
||
112 | |||
189 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.