1 | <?php |
||
17 | abstract class AbstractCommand extends Command |
||
18 | { |
||
19 | public function __construct($name) |
||
23 | |||
24 | /** |
||
25 | * {@inheritDoc} |
||
26 | */ |
||
27 | public function configure() |
||
31 | |||
32 | /** |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | public function execute(InputInterface $input, OutputInterface $output) |
||
51 | |||
52 | /** |
||
53 | * @return \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer |
||
54 | */ |
||
55 | protected function getSynchronizer(Connection $connection) |
||
59 | |||
60 | /** |
||
61 | * @param \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer $sync |
||
62 | * @param \Doctrine\DBAL\Schema\Schema $schema |
||
63 | * @return array |
||
64 | */ |
||
65 | abstract protected function getSql(Synchronizer $sync, Schema $schema); |
||
66 | |||
67 | /** |
||
68 | * @param \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer $sync |
||
69 | * @param \Doctrine\DBAL\Schema\Schema $schema |
||
70 | */ |
||
71 | abstract protected function applySql(Synchronizer $sync, Schema $schema); |
||
72 | } |
||
73 |
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: