These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Moka\Generator\Template; |
||
5 | |||
6 | /** |
||
7 | * Class PropertyInitializationTemplate |
||
8 | * @package Moka\Generator\Template |
||
9 | */ |
||
10 | class PropertyInitializationTemplate implements TemplateInterface |
||
11 | { |
||
12 | const TEMPLATE = ' |
||
13 | %s%s = function () { |
||
14 | return $this->doGet("%s"); |
||
15 | }; |
||
16 | '; |
||
17 | |||
18 | /** |
||
19 | * @param \ReflectionProperty $property |
||
20 | * @return string |
||
21 | */ |
||
22 | 4 | public static function generate(\Reflector $property): string |
|
23 | { |
||
24 | 4 | return self::doGenerate($property); |
|
1 ignored issue
–
show
|
|||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param \ReflectionProperty $property |
||
29 | * @return string |
||
30 | */ |
||
31 | 4 | protected static function doGenerate(\ReflectionProperty $property): string |
|
32 | { |
||
33 | 4 | $scope = $property->isStatic() ? 'self::$' : '$this->'; |
|
34 | |||
35 | 4 | $name = $property->name; |
|
36 | |||
37 | 4 | return sprintf( |
|
38 | 4 | self::TEMPLATE, |
|
39 | 4 | $scope, |
|
40 | 4 | $name, |
|
41 | 4 | $name |
|
42 | ); |
||
43 | } |
||
44 | } |
||
45 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.