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