| 1 | <?php |
||
| 15 | abstract class DBALObjectRepository implements Repository |
||
| 16 | { |
||
| 17 | public function getIterator(): Result |
||
| 21 | |||
| 22 | public function count(): int |
||
| 26 | |||
| 27 | abstract protected static function createObject(array $data): object; |
||
| 28 | |||
| 29 | abstract protected static function tableName(): string; |
||
| 30 | |||
| 31 | abstract protected function getConnection(): Connection; |
||
| 32 | |||
| 33 | final protected static function createResult(QueryBuilder $qb): Result |
||
| 42 | |||
| 43 | protected static function createDBALQueryBuilderResult(QueryBuilder $qb): DBALQueryBuilderResult |
||
| 47 | |||
| 48 | protected function qb(): QueryBuilder |
||
| 52 | } |
||
| 53 |
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: