| Conditions | 11 |
| Paths | 14 |
| Total Lines | 56 |
| Code Lines | 27 |
| 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 |
||
| 73 | public function exec() |
||
| 74 | {
|
||
| 75 | $fs = new FileSystem(); |
||
| 76 | $module = $this->getArgument('module');
|
||
| 77 | $modulePath = modules_dir() . DS . $module; |
||
| 78 | $file = $modulePath . DS . 'Config' . DS . 'routes.php'; |
||
| 79 | $openApiRoutes = " |
||
| 80 | use Quantum\Libraries\Storage\FileSystem; |
||
| 81 | use Quantum\Http\Response; |
||
| 82 | use Quantum\Di\Di; |
||
| 83 | |||
| 84 | return function (\$route) {
|
||
| 85 | //\$route->group('openapi', function (\$route) {
|
||
| 86 | \$route->get('" . strtolower($module) . "/documentation', function (Response \$response) {
|
||
| 87 | \$response->html(partial('swagger/swagger'));
|
||
| 88 | }); |
||
| 89 | |||
| 90 | \$route->get('" . strtolower($module) . "/docs', function (Response \$response) {
|
||
| 91 | \$fs = Di::get(FileSystem::class); |
||
| 92 | \$response->json((array) json_decode(\$fs->get(modules_dir() . DS . '" . $module . "' . DS . 'Resources' . DS . 'swagger' . DS . 'docs.json', true))); |
||
| 93 | //}); |
||
| 94 | });"; |
||
| 95 | if (strpos($fs->get($file), "\$route->group('openapi', function (\$route) {") === false) {
|
||
| 96 | $fs->put($file, str_replace('return function ($route) {', $openApiRoutes, $fs->get($file)));
|
||
| 97 | } |
||
| 98 | if (!is_dir($modulePath)) {
|
||
| 99 | $this->error('The module ' . $module . ' not found');
|
||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!installed($modulePath . DS . 'swagger' . DS . 'docs.json')) {
|
||
| 104 | $fp = fopen($modulePath . DS . 'Resources' . DS . "swagger" . DS . "docs.json", "wb"); |
||
| 105 | fclose($fp); |
||
| 106 | } |
||
| 107 | |||
| 108 | exec(base_dir() . DS . 'vendor/bin/openapi modules/' . $module . '/Controllers/ -o modules/' . $module . '/Resources/swagger/docs.json'); |
||
| 109 | |||
| 110 | |||
| 111 | if (installed(assets_dir() . DS . 'SwaggerUi' . DS . 'index.css')) {
|
||
| 112 | $this->error('The swagger ui already installed');
|
||
| 113 | return; |
||
| 114 | } |
||
| 115 | |||
| 116 | $dir = opendir($this->vendorSwaggerFolderPath); |
||
| 117 | |||
| 118 | if (is_resource($dir)) {
|
||
| 119 | while (($file = readdir($dir))) {
|
||
| 120 | if ($file && ($file != '.') && ($file != '..') && !in_array($file, $this->excludeFileNames)) {
|
||
| 121 | copy($this->vendorSwaggerFolderPath . '/' . $file, $this->publicSwaggerFolderPath . '/' . $file); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | closedir($dir); |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->info('Swagger assets successfully published');
|
||
| 129 | } |
||
| 131 |