1 | <?php |
||
20 | class DoctrinePaginatorAdapter implements PaginatorInterface |
||
21 | { |
||
22 | /** |
||
23 | * The paginator instance. |
||
24 | * @var Paginator |
||
25 | */ |
||
26 | private $paginator; |
||
27 | |||
28 | /** |
||
29 | * The route generator. |
||
30 | * |
||
31 | * @var callable |
||
32 | */ |
||
33 | private $routeGenerator; |
||
34 | |||
35 | /** |
||
36 | * Create a new DoctrinePaginatorAdapter. |
||
37 | * @param Paginator $paginator |
||
38 | * @param callable $routeGenerator |
||
39 | * |
||
40 | */ |
||
41 | 1 | public function __construct(Paginator $paginator, callable $routeGenerator) |
|
46 | |||
47 | /** |
||
48 | * Get the current page. |
||
49 | * |
||
50 | * @return int |
||
51 | */ |
||
52 | 1 | public function getCurrentPage() |
|
56 | |||
57 | /** |
||
58 | * Get the last page. |
||
59 | * |
||
60 | * @return int |
||
61 | */ |
||
62 | 1 | public function getLastPage() |
|
66 | |||
67 | /** |
||
68 | * Get the total. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | 1 | public function getTotal() |
|
76 | |||
77 | /** |
||
78 | * Get the count. |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | 1 | public function getCount() |
|
86 | |||
87 | /** |
||
88 | * Get the number per page. |
||
89 | * |
||
90 | * @return int |
||
91 | */ |
||
92 | 1 | public function getPerPage() |
|
96 | |||
97 | /** |
||
98 | * Get the url for the given page. |
||
99 | * |
||
100 | * @param int $page |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 1 | public function getUrl($page) |
|
108 | |||
109 | /** |
||
110 | * Get the the route generator. |
||
111 | * |
||
112 | * @return callable |
||
113 | */ |
||
114 | 1 | private function getRouteGenerator() |
|
118 | } |
||
119 |
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: