Category   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Test Coverage

Coverage 86.96%

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 104
ccs 20
cts 23
cp 0.8696
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTickets() 0 3 1
A activate() 0 7 2
A isActive() 0 3 1
A getTitle() 0 3 1
A deactivate() 0 11 3
1
<?php
2
3
namespace Matks\Bundle\CustomerSupportBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
use Matks\Bundle\CustomerSupportBundle\Model\TicketInterface;
10
use Matks\Bundle\CustomerSupportBundle\Model\CategoryInterface;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use LogicException;
14
15
/**
16
 * Category entity
17
 *
18
 * @ORM\Entity(repositoryClass="Matks\Bundle\CustomerSupportBundle\Repository\CategoryRepository")
19
 * @ORM\Table(name="categories")
20
 *
21
 * @author Mathieu Ferment <[email protected]>
22
 */
23
class Category implements CategoryInterface
24
{
25
    use ORMBehaviors\Timestampable\Timestampable;
26
27
    /**
28
     * @var int
29
     *
30
     * @ORM\Id
31
     * @ORM\Column(type="integer")
32
     * @ORM\GeneratedValue(strategy="AUTO")
33
     */
34
    private $id;
0 ignored issues
show
introduced by
The private property $id is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @var string
38
     *
39
     * @ORM\Column(type="string", length=255)
40
     * @Assert\NotBlank()
41
     */
42
    private $title;
43
44
    /**
45
     * @var TicketInterface[]
46
     *
47
     * There are no addTicket or removeTicket functions as this is done by
48
     * the owning side, on Ticket entity
49
     *
50
     * @ORM\OneToMany(
51
     *     targetEntity="Matks\Bundle\CustomerSupportBundle\Model\TicketInterface",
52
     *     mappedBy="category",
53
     *     cascade={"persist", "remove", "merge"}
54
     * )
55
     * @Assert\Valid()
56
     */
57
    private $tickets;
58
59
    /**
60
     * @var boolean
61
     *
62
     * @ORM\Column(type="boolean")
63
     * @Assert\NotBlank()
64
     */
65
    private $enabled;
66
67
    /**
68
     * Constructor
69
     *
70
     * @param string $title
71
     */
72 4
    public function __construct($title)
73
    {
74 4
        $this->title   = $title;
75 4
        $this->tickets = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Matks\Bundle\CustomerSup...Model\TicketInterface[] of property $tickets.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
76 4
        $this->enabled = true;
77 4
    }
78
79
    /**
80
     * Get tickets associated
81
     *
82
     * @return TicketInterface[]
83
     */
84 3
    public function getTickets()
85
    {
86 3
        return $this->tickets;
87
    }
88
89
    /**
90
     * Get title
91
     *
92
     * @return string
93
     */
94
    public function getTitle()
95
    {
96
        return $this->title;
97
    }
98
99 2
    public function deactivate()
100
    {
101 2
        if (!$this->isActive()) {
102 1
            throw new LogicException("Cannot deactivate category not active");
103
        }
104
105 2
        if (!$this->getTickets()->isEmpty()) {
106
            throw new LogicException("Cannot deactivate category with tickets associated");
107
        }
108
109 2
        $this->enabled = false;
110 2
    }
111
112 1
    public function activate()
113
    {
114 1
        if ($this->isActive()) {
115 1
            throw new LogicException("Cannot activate category already active");
116
        }
117
118 1
        $this->enabled = true;
119 1
    }
120
121
    /**
122
     * @return bool
123
     */
124 3
    public function isActive()
125
    {
126 3
        return true === $this->enabled;
127
    }
128
}
129