OverviewEvent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 86
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntries() 0 4 1
A getCategories() 0 4 1
A __construct() 0 5 1
A addEntry() 0 12 2
A addCategory() 0 9 3
1
<?php
2
3
/*
4
 * (c) Jim Martens <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace TwoMartens\Bundle\CoreBundle\Event;
11
12
use Symfony\Component\EventDispatcher\Event;
13
14
/**
15
 * Event object used for overview pages.
16
 *
17
 * @author    Jim Martens <[email protected]>
18
 * @copyright 2013-2015 Jim Martens
19
 */
20
class OverviewEvent extends Event
21
{
22
    /**
23
     * list of entries
24
     * @var array
25
     */
26
    private $entries;
27
28
    /**
29
     * list of categories
30
     * @var array
31
     */
32
    private $categories;
33
34
    /**
35
     * Initializes the event.
36
     */
37
    public function __construct()
38
    {
39
        $this->entries = [];
40
        $this->categories = [];
41
    }
42
43
    /**
44
     * Returns list of entries.
45
     *
46
     * The list contains arrays, each of which has four keys:
47
     * 'entryName', 'translationDomain', 'route', 'role'
48
     *
49
     * @return array[]
50
     */
51
    public function getEntries()
52
    {
53
        return $this->entries;
54
    }
55
56
    /**
57
     * Returns the category info.
58
     *
59
     * Keys are category names and values are translation domains.
60
     *
61
     * @return string[]
62
     */
63
    public function getCategories()
64
    {
65
        return $this->categories;
66
    }
67
68
    /**
69
     * Adds an entry.
70
     *
71
     * @param string $categoryName
72
     * @param string $entryName
73
     * @param string $translationDomain
74
     * @param string $route
75
     * @param string $role
76
     */
77
    public function addEntry($categoryName, $entryName, $translationDomain, $route, $role)
78
    {
79
        if (!isset($this->entries[$categoryName])) {
80
            $this->addCategory($categoryName, $translationDomain);
81
        }
82
        $this->entries[$categoryName][] = [
83
            'entryName' => $entryName,
84
            'translationDomain' => $translationDomain,
85
            'route' => $route,
86
            'role' => $role
87
        ];
88
    }
89
90
    /**
91
     * Adds a category.
92
     *
93
     * @param string $categoryName
94
     * @param string $translationDomain
95
     */
96
    public function addCategory($categoryName, $translationDomain)
97
    {
98
        if (!isset($this->entries[$categoryName])) {
99
            $this->entries[$categoryName] = [];
100
        }
101
        if (!isset($this->categories[$categoryName])) {
102
            $this->categories[$categoryName] = $translationDomain;
103
        }
104
    }
105
}
106