| Conditions | 3 |
| Paths | 2 |
| Total Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 95 | public function __construct (Election $mother) |
|
| 27 | { |
||
| 28 | 95 | $this->_selfElection = $mother; |
|
| 29 | |||
| 30 | 95 | if (!is_null(static::$MaxCandidates) && $this->_selfElection->countCandidates() > static::$MaxCandidates) : |
|
| 31 | 2 | throw new CondorcetException(101, static::METHOD_NAME[0].' is configured to accept only '.static::$MaxCandidates.' candidates'); |
|
| 32 | endif; |
||
| 33 | 93 | } |
|
| 34 | |||
| 60 |
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: