These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache; |
||
6 | |||
7 | use Doctrine\Common\Cache\ApcCache; |
||
8 | use Symfony\Component\Console\Command\Command; |
||
9 | use Symfony\Component\Console\Input\InputInterface; |
||
10 | use Symfony\Component\Console\Output\OutputInterface; |
||
11 | use const PHP_EOL; |
||
12 | |||
13 | /** |
||
14 | * Command to clear the metadata cache of the various cache drivers. |
||
15 | * |
||
16 | */ |
||
17 | class MetadataCommand extends Command |
||
18 | { |
||
19 | /** |
||
20 | * @see \Symfony\Component\Console\Command\Command |
||
21 | */ |
||
22 | protected function configure() |
||
23 | { |
||
24 | $this |
||
25 | ->setName('odm:clear-cache:metadata') |
||
26 | ->setDescription('Clear all metadata cache of the various cache drivers.') |
||
27 | ->setDefinition([]) |
||
28 | ->setHelp(<<<EOT |
||
29 | Clear all metadata cache of the various cache drivers. |
||
30 | EOT |
||
31 | ); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @see \Symfony\Component\Console\Command\Command |
||
36 | */ |
||
37 | protected function execute(InputInterface $input, OutputInterface $output) |
||
38 | { |
||
39 | $dm = $this->getHelper('documentManager')->getDocumentManager(); |
||
0 ignored issues
–
show
|
|||
40 | $cacheDriver = $dm->getConfiguration()->getMetadataCacheImpl(); |
||
41 | |||
42 | if (! $cacheDriver) { |
||
43 | throw new \InvalidArgumentException('No Metadata cache driver is configured on given DocumentManager.'); |
||
44 | } |
||
45 | |||
46 | if ($cacheDriver instanceof ApcCache) { |
||
47 | throw new \LogicException('Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.'); |
||
48 | } |
||
49 | |||
50 | $output->write('Clearing ALL Metadata cache entries' . PHP_EOL); |
||
51 | |||
52 | $success = $cacheDriver->deleteAll(); |
||
53 | |||
54 | if ($success) { |
||
55 | $output->write('The cache entries were successfully deleted.' . PHP_EOL); |
||
56 | } else { |
||
57 | $output->write('No entries to be deleted.' . PHP_EOL); |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 |
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: