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 Jumilla\Addomnipot\Laravel\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Filesystem\Filesystem; |
||
7 | use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment; |
||
8 | use Jumilla\Addomnipot\Laravel\Generator as AddonGenerator; |
||
9 | use UnexpectedValueException; |
||
10 | use Exception; |
||
11 | |||
12 | /** |
||
13 | * Modules console commands. |
||
14 | * |
||
15 | * @author Fumio Furukawa <[email protected]> |
||
16 | */ |
||
17 | class AddonMakeCommand extends Command |
||
18 | { |
||
19 | use Functions; |
||
20 | use MakeCommandTrait; |
||
21 | |||
22 | /** |
||
23 | * The console command signature. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $signature = 'make:addon |
||
28 | {name : The name of the addon.} |
||
29 | {skeleton? : Skeleton of addon.} |
||
30 | {--space= : Addons space.} |
||
31 | {--namespace= : PHP namespace of addon. Slash OK.} |
||
32 | {--no-namespace : No PHP namespace.} |
||
33 | {--language= : Languages, comma separated.} |
||
34 | {--yes : No confirm.} |
||
35 | '; |
||
36 | |||
37 | /** |
||
38 | * The console command description. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $description = 'Create a new addon directory'; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $skeletons = [ |
||
48 | 1 => 'minimum', |
||
49 | 2 => 'simple', |
||
50 | 3 => 'asset', |
||
51 | 4 => 'library', |
||
52 | 5 => 'api', |
||
53 | 6 => 'ui', |
||
54 | 11 => 'ui-sample', |
||
55 | 12 => 'debug', |
||
56 | 13 => 'generator', |
||
57 | 14 => 'laravel5', |
||
58 | 15 => 'laravel5-auth', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $default_skeleton = 'ui-sample'; |
||
65 | |||
66 | /** |
||
67 | * Execute the console command. |
||
68 | * |
||
69 | * @param \Jumilla\Addomnipot\Laravel\Addons\AddonGenerator $generator |
||
70 | * |
||
71 | * @return mixed |
||
72 | */ |
||
73 | public function handle(Filesystem $filesystem, AddonEnvironment $env, AddonGenerator $generator) |
||
74 | { |
||
75 | $addon_name = preg_replace('#(/+)#', '-', $this->argument('name')); |
||
76 | |||
77 | // Check addon-directory |
||
78 | if ($env->exists($addon_name)) { |
||
0 ignored issues
–
show
|
|||
79 | throw new UnexpectedValueException("addon directory '{$addon_name}' is already exists."); |
||
80 | } |
||
81 | |||
82 | $output_path = $env->spacePath($this->option('space'), $addon_name); |
||
0 ignored issues
–
show
It seems like
$this->option('space') targeting Illuminate\Console\Command::option() can also be of type array ; however, Jumilla\Addomnipot\Larav...nvironment::spacePath() does only seem to accept string , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() It seems like
$addon_name defined by preg_replace('#(/+)#', '...this->argument('name')) on line 75 can also be of type array<integer,string> ; however, Jumilla\Addomnipot\Larav...nvironment::spacePath() does only seem to accept string|null , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
83 | |||
84 | // Adjust addon_name |
||
85 | $addon_name = preg_replace('/[^\w_\-]/', '', $addon_name); |
||
86 | |||
87 | $addon_class = preg_replace( |
||
88 | ['/[^\w_]/', '/^(\d)/'], |
||
89 | ['', '_$1'], |
||
90 | studly_case($addon_name) |
||
0 ignored issues
–
show
It seems like
$addon_name defined by preg_replace('/[^\\w_\\-]/', '', $addon_name) on line 85 can also be of type array<integer,string> ; however, studly_case() does only seem to accept string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
91 | ); |
||
92 | |||
93 | // namespace |
||
94 | if ($this->option('no-namespace')) { |
||
95 | $namespace = ''; |
||
96 | } else { |
||
97 | if ($this->option('namespace')) { |
||
98 | $namespace = str_replace('/', '\\', $this->option('namespace')); |
||
99 | } else { |
||
100 | $namespace = 'App\\'.$addon_class; |
||
101 | } |
||
102 | |||
103 | if (! $this->validPhpNamespace($namespace)) { |
||
104 | throw new UnexpectedValueException("PHP namespace '{$namespace}' is invalid."); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | // languages |
||
109 | $languages = $this->option('language') ? explode($this->option('language')) : []; |
||
110 | |||
111 | // Show select prompt if not specified |
||
112 | $skeleton = $this->chooseSkeleton($this->argument('skeleton')); |
||
0 ignored issues
–
show
It seems like
$this->argument('skeleton') targeting Illuminate\Console\Command::argument() can also be of type array ; however, Jumilla\Addomnipot\Larav...Trait::chooseSkeleton() does only seem to accept string , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
113 | |||
114 | $properties = [ |
||
115 | 'addon_name' => $addon_name, |
||
116 | 'addon_class' => $addon_class, |
||
117 | 'namespace' => $namespace, |
||
118 | 'languages' => array_unique(array_merge(['en', $this->laravel['config']->get('app.locale')], $languages)), |
||
119 | 'test_namespace' => 'Tests\\'.studly_case($addon_name), |
||
0 ignored issues
–
show
It seems like
$addon_name defined by preg_replace('/[^\\w_\\-]/', '', $addon_name) on line 85 can also be of type array<integer,string> ; however, studly_case() does only seem to accept string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
120 | ]; |
||
121 | |||
122 | // confirm |
||
123 | $this->line('Addon name: '.$properties['addon_name']); |
||
124 | $this->line('PHP namespace: '.$properties['namespace']); |
||
125 | $this->line('Skeleton: '.$skeleton); |
||
126 | $this->line('Languages: '.implode(', ', $properties['languages'])); |
||
127 | |||
128 | View Code Duplication | if (!$this->option('yes') && !$this->confirm('generate ready? [Y/n]', true)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
129 | $this->comment('canceled'); |
||
130 | return; |
||
131 | } |
||
132 | |||
133 | try { |
||
134 | $generator->generateAddon($output_path, str_replace(':', '-', $skeleton), $properties); |
||
135 | $this->info('Addon Generated.'); |
||
136 | } catch (Exception $ex) { |
||
137 | $filesystem->deleteDirectory($output_path); |
||
138 | |||
139 | throw $ex; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.