| Conditions | 22 |
| Paths | 2016 |
| Total Lines | 79 |
| 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 |
||
| 17 | public function clearMissingAction() { |
||
| 18 | if (!empty($_POST['files'])) { |
||
| 19 | $files = \Files\File::getList(['where' => ['id', $_POST['files'], 'IN']]); |
||
| 20 | foreach ($files as $file) { |
||
| 21 | $file->delete(); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | if (!empty($_POST['untrackedfiles'])) { |
||
| 25 | foreach ($_POST['untrackedfiles'] as $file) { |
||
| 26 | if (strpos($file, '..') !== false || strpos($file, '/static/mediafiles') !== 0) { |
||
| 27 | continue; |
||
| 28 | } |
||
| 29 | unlink(\App::$primary->path . $file); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | $usedImages = []; |
||
| 33 | $installedModules = \Module::getInstalled(App::$primary); |
||
| 34 | foreach ($installedModules as $module) { |
||
| 35 | foreach (\Module::getModels($module) as $modelPath => $modelName) { |
||
| 36 | foreach ($modelName::$cols as $colName => $col) { |
||
| 37 | if ($col['type'] == 'image') { |
||
| 38 | $items = $modelName::getList(['where' => [$colName, 0, '!='], 'array' => true, 'key' => false, 'cols' => $modelName::colPrefix() . $colName]); |
||
| 39 | if ($items) { |
||
| 40 | foreach ($items as $item) { |
||
| 41 | $usedImages[$item[$modelName::colPrefix() . $colName]] = true; |
||
| 42 | } |
||
| 43 | |||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | $allImages = \Files\File::getList(['key' => 'path', 'array' => true, 'cols' => 'file_path']); |
||
| 50 | $result = []; |
||
| 51 | Tools::getDirContents(\App::$primary->path . '/static/mediafiles', $result, '/static/mediafiles'); |
||
|
|
|||
| 52 | echo '<form method="post"><table>'; |
||
| 53 | foreach ($result as $file) { |
||
| 54 | if (!isset($allImages[$file])) { |
||
| 55 | echo '<tr>'; |
||
| 56 | echo "<td><input type='checkbox' name='untrackedfiles[]' value='{$file}' checked /></td>"; |
||
| 57 | echo "<td></td>"; |
||
| 58 | echo "<td></td>"; |
||
| 59 | echo "<td>untracked file</td>"; |
||
| 60 | echo "<td></td>"; |
||
| 61 | echo "<td><a href='{$file}' target='_blank'>{$file}</a></td>"; |
||
| 62 | echo '</tr>'; |
||
| 63 | } |
||
| 64 | |||
| 65 | } |
||
| 66 | |||
| 67 | $missingImages = \Files\File::getList(['where' => ['id', array_keys($usedImages), 'NOT IN'], 'key' => 'path', 'array' => true]); |
||
| 68 | $texts = ''; |
||
| 69 | foreach (\Materials\Material::getList(['array' => true]) as $material) { |
||
| 70 | $texts .= $material['material_preview']; |
||
| 71 | $texts .= $material['material_text']; |
||
| 72 | } |
||
| 73 | if (!empty($installedModules['TextBlocks'])) { |
||
| 74 | foreach (\TextBlocks\Block::getList(['array' => true]) as $block) { |
||
| 75 | $texts .= $block['block_text']; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | $deleted = 0; |
||
| 79 | foreach ($missingImages as $path => $file) { |
||
| 80 | if (strpos($texts, $path)) { |
||
| 81 | unset($missingImages[$path]); |
||
| 82 | $deleted++; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | foreach ($missingImages as $path => $file) { |
||
| 86 | echo '<tr>'; |
||
| 87 | echo "<td><input type='checkbox' name='files[]' value='{$file['file_id']}' " . ($file['file_upload_code'] == 'MigrationUpload' ? 'checked' : '') . " /></td>"; |
||
| 88 | echo "<td>{$file['file_id']}</td>"; |
||
| 89 | echo "<td>{$file['file_code']}</td>"; |
||
| 90 | echo "<td>{$file['file_upload_code']}</td>"; |
||
| 91 | echo "<td>{$file['file_name']}</td>"; |
||
| 92 | echo "<td><a href='{$path}' target='_blank'>{$path}</a></td>"; |
||
| 93 | echo '</tr>'; |
||
| 94 | } |
||
| 95 | echo '</table><button>Удалить</button></form>'; |
||
| 96 | } |
||
| 99 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths