1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * @copyright 2020 Mautic Contributors. All rights reserved |
||
7 | * @author Mautic |
||
8 | * |
||
9 | * @link https://mautic.org |
||
10 | * |
||
11 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
12 | */ |
||
13 | |||
14 | namespace Mautic\CacheBundle\EventListener; |
||
15 | |||
16 | use Mautic\CacheBundle\Cache\CacheProvider; |
||
17 | use Psr\Log\LoggerInterface; |
||
18 | use Symfony\Component\Cache\Adapter\AdapterInterface; |
||
19 | use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; |
||
20 | |||
21 | class CacheClearSubscriber implements CacheClearerInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var CacheProvider |
||
25 | */ |
||
26 | private $cacheProvider; |
||
27 | /** |
||
28 | * @var LoggerInterface |
||
29 | */ |
||
30 | private $logger; |
||
31 | |||
32 | public function __construct(AdapterInterface $cacheProvider, LoggerInterface $logger) |
||
33 | { |
||
34 | $this->cacheProvider = $cacheProvider; |
||
0 ignored issues
–
show
|
|||
35 | $this->logger = $logger; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param string $cacheDir |
||
40 | * |
||
41 | * @throws \Exception |
||
42 | */ |
||
43 | public function clear($cacheDir): void |
||
44 | { |
||
45 | try { |
||
46 | $reflect = new \ReflectionClass($this->cacheProvider->getCacheAdapter()); |
||
47 | $adapter = $reflect->getShortName(); |
||
48 | } catch (\ReflectionException $e) { |
||
49 | $adapter = 'unknown'; |
||
50 | } |
||
51 | |||
52 | try { |
||
53 | if (!$this->cacheProvider->clear()) { |
||
54 | $this->logger->emergency('Failed to clear Mautic cache.', ['adapter' => $adapter]); |
||
55 | throw new \Exception('Failed to clear '.$adapter); |
||
56 | } |
||
57 | } catch (\PDOException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
58 | } |
||
59 | } |
||
60 | } |
||
61 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.