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