| Conditions | 3 |
| Paths | 3 |
| Total Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | 9 | private function parseMemberDocblock(&$member, Doc $doc = null) { |
|
| 17 | 9 | if ($doc !== null) { |
|
| 18 | 3 | $member->setDocblock($doc->getReformattedText()); |
|
| 19 | 3 | $docblock = $member->getDocblock(); |
|
| 20 | 3 | $member->setDescription($docblock->getShortDescription()); |
|
| 21 | 3 | $member->setLongDescription($docblock->getLongDescription()); |
|
| 22 | |||
| 23 | 3 | $vars = $docblock->getTags('var'); |
|
| 24 | 3 | if ($vars->size() > 0) { |
|
| 25 | 2 | $var = $vars->get(0); |
|
| 26 | 2 | $member->setType($var->getType(), $var->getDescription()); |
|
| 27 | } |
||
| 28 | } |
||
| 29 | 9 | } |
|
| 30 | |||
| 49 |
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 implementation 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 interface: