| 1 | <?php |
||
| 13 | class PagesImporterCli { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var InputInterface |
||
| 17 | */ |
||
| 18 | private $input; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var OutputInterface |
||
| 22 | */ |
||
| 23 | private $output; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var ServiceFactory |
||
| 27 | */ |
||
| 28 | private $factory = null; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var callable|null |
||
| 32 | */ |
||
| 33 | private $onAborted; |
||
| 34 | |||
| 35 | public function __construct( InputInterface $input, OutputInterface $output, |
||
| 43 | |||
| 44 | public function runImport( \Iterator $entityPageIterator ) { |
||
| 56 | |||
| 57 | private function newReporter() { |
||
| 62 | |||
| 63 | |||
| 64 | } |
||
| 65 |
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: