| Conditions | 1 |
| Paths | 1 |
| Total Lines | 18 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | public function __construct( |
||
| 29 | string $thing, |
||
| 30 | string $className, |
||
| 31 | string $property, |
||
| 32 | int $code = 0, |
||
| 33 | Throwable $previous = null |
||
| 34 | ) { |
||
| 35 | parent::__construct( |
||
|
|
|||
| 36 | sprintf( |
||
| 37 | 'Property not %s: %s::$%s', |
||
| 38 | $thing, |
||
| 39 | $className, |
||
| 40 | $property |
||
| 41 | ), |
||
| 42 | $code, |
||
| 43 | $previous |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |
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: