| Conditions | 1 |
| Paths | 1 |
| Total Lines | 7 |
| Code Lines | 5 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 4 | public function visitConstant(Const_ $node, Doc $doc = null) { |
|
| 24 | 4 | $const = new PhpConstant($node->name); |
|
| 25 | 4 | $this->parseValue($const, $node); |
|
| 26 | 4 | $this->parseMemberDocblock($const, $doc); |
|
| 27 | |||
| 28 | 4 | $this->struct->setConstant($const); |
|
|
1 ignored issue
–
show
|
|||
| 29 | } |
||
| 30 | } |
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: