Conditions | 5 |
Paths | 12 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
31 | protected function execute(InputInterface $input, OutputInterface $output) |
||
32 | { |
||
33 | /** @var DocumentManager $dm */ |
||
34 | $dm = $this->getHelper('documentManager')->getDocumentManager(); |
||
|
|||
35 | $metadataFactory = $dm->getMetadataFactory(); |
||
36 | $metadataFactory->setCacheDriver(new VoidCache()); |
||
37 | |||
38 | $errors = 0; |
||
39 | foreach ($metadataFactory->getAllMetadata() as $meta) { |
||
40 | if ($meta != unserialize(serialize($meta))) { |
||
41 | ++$errors; |
||
42 | $output->writeln(sprintf("%s has mapping issues.", $meta->name)); |
||
43 | } |
||
44 | } |
||
45 | if ($errors) { |
||
46 | $output->writeln(sprintf('<error>%d document(s) have mapping issues.</error>')); |
||
47 | } else { |
||
48 | $output->writeln('All documents are OK!'); |
||
49 | } |
||
50 | |||
51 | return $errors ? 255 : 0; |
||
52 | } |
||
53 | } |
||
54 |
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: