1 | <?php |
||
19 | class JobBoardPaginationQuery extends AbstractPaginationQuery |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $sortPropertiesMap = [ |
||
25 | 'company' => 'companyName', |
||
26 | 'date' => 'dateCreated', |
||
27 | ]; |
||
28 | |||
29 | protected $propertiesMap = [ |
||
30 | 'organizationName' => 'convertOrganizationName', |
||
31 | 'companyLogo' => 'convertCompanyLogo', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | public function createQuery(array $params, $query) |
||
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | public function getEntityClass() |
||
79 | |||
80 | /** |
||
81 | * Convert organizationName result |
||
82 | * @param Job $ob |
||
83 | * @param string $value |
||
84 | */ |
||
85 | public function convertOrganizationName($ob,$value) |
||
93 | |||
94 | /** |
||
95 | * Convert companyLogo result |
||
96 | * @param Job $ob |
||
97 | * @param mixed $value |
||
98 | */ |
||
99 | public function convertCompanyLogo($ob,$value) |
||
112 | } |
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: