| Conditions | 7 |
| Paths | 1 |
| Total Lines | 195 |
| Code Lines | 109 |
| 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 declare(strict_types=1); |
||
| 36 | public function setup(\Pimple\Container $container): void |
||
| 37 | { |
||
| 38 | $backupDir = SW_PATH . \DIRECTORY_SEPARATOR . 'files' . \DIRECTORY_SEPARATOR . 'backup' . \DIRECTORY_SEPARATOR . 'auto_update'; |
||
| 39 | |||
| 40 | $me = $this; |
||
| 41 | |||
| 42 | $container['shopware.version'] = function () use ($me) { |
||
| 43 | $version = trim(file_get_contents(UPDATE_ASSET_PATH . \DIRECTORY_SEPARATOR . 'version')); |
||
| 44 | |||
| 45 | return $version; |
||
| 46 | }; |
||
| 47 | |||
| 48 | $container['env.path'] = static function () { |
||
| 49 | return SW_PATH . '/.env'; |
||
| 50 | }; |
||
| 51 | |||
| 52 | $container['default.env.path'] = static function () { |
||
| 53 | return UPDATE_ASSET_PATH . '/.env.defaults'; |
||
| 54 | }; |
||
| 55 | |||
| 56 | $container['default.env'] = static function ($c) { |
||
| 57 | if (!is_readable($c['default.env.path'])) { |
||
| 58 | return []; |
||
| 59 | } |
||
| 60 | |||
| 61 | return (new DotEnv()) |
||
| 62 | ->usePutenv(true) |
||
| 63 | ->parse(file_get_contents($c['default.env.path']), $c['default.env.path']); |
||
| 64 | }; |
||
| 65 | |||
| 66 | $container['env.path'] = static function () { |
||
| 67 | return SW_PATH . '/.env'; |
||
| 68 | }; |
||
| 69 | |||
| 70 | $container['env.load'] = static function ($c) { |
||
| 71 | $defaultPath = $c['default.env.path']; |
||
| 72 | $path = $c['env.path']; |
||
| 73 | |||
| 74 | return static function () use ($defaultPath, $path): void { |
||
| 75 | if (is_readable((string) $defaultPath)) { |
||
| 76 | (new Dotenv()) |
||
| 77 | ->usePutenv(true) |
||
| 78 | ->load((string) $defaultPath); |
||
| 79 | } |
||
| 80 | if (is_readable((string) $path)) { |
||
| 81 | (new Dotenv()) |
||
| 82 | ->usePutenv(true) |
||
| 83 | ->load((string) $path); |
||
| 84 | } |
||
| 85 | }; |
||
| 86 | }; |
||
| 87 | |||
| 88 | $container['feature.isActive'] = static function ($c) { |
||
| 89 | // load .env on first call |
||
| 90 | $c['env.load'](); |
||
| 91 | |||
| 92 | return static function (string $featureName): bool { |
||
| 93 | return Feature::isActive($featureName); |
||
| 94 | }; |
||
| 95 | }; |
||
| 96 | |||
| 97 | $container['db'] = function () { |
||
| 98 | return Utils::getConnection(SW_PATH); |
||
| 99 | }; |
||
| 100 | |||
| 101 | $container['dbal'] = function ($c) { |
||
| 102 | $options = [ |
||
| 103 | 'pdo' => $c['db'], |
||
| 104 | 'driver' => 'pdo_mysql', |
||
| 105 | ]; |
||
| 106 | |||
| 107 | return DriverManager::getConnection($options); |
||
| 108 | }; |
||
| 109 | |||
| 110 | $container['filesystem.factory'] = function () use ($me) { |
||
| 111 | $updateConfig = $me->getParameter('update.config'); |
||
| 112 | $ftp = (isset($updateConfig['ftp_credentials'])) ? $updateConfig['ftp_credentials'] : []; |
||
| 113 | |||
| 114 | return new FilesystemFactory(SW_PATH, $ftp); |
||
| 115 | }; |
||
| 116 | |||
| 117 | $container['path.builder'] = function () use ($backupDir) { |
||
| 118 | $baseDir = SW_PATH; |
||
| 119 | $updateDir = UPDATE_FILES_PATH; |
||
| 120 | |||
| 121 | return new PathBuilder($baseDir, $updateDir, $backupDir); |
||
| 122 | }; |
||
| 123 | |||
| 124 | $container['migration.sources'] = static function ($c) { |
||
| 125 | return MigrationSourceCollector::collect(); |
||
| 126 | }; |
||
| 127 | |||
| 128 | $container['migration.runtime'] = static function ($c) { |
||
| 129 | return new CoreMigrationRuntime($c['dbal'], new NullLogger()); |
||
| 130 | }; |
||
| 131 | |||
| 132 | $container['migration.collection.loader'] = static function ($c) { |
||
| 133 | return new CoreMigrationCollectionLoader($c['dbal'], $c['migration.runtime'], $c['migration.sources']); |
||
| 134 | }; |
||
| 135 | |||
| 136 | $container['app'] = function ($c) { |
||
| 137 | foreach ($c['config']['slim'] as $k => $v) { |
||
| 138 | $c[$k] = $v; |
||
| 139 | } |
||
| 140 | |||
| 141 | return new App($c); |
||
| 142 | }; |
||
| 143 | |||
| 144 | $container['http-client'] = function () { |
||
| 145 | return new CurlClient(); |
||
| 146 | }; |
||
| 147 | |||
| 148 | $container['store.api'] = function () use ($me) { |
||
| 149 | return new StoreApi( |
||
| 150 | $me->get('http-client'), |
||
| 151 | $me->getParameter('storeapi.endpoint') |
||
| 152 | ); |
||
| 153 | }; |
||
| 154 | |||
| 155 | $container['cleanup.files.finder'] = function () { |
||
| 156 | return new CleanupFilesFinder(SW_PATH); |
||
| 157 | }; |
||
| 158 | |||
| 159 | $container['system.locker'] = function () { |
||
| 160 | return new SystemLocker( |
||
| 161 | SW_PATH . \DIRECTORY_SEPARATOR . 'recovery' . \DIRECTORY_SEPARATOR . 'install' . \DIRECTORY_SEPARATOR . 'data' . \DIRECTORY_SEPARATOR . 'install.lock' |
||
| 162 | ); |
||
| 163 | }; |
||
| 164 | |||
| 165 | $container['controller.batch'] = function () use ($me) { |
||
| 166 | return new BatchController( |
||
| 167 | $me |
||
| 168 | ); |
||
| 169 | }; |
||
| 170 | |||
| 171 | $container['controller.requirements'] = function () use ($me) { |
||
| 172 | return new RequirementsController( |
||
| 173 | $me, |
||
| 174 | $me->get('app') |
||
| 175 | ); |
||
| 176 | }; |
||
| 177 | |||
| 178 | $container['controller.cleanup'] = function () use ($me, $backupDir) { |
||
| 179 | return new CleanupController( |
||
| 180 | $me->get('cleanup.files.finder'), |
||
| 181 | $me->get('shopware.update.cleanup'), |
||
| 182 | $me->get('app'), |
||
| 183 | SW_PATH, |
||
| 184 | $backupDir |
||
| 185 | ); |
||
| 186 | }; |
||
| 187 | |||
| 188 | $container['shopware.update.cleanup'] = function ($container) use ($backupDir) { |
||
| 189 | return new Cleanup(SW_PATH, $backupDir); |
||
| 190 | }; |
||
| 191 | |||
| 192 | $container['shopware.update.chmod'] = function ($container) { |
||
| 193 | return new FilePermissionChanger([ |
||
| 194 | ['chmod' => 0775, 'filePath' => SW_PATH . '/bin/console'], |
||
| 195 | ]); |
||
| 196 | }; |
||
| 197 | |||
| 198 | $container['renderer'] = function ($c) { |
||
| 199 | return new PhpRenderer($c['config']['slim']['templates.path']); |
||
| 200 | }; |
||
| 201 | |||
| 202 | $container['errorHandler'] = function ($c) { |
||
| 203 | return static function (ServerRequestInterface $request, ResponseInterface $response, \Throwable $e) use ($c) { |
||
| 204 | if (empty($request->getHeader('X-Requested-With'))) { |
||
| 205 | throw $e; |
||
| 206 | } |
||
| 207 | |||
| 208 | $data = [ |
||
| 209 | 'code' => $e->getCode(), |
||
| 210 | 'message' => $e->getMessage(), |
||
| 211 | 'file' => $e->getFile(), |
||
| 212 | 'line' => $e->getLine(), |
||
| 213 | 'trace' => $e->getTraceAsString(), |
||
| 214 | ]; |
||
| 215 | |||
| 216 | return $response->withStatus(500) |
||
| 217 | ->withHeader('Content-Type', 'application/json') |
||
| 218 | ->write(json_encode($data)); |
||
| 219 | }; |
||
| 220 | }; |
||
| 221 | |||
| 222 | $container['jwt_certificate.writer'] = static function () { |
||
| 223 | return new JwtCertificateService( |
||
| 224 | SW_PATH . '/config/jwt/', |
||
| 225 | new JwtCertificateGenerator() |
||
| 226 | ); |
||
| 227 | }; |
||
| 228 | |||
| 229 | $container['system.config'] = static function ($c) { |
||
| 230 | return new RecoveryConfigManager($c['dbal']); |
||
| 231 | }; |
||
| 234 |
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