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 Encore\Admin\Form\Field; |
||
4 | |||
5 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||
6 | |||
7 | class MultipleImage extends MultipleFile |
||
8 | { |
||
9 | use ImageField; |
||
10 | |||
11 | /** |
||
12 | * {@inheritdoc} |
||
13 | */ |
||
14 | protected $view = 'admin::form.multiplefile'; |
||
15 | |||
16 | /** |
||
17 | * Validation rules. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $rules = 'image'; |
||
22 | |||
23 | /** |
||
24 | * Prepare for each file. |
||
25 | * |
||
26 | * @param UploadedFile $image |
||
27 | * |
||
28 | * @return mixed|string |
||
29 | */ |
||
30 | View Code Duplication | protected function prepareForeach(UploadedFile $image = null) |
|
0 ignored issues
–
show
|
|||
31 | { |
||
32 | $this->name = $this->getStoreName($image); |
||
33 | |||
34 | $this->callInterventionMethods($image->getRealPath()); |
||
35 | |||
36 | return tap($this->upload($image), function () { |
||
0 ignored issues
–
show
It seems like
$image defined by parameter $image on line 30 can be null ; however, Encore\Admin\Form\Field\UploadField::upload() does not accept null , maybe add an additional type check?
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null. We recommend to add an additional type check (or disallow null for the parameter): function notNullable(stdClass $x) { }
// Unsafe
function withoutCheck(stdClass $x = null) {
notNullable($x);
}
// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
if ($x instanceof stdClass) {
notNullable($x);
}
}
// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
notNullable($x);
}
Loading history...
|
|||
37 | $this->name = null; |
||
38 | }); |
||
39 | } |
||
40 | } |
||
41 |
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.