CachedDomainsListWarmer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isOptional() 0 4 1
A warmUp() 0 9 2
1
<?php
2
3
namespace EmanueleMinotto\DomainParserBundle\CacheWarmer;
4
5
use Pdp\HttpAdapter\HttpAdapterInterface;
6
use Pdp\PublicSuffixListManager;
7
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
8
9
/**
10
 * Refresh domains list on cache warmup.
11
 *
12
 * @author Emanuele Minotto <[email protected]>
13
 */
14
class CachedDomainsListWarmer extends CacheWarmer
15
{
16
    /**
17
     * Pdp Public Suffix List Manager HTTP adapter.
18
     *
19
     * @var HttpAdapterInterface|null
20
     */
21
    private $httpAdapter;
22
23
    /**
24
     * Cache warmer constructor with optional dependency.
25
     *
26
     * @param HttpAdapterInterface|null $httpAdapter
27
     */
28 9
    public function __construct(HttpAdapterInterface $httpAdapter = null)
29
    {
30 9
        $this->httpAdapter = $httpAdapter;
31 9
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 3
    public function isOptional()
37
    {
38 3
        return true;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 6
    public function warmUp($cacheDir)
45
    {
46 6
        $manager = new PublicSuffixListManager($cacheDir);
47 6
        if (null !== $this->httpAdapter) {
48 3
            $manager->setHttpAdapter($this->httpAdapter);
49 3
        }
50
51 6
        $manager->refreshPublicSuffixList();
52 6
    }
53
}
54