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