CategoryManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A deactivate() 0 4 1
A activate() 0 4 1
A create() 0 7 1
1
<?php
2
3
namespace Matks\Bundle\CustomerSupportBundle\Manager;
4
5
use Matks\Bundle\CustomerSupportBundle\Model\CategoryInterface;
6
7
use Doctrine\Common\Persistence\ManagerRegistry;
8
9
/**
10
 * Category Manager
11
 *
12
 * @author Mathieu Ferment <[email protected]>
13
 */
14
class CategoryManager implements CategoryManagerInterface
15
{
16
    /**
17
     * @var ManagerRegistry
18
     */
19
    private $doctrine;
20
21
    /**
22
     * @var string Category FQDN
23
     */
24
    private $categoryClass;
25
26
    /**
27
     * Constructor
28
     *
29
     * @param ManagerRegistry $doctrine
30
     * @param string          $categoryClass
31
     */
32 4
    public function __construct(ManagerRegistry $doctrine, $categoryClass)
33
    {
34 4
        $this->doctrine      = $doctrine;
35 4
        $this->categoryClass = $categoryClass;
36 4
    }
37
38
    /**
39
     * Create a new category
40
     *
41
     * @param  string $title
42
     *
43
     * @return CategoryInterface
44
     */
45 1
    public function create($title)
46
    {
47 1
        $category = new $this->categoryClass($title);
48 1
        $this->doctrine->getManager()->persist($category);
49 1
        $this->doctrine->getManager()->flush();
50
51 1
        return $category;
52
    }
53
54
    /**
55
     * Deactivate a category
56
     *
57
     * @param CategoryInterface $category
58
     */
59 1
    public function deactivate(CategoryInterface $category)
60
    {
61 1
        $category->deactivate();
62 1
        $this->doctrine->getManager()->flush();
63 1
    }
64
65
    /**
66
     * Reactivate a category
67
     *
68
     * @param CategoryInterface $category
69
     */
70 1
    public function activate(CategoryInterface $category)
71
    {
72 1
        $category->activate();
73 1
        $this->doctrine->getManager()->flush();
74 1
    }
75
}
76