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