caffeinated /
modules
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Caffeinated\Modules\Console\Generators; |
||
| 4 | |||
| 5 | use Caffeinated\Modules\Modules; |
||
| 6 | use Illuminate\Console\Command as CommandGenerator; |
||
| 7 | use Illuminate\Filesystem\Filesystem; |
||
| 8 | |||
| 9 | class MakeCommand extends CommandGenerator |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Module folders to be created. |
||
| 13 | * |
||
| 14 | * @var array |
||
| 15 | */ |
||
| 16 | protected $listFolders = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Module files to be created. |
||
| 20 | * |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $listFiles = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Module signature option. |
||
| 27 | * |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $signOption = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Module stubs used to populate defined files. |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | protected $listStubs = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The modules instance. |
||
| 41 | * |
||
| 42 | * @var Modules |
||
| 43 | */ |
||
| 44 | protected $module; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The modules path. |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | protected $modulePath; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The modules info. |
||
| 55 | * |
||
| 56 | * @var Illuminate\Support\Collection; |
||
| 57 | */ |
||
| 58 | protected $moduleInfo; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The filesystem instance. |
||
| 62 | * |
||
| 63 | * @var Filesystem |
||
| 64 | */ |
||
| 65 | protected $files; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Array to store the configuration details. |
||
| 69 | * |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | protected $container; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * String to store the command type. |
||
| 76 | * |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | protected $type; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Create a new command instance. |
||
| 83 | * |
||
| 84 | * @param Filesystem $files |
||
| 85 | * @param Modules $module |
||
| 86 | */ |
||
| 87 | public function __construct(Filesystem $files, Modules $module) |
||
| 88 | { |
||
| 89 | parent::__construct(); |
||
| 90 | |||
| 91 | $this->files = $files; |
||
| 92 | $this->module = $module; |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Execute the console command. |
||
| 97 | * |
||
| 98 | * @return mixed |
||
| 99 | */ |
||
| 100 | public function fire() |
||
| 101 | { |
||
| 102 | $slug = $this->parseSlug($this->argument('slug')); |
||
| 103 | $name = $this->parseName($this->argument('name')); |
||
| 104 | |||
| 105 | if ($this->module->exists($slug)) { |
||
| 106 | $this->modulePath = $this->module->getPath(); |
||
| 107 | $this->moduleInfo = collect($this->module->where('slug', $slug)->first()); |
||
| 108 | |||
| 109 | $this->container['slug'] = $slug; |
||
| 110 | $this->container['name'] = $name; |
||
| 111 | |||
| 112 | return $this->generate(); |
||
| 113 | } |
||
| 114 | |||
| 115 | return $this->error('Module '.$this->container['slug'].' does not exist.'); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * generate the console command. |
||
| 120 | * |
||
| 121 | * @return mixed |
||
| 122 | */ |
||
| 123 | protected function generate() |
||
| 124 | { |
||
| 125 | foreach ($this->listFiles as $key => $file) { |
||
| 126 | $filePath = $this->makeFilePath($this->listFolders[$key], $this->container['name']); |
||
| 127 | |||
| 128 | $this->resolveByPath($filePath); |
||
| 129 | |||
| 130 | $file = $this->formatContent($file); |
||
| 131 | $find = basename($filePath); |
||
| 132 | $filePath = strrev(preg_replace(strrev("/$find/"), '', strrev($filePath), 1)); |
||
| 133 | $filePath = $filePath.$file; |
||
| 134 | |||
| 135 | if ($this->files->exists($filePath)) { |
||
| 136 | return $this->error($this->type.' already exists!'); |
||
| 137 | } |
||
| 138 | |||
| 139 | $this->makeDirectory($filePath); |
||
| 140 | |||
| 141 | foreach ($this->signOption as $option) { |
||
| 142 | if ($this->option($option)) { |
||
| 143 | $stubFile = $this->listStubs[$option][$key]; |
||
| 144 | |||
| 145 | $this->resolveByOption($this->option($option)); |
||
| 146 | |||
| 147 | break; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | if (!isset($stubFile)) { |
||
| 152 | $stubFile = $this->listStubs['default'][$key]; |
||
| 153 | } |
||
| 154 | |||
| 155 | $this->files->put( |
||
| 156 | $filePath, |
||
| 157 | $this->getStubContent($stubFile) |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | |||
| 161 | return $this->info($this->type.' created successfully.'); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Resolve Container after getting file path. |
||
| 166 | * |
||
| 167 | * @param string $FilePath |
||
|
0 ignored issues
–
show
|
|||
| 168 | * |
||
| 169 | * @return array |
||
| 170 | */ |
||
| 171 | protected function resolveByPath($filePath) |
||
| 172 | { |
||
| 173 | // |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Resolve Container after getting input option. |
||
| 178 | * |
||
| 179 | * @param string $option |
||
| 180 | * |
||
| 181 | * @return array |
||
| 182 | */ |
||
| 183 | protected function resolveByOption($option) |
||
| 184 | { |
||
| 185 | // |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Parse slug name of the module. |
||
| 190 | * |
||
| 191 | * @param string $slug |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | protected function parseSlug($slug) |
||
| 196 | { |
||
| 197 | return str_slug($slug); |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Parse class name of the module. |
||
| 202 | * |
||
| 203 | * @param string $slug |
||
|
0 ignored issues
–
show
There is no parameter named
$slug. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 204 | * |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | protected function parseName($name) |
||
| 208 | { |
||
| 209 | if (str_contains($name, '\\')) { |
||
| 210 | $name = str_replace('\\', '/', $name); |
||
| 211 | } |
||
| 212 | |||
| 213 | if (str_contains($name, '/')) { |
||
| 214 | $formats = collect(explode('/', $name))->map(function ($name) { |
||
| 215 | return studly_case($name); |
||
| 216 | }); |
||
| 217 | |||
| 218 | $name = $formats->implode('/'); |
||
| 219 | } else { |
||
| 220 | $name = studly_case($name); |
||
| 221 | } |
||
| 222 | |||
| 223 | return $name; |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Make FilePath. |
||
| 228 | * |
||
| 229 | * @param string $folder |
||
| 230 | * @param string $name |
||
| 231 | * |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | protected function makeFilePath($folder, $name) |
||
| 235 | { |
||
| 236 | $folder = ltrim($folder, '\/'); |
||
| 237 | $folder = rtrim($folder, '\/'); |
||
| 238 | |||
| 239 | $name = ltrim($name, '\/'); |
||
| 240 | $name = rtrim($name, '\/'); |
||
| 241 | |||
| 242 | return |
||
| 243 | $this->modulePath.DIRECTORY_SEPARATOR. |
||
| 244 | $this->moduleInfo->get('namespace').DIRECTORY_SEPARATOR. |
||
| 245 | $folder.DIRECTORY_SEPARATOR.$name; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Make FileName. |
||
| 250 | * |
||
| 251 | * @param string $filePath |
||
| 252 | * |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | protected function makeFileName($filePath) |
||
| 256 | { |
||
| 257 | return basename($filePath); |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Build the directory for the class if necessary. |
||
| 262 | * |
||
| 263 | * @param string $path |
||
| 264 | * |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | protected function makeDirectory($path) |
||
| 268 | { |
||
| 269 | if (!$this->files->isDirectory(dirname($path))) { |
||
| 270 | $this->files->makeDirectory(dirname($path), 0777, true, true); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Get Namespace of the current file. |
||
| 276 | * |
||
| 277 | * @param string $file |
||
| 278 | * |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | protected function getNamespace($file) |
||
| 282 | { |
||
| 283 | $namespace = str_replace($this->modulePath, '', $file); |
||
| 284 | $find = basename($namespace); |
||
| 285 | $namespace = strrev(preg_replace(strrev("/$find/"), '', strrev($namespace), 1)); |
||
| 286 | $namespace = ltrim($namespace, '\/'); |
||
| 287 | $namespace = rtrim($namespace, '\/'); |
||
| 288 | |||
| 289 | return str_replace('/', '\\', $namespace); |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get the configured module base namespace. |
||
| 294 | * |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | protected function getBaseNamespace() |
||
| 298 | { |
||
| 299 | return $this->module->getNamespace(); |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Get stub content by key. |
||
| 304 | * |
||
| 305 | * @param int $key |
||
|
0 ignored issues
–
show
There is no parameter named
$key. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 306 | * |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | protected function getStubContent($stubName) |
||
| 310 | { |
||
| 311 | if(!empty(config('modules.custom_stubs'))){ |
||
| 312 | $stubPath = config('modules.custom_stubs'); |
||
| 313 | }else{ |
||
| 314 | $stubPath = __DIR__.'/../../../resources/stubs/'; |
||
| 315 | } |
||
| 316 | return $this->formatContent($this->files->get($stubPath.$stubName)); |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Replace placeholder text with correct values. |
||
| 321 | * |
||
| 322 | * @return string |
||
| 323 | */ |
||
| 324 | protected function formatContent($content) |
||
| 325 | { |
||
| 326 | // |
||
| 327 | } |
||
| 328 | } |
||
| 329 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.