Skip to content

Commit

Permalink
[doctrineGH-8327] Bugfix: phpstan detected stricter type checks needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Apr 18, 2021
1 parent 3f7452d commit cdc1eca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ClearableCache;
use Doctrine\Common\Cache\FlushableCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
Expand Down Expand Up @@ -88,12 +90,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new LogicException('Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.');
}

if (!($cacheDriver instanceof ClearableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when ClearableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$ui->comment('Clearing <info>all</info> Metadata cache entries');

$result = $cacheDriver->deleteAll();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';

if ($input->getOption('flush') === true) {
if (!($cacheDriver instanceof FlushableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when FlushableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$result = $cacheDriver->flushAll();
$message = $result ? 'Successfully flushed cache entries.' : $message;
}
Expand Down
16 changes: 16 additions & 0 deletions lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ClearableCache;
use Doctrine\Common\Cache\FlushableCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
Expand Down Expand Up @@ -88,12 +90,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new LogicException('Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.');
}

if (!($cacheDriver instanceof ClearableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when ClearableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$ui->comment('Clearing <info>all</info> Query cache entries');

$result = $cacheDriver->deleteAll();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';

if ($input->getOption('flush') === true) {
if (!($cacheDriver instanceof FlushableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when FlushableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$result = $cacheDriver->flushAll();
$message = $result ? 'Successfully flushed cache entries.' : $message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;

use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ClearableCache;
use Doctrine\Common\Cache\FlushableCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
Expand Down Expand Up @@ -88,12 +90,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new LogicException('Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.');
}

if (!($cacheDriver instanceof ClearableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when ClearableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$ui->comment('Clearing <info>all</info> Result cache entries');

$result = $cacheDriver->deleteAll();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';

if ($input->getOption('flush') === true) {
if (!($cacheDriver instanceof FlushableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when FlushableCache interface is implemented, %s does not implement.',
get_class($cacheDriver)
));
}

$result = $cacheDriver->flushAll();
$message = $result ? 'Successfully flushed cache entries.' : $message;
}
Expand Down

0 comments on commit cdc1eca

Please sign in to comment.