Completed
Push — master ( e6d1d6...c38c1e )
by Mike
08:50
created

PurgeCachesWhenForced::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author    Mike van Riel <[email protected]>
12
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
14
 * @link      http://phpdoc.org
15
 */
16
17
namespace phpDocumentor\Application\Stage\Cache;
18
19
use phpDocumentor\Application\Stage\Payload;
20
use Psr\Log\LoggerInterface;
21
use Symfony\Component\Cache\Adapter\AdapterInterface;
22
23
final class PurgeCachesWhenForced
24
{
25
    private $filesCache;
26
    private $descriptorsCache;
27
    private $logger;
28
29
    public function __construct(
30
        AdapterInterface $filesCache,
31
        AdapterInterface $descriptorsCache,
32
        LoggerInterface $logger
33
    ) {
34
        $this->filesCache = $filesCache;
35
        $this->descriptorsCache = $descriptorsCache;
36
        $this->logger = $logger;
37
    }
38
39
    public function __invoke(Payload $payload)
40
    {
41
        $this->logger->info('Checking whether to purge cache');
42
        if (! $payload->getConfig()['phpdocumentor']['use-cache']) {
43
            $this->logger->info('Purging cache');
44
            $this->filesCache->clear();
45
            $this->descriptorsCache->clear();
46
        }
47
48
        return $payload;
49
    }
50
}
51