Conditions | 1 |
Paths | 1 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
17 | { |
||
18 | /* @var $options Options\ModuleOptions */ |
||
19 | $options = $serviceLocator->get('zfcuser_module_options'); |
||
20 | |||
21 | /* @var $dbAdapter Db\Adapter\Adapter */ |
||
22 | $dbAdapter = $serviceLocator->get('zfcuser_zend_db_adapter'); |
||
23 | |||
24 | $mapper = new Mapper\User(); |
||
25 | $mapper->setDbAdapter($dbAdapter); |
||
26 | |||
27 | $entityClass = $options->getUserEntityClass(); |
||
28 | |||
29 | /* @var $hydrator Hydrator\HydratorInterface */ |
||
30 | $hydrator = $serviceLocator->get('zfcuser_user_hydrator'); |
||
31 | |||
32 | $mapper |
||
|
|||
33 | ->setEntityPrototype(new $entityClass) |
||
34 | ->setHydrator($hydrator) |
||
35 | ->setTableName($options->getTableName()) |
||
36 | ; |
||
37 | |||
38 | return $mapper; |
||
39 | } |
||
40 | } |
||
41 |
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: