1 | <?php |
||
17 | class TransformedFinder implements PaginatedFinderInterface |
||
18 | { |
||
19 | protected $searchable; |
||
20 | protected $transformer; |
||
21 | |||
22 | /** |
||
23 | * @param SearchableInterface $searchable |
||
24 | * @param ElasticaToModelTransformerInterface $transformer |
||
25 | */ |
||
26 | 7 | public function __construct(SearchableInterface $searchable, ElasticaToModelTransformerInterface $transformer) |
|
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 1 | public function find($query, $limit = null, $options = array()) |
|
41 | |||
42 | 1 | public function findHybrid($query, $limit = null, $options = array()) |
|
48 | |||
49 | /** |
||
50 | * Find documents similar to one with passed id. |
||
51 | * |
||
52 | * @param integer $id |
||
53 | * @param array $params |
||
54 | * @param array $query |
||
55 | * |
||
56 | * @return array of model objects |
||
57 | **/ |
||
58 | 1 | public function moreLikeThis($id, $params = array(), $query = array()) |
|
65 | |||
66 | /** |
||
67 | * @param $query |
||
68 | * @param null|int $limit |
||
69 | * @param array $options |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | 1 | protected function search($query, $limit = null, $options = array()) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 1 | public function findPaginated($query, $options = array()) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 2 | public function createPaginatorAdapter($query, $options = array()) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 1 | public function createHybridPaginatorAdapter($query) |
|
114 | } |
||
115 |
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: