1 | <?php |
||
13 | class Repository implements RepositoryInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var \eZ\Publish\API\Repository\Repository |
||
17 | */ |
||
18 | protected $innerRepository; |
||
19 | |||
20 | /** |
||
21 | * @param \eZ\Publish\API\Repository\Repository $innerRepository |
||
22 | */ |
||
23 | public function __construct(RepositoryInterface $innerRepository) |
||
27 | |||
28 | public function getCurrentUser() |
||
32 | |||
33 | public function getCurrentUserReference() |
||
37 | |||
38 | public function setCurrentUser(UserReference $user) |
||
42 | |||
43 | public function sudo(\Closure $callback) |
||
47 | |||
48 | public function hasAccess($module, $function, UserReference $user = null) |
||
52 | |||
53 | public function canUser($module, $function, ValueObject $object, $targets = null) |
||
57 | |||
58 | public function getContentService() |
||
62 | |||
63 | public function getContentLanguageService() |
||
67 | |||
68 | public function getContentTypeService() |
||
72 | |||
73 | public function getLocationService() |
||
77 | |||
78 | public function getTrashService() |
||
82 | |||
83 | public function getSectionService() |
||
87 | |||
88 | public function getUserService() |
||
92 | |||
93 | public function getURLAliasService() |
||
97 | |||
98 | public function getURLWildcardService() |
||
102 | |||
103 | public function getObjectStateService() |
||
107 | |||
108 | public function getRoleService() |
||
112 | |||
113 | public function getSearchService() |
||
117 | |||
118 | public function getFieldTypeService() |
||
122 | |||
123 | public function beginTransaction() |
||
127 | |||
128 | public function commit() |
||
132 | |||
133 | public function rollback() |
||
137 | |||
138 | public function commitEvent($event) |
||
142 | |||
143 | public function createDateTime($timestamp = null) |
||
147 | } |
||
148 |
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: