Conditions | 15 |
Paths | 364 |
Total Lines | 58 |
Code Lines | 42 |
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 | var_dump($_POST['files']); |
||
|
|||
20 | $files = \Files\File::getList(['where' => ['id', $_POST['files'], 'IN']]); |
||
21 | foreach ($files as $file) { |
||
22 | $file->delete(); |
||
23 | } |
||
24 | } |
||
25 | $usedImages = []; |
||
26 | $installedModules = \Module::getInstalled(App::$primary); |
||
27 | foreach ($installedModules as $module) { |
||
28 | foreach (\Module::getModels($module) as $modelPath => $modelName) { |
||
29 | foreach ($modelName::$cols as $colName => $col) { |
||
30 | if ($col['type'] == 'image') { |
||
31 | $items = $modelName::getList(['where' => [$colName, 0, '!='], 'array' => true, 'key' => false, 'cols' => $modelName::colPrefix() . $colName]); |
||
32 | if ($items) { |
||
33 | foreach ($items as $item) { |
||
34 | $usedImages[$item[$modelName::colPrefix() . $colName]] = true; |
||
35 | } |
||
36 | |||
37 | } |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | echo '<form method="post"><table>'; |
||
43 | $missingImages = \Files\File::getList(['where' => ['id', array_keys($usedImages), 'NOT IN'], 'key' => 'path', 'array' => true]); |
||
44 | $texts = ''; |
||
45 | foreach (\Materials\Material::getList(['array' => true]) as $material) { |
||
46 | $texts .= $material['material_preview']; |
||
47 | $texts .= $material['material_text']; |
||
48 | } |
||
49 | if (!empty($installedModules['TextBlocks'])) { |
||
50 | foreach (\TextBlocks\Block::getList(['array' => true]) as $block) { |
||
51 | var_dump($block); |
||
52 | exit(); |
||
53 | $texts .= $material['material_preview']; |
||
54 | $texts .= $material['material_text']; |
||
55 | } |
||
56 | } |
||
57 | $deleted = 0; |
||
58 | foreach ($missingImages as $path => $file) { |
||
59 | if (strpos($texts, $path)) { |
||
60 | unset($missingImages[$path]); |
||
61 | $deleted++; |
||
62 | } |
||
63 | } |
||
64 | foreach ($missingImages as $path => $file) { |
||
65 | echo '<tr>'; |
||
66 | echo "<td><input type='checkbox' name='files[]' value='{$file['file_id']}' checked /></td>"; |
||
67 | echo "<td>{$file['file_id']}</td>"; |
||
68 | echo "<td>{$file['file_code']}</td>"; |
||
69 | echo "<td>{$file['file_upload_code']}</td>"; |
||
70 | echo "<td>{$file['file_name']}</td>"; |
||
71 | echo '</tr>'; |
||
72 | } |
||
73 | echo '</table><button>Удалить</button></form>'; |
||
74 | } |
||
75 | |||
77 |