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(); |
||
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) { |
||
0 ignored issues
–
show
|
|||
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 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.