1 | <?php |
||
28 | class RevisionManager implements RevisionManagerInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var FactoryInterface |
||
32 | */ |
||
33 | protected $revisionFactory; |
||
34 | |||
35 | /** |
||
36 | * @var RevisionContextInterface |
||
37 | */ |
||
38 | protected $revisionContext; |
||
39 | |||
40 | /** |
||
41 | * @var EntityManagerInterface |
||
42 | */ |
||
43 | protected $objectManager; |
||
44 | |||
45 | /** |
||
46 | * @var EventDispatcherInterface |
||
47 | */ |
||
48 | protected $eventDispatcher; |
||
49 | |||
50 | /** |
||
51 | * RevisionManager constructor. |
||
52 | * |
||
53 | * @param FactoryInterface $revisionFactory |
||
54 | * @param RevisionContextInterface $revisionContext |
||
55 | * @param EventDispatcherInterface $eventDispatcher |
||
56 | * @param EntityManagerInterface $objectManager |
||
57 | */ |
||
58 | public function __construct( |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function publish(RevisionInterface $revision, RevisionInterface $workingRevision = null): RevisionInterface |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function rollback(RevisionInterface $revision): RevisionInterface |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function create(RevisionInterface $previous = null): RevisionInterface |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function getRevisionContext(): RevisionContextInterface |
||
133 | } |
||
134 |
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: