Conditions | 1 |
Paths | 1 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
36 | protected function template($namespace, $name, $topNSPart = "Models") |
||
37 | { |
||
38 | $className = str_plural($name); |
||
39 | $namespace = "{$namespace}\\{$topNSPart}"; |
||
40 | |||
41 | return <<< EOT |
||
42 | <?php |
||
43 | namespace $namespace; |
||
44 | |||
45 | use Atog\Api\Model; |
||
46 | |||
47 | /** |
||
48 | * Class $className |
||
49 | * @package $namespace |
||
50 | */ |
||
51 | class $className extends Model |
||
52 | { |
||
53 | } |
||
54 | |||
55 | EOT; |
||
56 | } |
||
57 | } |
||
58 |
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: