These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace gossi\swagger; |
||
3 | |||
4 | abstract class AbstractModel { |
||
5 | |||
6 | 6 | protected function export() { |
|
7 | 6 | $cols = func_get_args(); |
|
8 | |||
9 | // add cols |
||
10 | 6 | if (method_exists($this, 'hasRef') && $this->hasRef()) { |
|
0 ignored issues
–
show
|
|||
11 | 5 | $cols = array_merge(['$ref'], $cols); |
|
12 | 5 | } |
|
13 | |||
14 | // flatten array |
||
15 | 6 | $fields = []; |
|
16 | array_walk_recursive($cols, function($a) use (&$fields) { $fields[] = $a; }); |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | 6 | $out = []; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
19 | 6 | $refl = new \ReflectionClass(get_class($this)); |
|
20 | |||
21 | 6 | foreach ($fields as $field) { |
|
22 | 6 | if ($field == 'tags') { |
|
23 | 6 | $val = $this->exportTags(); |
|
0 ignored issues
–
show
The method
exportTags() does not exist on gossi\swagger\AbstractModel . Did you maybe mean export() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise.
Loading history...
|
|||
24 | 6 | } else { |
|
25 | 6 | $prop = $refl->getProperty($field == '$ref' ? 'ref' : $field); |
|
26 | 6 | $prop->setAccessible(true); |
|
27 | 6 | $val = $prop->getValue($this); |
|
28 | |||
29 | 6 | if (method_exists($val, 'toArray')) { |
|
30 | 6 | $val = $val->toArray(); |
|
31 | 6 | } |
|
32 | } |
||
33 | |||
34 | 6 | if ($field == 'required' && is_bool($val) || !empty($val)) { |
|
35 | 6 | $out[$field] = $val; |
|
36 | 6 | } |
|
37 | 6 | } |
|
38 | |||
39 | 6 | if (method_exists($this, 'getExtensions')) { |
|
40 | 6 | $out = array_merge($out, $this->getExtensions()->toArray()); |
|
41 | 6 | } |
|
42 | |||
43 | 6 | return $out; |
|
44 | } |
||
45 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: