Source   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 96
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getItem() 0 4 1
A __toString() 0 4 1
A getId() 0 4 1
A setUrl() 0 6 1
A getUrl() 0 4 1
A setItem() 0 18 4
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 Doctrine\ORM\Mapping as ORM;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
/**
16
 * Source for item fill.
17
 *
18
 * @ORM\Entity
19
 * @ORM\Table(name="source", indexes={
20
 *   @ORM\Index(name="source_url_idx", columns={"url"})
21
 * })
22
 *
23
 * @author  Peter Gribanov <[email protected]>
24
 */
25
class Source
26
{
27
    /**
28
     * @ORM\Id
29
     * @ORM\GeneratedValue
30
     * @ORM\Column(type="integer")
31
     *
32
     * @var int
33
     */
34
    protected $id = 0;
35
36
    /**
37
     * @ORM\Column(type="string", length=256)
38
     * @Assert\NotBlank()
39
     * @Assert\Url()
40
     *
41
     * @var string
42
     */
43
    protected $url = '';
44
45
    /**
46
     * @ORM\ManyToOne(targetEntity="Item", inversedBy="sources", cascade={"persist"})
47
     * @ORM\JoinColumn(name="item", referencedColumnName="id")
48
     *
49
     * @var Item
50
     */
51
    protected $item;
52
53
    /**
54
     * @return int
55
     */
56 1
    public function getId()
57
    {
58 1
        return $this->id;
59
    }
60
61
    /**
62
     * @param string $url
63
     *
64
     * @return Source
65
     */
66 2
    public function setUrl($url)
67
    {
68 2
        $this->url = $url;
69
70 2
        return $this;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 2
    public function getUrl()
77
    {
78 2
        return $this->url;
79
    }
80
81
    /**
82
     * @param Item $item
83
     *
84
     * @return Source
85
     */
86 1
    public function setItem(Item $item = null)
87
    {
88 1
        if ($this->item !== $item) {
89
            // romove link on this item for old item
90 1
            if ($this->item instanceof Item) {
91 1
                $tmp = $this->item;
92 1
                $this->item = null;
93 1
                $tmp->removeSource($this);
94 1
            }
95 1
            $this->item = $item;
96
            // add link on this item
97 1
            if ($item instanceof Item) {
98 1
                $this->item->addSource($this);
99 1
            }
100 1
        }
101
102 1
        return $this;
103
    }
104
105
    /**
106
     * @return Item
107
     */
108 1
    public function getItem()
109
    {
110 1
        return $this->item;
111
    }
112
113
    /**
114
     * @return string
115
     */
116 1
    public function __toString()
117
    {
118 1
        return $this->getUrl();
119
    }
120
}
121