Studio   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 105
loc 105
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getId() 4 4 1
A setName() 6 6 1
A getName() 4 4 1
A addItem() 9 9 2
A removeItem() 9 9 2
A getItems() 4 4 1
A __toString() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use Doctrine\Common\Collections\ArrayCollection;
15
16
/**
17
 * @ORM\Entity
18
 * @ORM\Table(name="studio")
19
 *
20
 * @author  Peter Gribanov <[email protected]>
21
 */
22 View Code Duplication
class Studio
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    /**
25
     * @ORM\Id
26
     * @ORM\GeneratedValue
27
     * @ORM\Column(type="integer")
28
     *
29
     * @var int
30
     */
31
    protected $id = 0;
32
33
    /**
34
     * @ORM\Column(type="string", length=128)
35
     * @Assert\NotBlank()
36
     *
37
     * @var string
38
     */
39
    protected $name = '';
40
41
    /**
42
     * @ORM\OneToMany(targetEntity="Item", mappedBy="studio")
43
     *
44
     * @var ArrayCollection
45
     */
46
    protected $items;
47
48 86
    public function __construct()
49
    {
50 86
        $this->items = new ArrayCollection();
51 86
    }
52
53
    /**
54
     * @return int
55
     */
56 1
    public function getId()
57
    {
58 1
        return $this->id;
59
    }
60
61
    /**
62
     * @param string $name
63
     *
64
     * @return Studio
65
     */
66 2
    public function setName($name)
67
    {
68 2
        $this->name = $name;
69
70 2
        return $this;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 2
    public function getName()
77
    {
78 2
        return $this->name;
79
    }
80
81
    /**
82
     * @param Item $item
83
     *
84
     * @return Studio
85
     */
86 1
    public function addItem(Item $item)
87
    {
88 1
        if (!$this->items->contains($item)) {
89 1
            $this->items->add($item);
90 1
            $item->setStudio($this);
91 1
        }
92
93 1
        return $this;
94
    }
95
96
    /**
97
     * @param Item $item
98
     *
99
     * @return Studio
100
     */
101 1
    public function removeItem(Item $item)
102
    {
103 1
        if ($this->items->contains($item)) {
104 1
            $this->items->removeElement($item);
105 1
            $item->setStudio(null);
106 1
        }
107
108 1
        return $this;
109
    }
110
111
    /**
112
     * @return ArrayCollection
113
     */
114 1
    public function getItems()
115
    {
116 1
        return $this->items;
117
    }
118
119
    /**
120
     * @return string
121
     */
122 1
    public function __toString()
123
    {
124 1
        return $this->getName();
125
    }
126
}
127