1 | <?php |
||
16 | class DoctrineReader implements CountableReader |
||
17 | { |
||
18 | /** |
||
19 | * @var ObjectManager |
||
20 | */ |
||
21 | protected $objectManager; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $objectName; |
||
27 | |||
28 | /** |
||
29 | * @var IterableResult |
||
30 | */ |
||
31 | protected $iterableResult; |
||
32 | |||
33 | /** @var QueryBuilder */ |
||
34 | protected $queryBuilder; |
||
35 | |||
36 | 3 | /** |
|
37 | * @param ObjectManager $objectManager |
||
38 | 3 | * @param string $objectName e.g. YourBundle:YourEntity |
|
39 | 3 | */ |
|
40 | 3 | public function __construct(ObjectManager $objectManager, $objectName) |
|
45 | 1 | ||
46 | public function setQueryBuilder(QueryBuilder $queryBuilder) |
||
52 | |||
53 | protected function getQueryBuilder() |
||
62 | 1 | ||
63 | /** |
||
64 | 1 | * {@inheritdoc} |
|
65 | 1 | */ |
|
66 | public function getFields() |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function current() |
||
79 | |||
80 | 1 | /** |
|
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function next() |
||
87 | |||
88 | 1 | /** |
|
89 | * {@inheritdoc} |
||
90 | 1 | */ |
|
91 | 1 | public function key() |
|
95 | 1 | ||
96 | 1 | /** |
|
97 | * {@inheritdoc} |
||
98 | 1 | */ |
|
99 | 1 | public function valid() |
|
103 | |||
104 | 1 | /** |
|
105 | * {@inheritdoc} |
||
106 | 1 | */ |
|
107 | 1 | public function rewind() |
|
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function count() |
||
127 | } |
||
128 |
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: