| Conditions | 16 |
| Paths | 1536 |
| Total Lines | 155 |
| Code Lines | 97 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 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 |
||
| 44 | public function run($request) |
||
| 45 | { |
||
| 46 | $this->addLogHandlers(); |
||
| 47 | |||
| 48 | $args = $request->getVars(); |
||
| 49 | $this->validateArgs($args); |
||
| 50 | |||
| 51 | Injector::inst()->get(FileHashingService::class)->enableCache(); |
||
| 52 | |||
| 53 | // Set max time and memory limit |
||
| 54 | Environment::increaseTimeLimitTo(); |
||
| 55 | Environment::setMemoryLimitMax(-1); |
||
| 56 | Environment::increaseMemoryLimitTo(-1); |
||
| 57 | |||
| 58 | $this->extend('preFileMigration'); |
||
| 59 | |||
| 60 | $this->logger->warn( |
||
| 61 | 'Please read https://docs.silverstripe.org/en/4/developer_guides/files/file_migration/ ' . |
||
| 62 | 'before running this task.' |
||
| 63 | ); |
||
| 64 | |||
| 65 | $subtasks = !empty($args['only']) ? explode(',', $args['only']) : $this->defaultSubtasks; |
||
| 66 | |||
| 67 | $subtask = 'move-files'; |
||
| 68 | if (in_array($subtask, $subtasks)) { |
||
| 69 | if (!class_exists(FileMigrationHelper::class)) { |
||
| 70 | $this->logger->error("No file migration helper detected"); |
||
| 71 | } else { |
||
| 72 | $this->extend('preFileMigrationSubtask', $subtask); |
||
| 73 | |||
| 74 | $this->logger->notice("######################################################"); |
||
| 75 | $this->logger->notice("Migrating filesystem and database records ({$subtask})"); |
||
| 76 | $this->logger->notice("######################################################"); |
||
| 77 | |||
| 78 | FileMigrationHelper::singleton() |
||
| 79 | ->setLogger($this->logger) |
||
| 80 | ->run(); |
||
| 81 | |||
| 82 | // TODO Split file migration helper into two tasks, |
||
| 83 | // and report back on their process counts consistently here |
||
| 84 | // if ($count) { |
||
| 85 | // $this->logger->info("{$count} File objects upgraded"); |
||
| 86 | // } else { |
||
| 87 | // $this->logger->info("No File objects needed upgrading"); |
||
| 88 | // } |
||
| 89 | |||
| 90 | $this->extend('postFileMigrationSubtask', $subtask); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | $subtask = 'move-thumbnails'; |
||
| 95 | if (in_array($subtask, $subtasks)) { |
||
| 96 | if (!class_exists(LegacyThumbnailMigrationHelper::class)) { |
||
| 97 | $this->logger->error("LegacyThumbnailMigrationHelper not found"); |
||
| 98 | } else { |
||
| 99 | $this->extend('preFileMigrationSubtask', $subtask); |
||
| 100 | |||
| 101 | $this->logger->notice("#############################################################"); |
||
| 102 | $this->logger->notice("Migrating existing thumbnails to new file format ({$subtask})"); |
||
| 103 | $this->logger->notice("#############################################################"); |
||
| 104 | |||
| 105 | $paths = LegacyThumbnailMigrationHelper::singleton() |
||
| 106 | ->setLogger($this->logger) |
||
| 107 | ->run($this->getStore()); |
||
| 108 | |||
| 109 | if ($paths) { |
||
| 110 | $this->logger->info(sprintf("%d thumbnails moved", count($paths))); |
||
| 111 | } else { |
||
| 112 | $this->logger->info("No thumbnails needed to be moved"); |
||
| 113 | } |
||
| 114 | |||
| 115 | $this->extend('postFileMigrationSubtask', $subtask); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $subtask = 'generate-cms-thumbnails'; |
||
| 120 | if (in_array($subtask, $subtasks)) { |
||
| 121 | if (!class_exists(ImageThumbnailHelper::class)) { |
||
| 122 | $this->logger->error("ImageThumbnailHelper not found"); |
||
| 123 | } else { |
||
| 124 | $this->extend('preFileMigrationSubtask', $subtask); |
||
| 125 | |||
| 126 | $this->logger->notice("#############################################"); |
||
| 127 | $this->logger->notice("Generating new CMS UI thumbnails ({$subtask})"); |
||
| 128 | $this->logger->notice("#############################################"); |
||
| 129 | |||
| 130 | $count = ImageThumbnailHelper::singleton() |
||
| 131 | ->setLogger($this->logger) |
||
| 132 | ->run(); |
||
| 133 | |||
| 134 | if ($count > 0) { |
||
| 135 | $this->logger->info("Created {$count} CMS UI thumbnails"); |
||
| 136 | } else { |
||
| 137 | $this->logger->info("No CMS UI thumbnails needed to be created"); |
||
| 138 | } |
||
| 139 | |||
| 140 | $this->extend('postFileMigrationSubtask', $subtask); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | $subtask = 'fix-folder-permissions'; |
||
| 145 | if (in_array($subtask, $subtasks)) { |
||
| 146 | if (!class_exists(FixFolderPermissionsHelper::class)) { |
||
| 147 | $this->logger->error("FixFolderPermissionsHelper not found"); |
||
| 148 | } else { |
||
| 149 | $this->extend('preFileMigrationSubtask', $subtask); |
||
| 150 | |||
| 151 | $this->logger->notice("####################################################"); |
||
| 152 | $this->logger->notice("Fixing secure-assets folder permissions ({$subtask})"); |
||
| 153 | $this->logger->notice("####################################################"); |
||
| 154 | $this->logger->debug('Only required if the 3.x project included silverstripe/secure-assets'); |
||
| 155 | |||
| 156 | $count = FixFolderPermissionsHelper::singleton() |
||
| 157 | ->setLogger($this->logger) |
||
| 158 | ->run(); |
||
| 159 | |||
| 160 | if ($count > 0) { |
||
| 161 | $this->logger->info("Repaired {$count} folders with broken CanViewType settings"); |
||
| 162 | } else { |
||
| 163 | $this->logger->info("No folders required fixes"); |
||
| 164 | } |
||
| 165 | |||
| 166 | $this->extend('postFileMigrationSubtask', $subtask); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | $subtask = 'fix-secureassets'; |
||
| 171 | if (in_array($subtask, $subtasks)) { |
||
| 172 | if (!class_exists(SecureAssetsMigrationHelper::class)) { |
||
| 173 | $this->logger->error("SecureAssetsMigrationHelper not found"); |
||
| 174 | } else { |
||
| 175 | $this->extend('preFileMigrationSubtask', $subtask); |
||
| 176 | |||
| 177 | $this->logger->notice("#####################################################"); |
||
| 178 | $this->logger->notice("Fixing secure-assets folder restrictions ({$subtask})"); |
||
| 179 | $this->logger->notice("#####################################################"); |
||
| 180 | $this->logger->debug('Only required if the 3.x project included silverstripe/secure-assets'); |
||
| 181 | |||
| 182 | $paths = SecureAssetsMigrationHelper::singleton() |
||
| 183 | ->setLogger($this->logger) |
||
| 184 | ->run($this->getStore()); |
||
| 185 | |||
| 186 | if (count($paths) > 0) { |
||
| 187 | $this->logger->info(sprintf("Repaired %d folders broken folder restrictions", count($paths))); |
||
| 188 | } else { |
||
| 189 | $this->logger->info("No folders required fixes"); |
||
| 190 | } |
||
| 191 | |||
| 192 | $this->extend('postFileMigrationSubtask', $subtask); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | $this->extend('postFileMigration'); |
||
| 197 | |||
| 198 | $this->logger->info("Done!"); |
||
| 199 | } |
||
| 277 |
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