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 Ngtfkx\Laradeck\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Support\Str; |
||
7 | |||
8 | class MakeViewCommand extends Command |
||
9 | { |
||
10 | protected $signature = 'laradeck:view |
||
11 | {name : View name with dot syntax} |
||
12 | {--F|force : Rewrite exists view} |
||
13 | {--extends= : Extends directive} |
||
14 | {--section=* : Section directive} |
||
15 | {--stack=* : Push directive} |
||
16 | {--component=* : Component directive} |
||
17 | '; |
||
18 | |||
19 | protected $description = 'Create a new view'; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $view; |
||
25 | |||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $force; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $extends; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $sections; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $stacks; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $components; |
||
50 | |||
51 | public function __construct() |
||
52 | { |
||
53 | parent::__construct(); |
||
54 | } |
||
55 | |||
56 | public function handle() |
||
57 | { |
||
58 | $this->view = $this->argument('name'); |
||
59 | |||
60 | $this->force = $this->option('force'); |
||
0 ignored issues
–
show
|
|||
61 | |||
62 | $this->extends = $this->option('extends'); |
||
63 | |||
64 | $this->sections = $this->parse($this->option('section')); |
||
65 | |||
66 | $this->stacks = $this->parse($this->option('stack')); |
||
67 | |||
68 | $this->components = $this->parse($this->option('component')); |
||
69 | |||
70 | $path = $this->path(); |
||
71 | |||
72 | $content = $this->content(); |
||
73 | |||
74 | $this->create($path, $content); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get path of view file and create directories for it |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | protected function path(): string |
||
83 | { |
||
84 | $path = resource_path('views' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $this->view) . '.blade.php'); |
||
85 | |||
86 | $directory = dirname($path); |
||
87 | |||
88 | if (!is_dir($directory)) { |
||
89 | \File::makeDirectory($directory, 0755, true); |
||
90 | } |
||
91 | |||
92 | return $path; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Generate content of a view |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function content(): string |
||
101 | { |
||
102 | $content = ''; |
||
103 | |||
104 | if ($this->extends) { |
||
105 | $content .= "@extends('" . $this->extends . "')"; |
||
106 | } |
||
107 | |||
108 | $types = [ |
||
109 | 'section' => $this->sections, |
||
110 | 'component' => $this->components, |
||
111 | 'push' => $this->stacks, |
||
112 | ]; |
||
113 | |||
114 | foreach ($types as $key => $values) { |
||
115 | $content .= $this->blocks($key, $values); |
||
116 | } |
||
117 | |||
118 | return $content; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Write content to a view |
||
123 | * |
||
124 | * @param string $path |
||
125 | * @param string $content |
||
126 | */ |
||
127 | protected function create(string $path, string $content) |
||
128 | { |
||
129 | if ($this->force || !file_exists($path)) { |
||
130 | \File::put($path, $content); |
||
131 | $this->info('View created successfully.'); |
||
132 | } else { |
||
133 | $this->error('View already exists!'); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param $value |
||
139 | * @return array |
||
140 | */ |
||
141 | protected function parse($value): array |
||
142 | { |
||
143 | $values = []; |
||
144 | |||
145 | foreach ($value as $item) { |
||
146 | if (Str::contains($item, ',')) { |
||
147 | $values = array_merge($values, explode(',', $item)); |
||
148 | } else { |
||
149 | $values[] = $item; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | return $values; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param $name |
||
158 | * @param $type |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function block($name, $type): string |
||
162 | { |
||
163 | $content = PHP_EOL . PHP_EOL . "@" . $type . "('" . $name . "')" . PHP_EOL; |
||
164 | $content .= "@end" . $type; |
||
165 | |||
166 | return $content; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @param string $key |
||
171 | * @param array $values |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function blocks(string $key, array $values): string |
||
175 | { |
||
176 | $content = ''; |
||
177 | |||
178 | foreach ($values as $item) { |
||
179 | $content .= $this->block($item, $key); |
||
180 | } |
||
181 | |||
182 | return $content; |
||
183 | } |
||
184 | } |
||
185 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..