SearchFiller::getUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\Entity;
11
12
use AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Filler\FillerInterface;
13
use Symfony\Component\Validator\Constraints as Assert;
14
use AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Filler\Chain;
15
use Symfony\Component\Validator\Context\ExecutionContextInterface;
16
17
/**
18
 * Search filler.
19
 *
20
 * @Assert\Callback(methods={"isUrlSupported"})
21
 *
22
 * @author  Peter Gribanov <[email protected]>
23
 */
24
class SearchFiller
25
{
26
    /**
27
     * @Assert\NotBlank()
28
     * @Assert\Url()
29
     *
30
     * @var string
31
     */
32
    protected $url = '';
33
34
    /**
35
     * @var FillerInterface|null
36
     */
37
    protected $filler;
38
39
    /**
40
     * @var Chain
41
     */
42
    protected $chain;
43
44
    /**
45
     * @param Chain $chain
46
     */
47
    public function __construct(Chain $chain)
48
    {
49
        $this->chain = $chain;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getUrl()
56
    {
57
        return $this->url;
58
    }
59
60
    /**
61
     * @param string $url
62
     *
63
     * @return SearchFiller
64
     */
65
    public function setUrl($url)
66
    {
67
        $this->url = $url;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return FillerInterface|null
74
     */
75
    public function getFiller()
76
    {
77
        return $this->filler;
78
    }
79
80
    /**
81
     * @param ExecutionContextInterface $context
82
     */
83
    public function isUrlSupported(ExecutionContextInterface $context)
84
    {
85
        foreach ($this->chain->getPlugins() as $plugin) {
86
            /* @var $plugin FillerInterface */
87
            if ($plugin->isSupportedUrl($this->url)) {
88
                $this->filler = $plugin;
89
90
                return;
91
            }
92
        }
93
94
        $context
95
            ->buildViolation('No fillers that would support this URL')
96
            ->atPath('url')
97
            ->addViolation();
98
    }
99
}
100