Passed
Push — master ( c0f44b...570aa6 )
by Jan
03:34
created

ToolsTreeBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTree() 0 18 1
1
<?php
2
/**
3
 * part-db version 0.1
4
 * Copyright (C) 2005 Christoph Lechner
5
 * http://www.cl-projects.de/.
6
 *
7
 * part-db version 0.2+
8
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
9
 * http://code.google.com/p/part-db/
10
 *
11
 * Part-DB Version 0.4+
12
 * Copyright (C) 2016 - 2019 Jan Böhmer
13
 * https://github.com/jbtronics
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
28
 */
29
30
namespace App\Services;
31
32
use App\Helpers\TreeViewNode;
33
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
34
use Symfony\Contracts\Translation\TranslatorInterface;
35
36
/**
37
 * This Service generates the tree structure for the tools.
38
 * @package App\Services
39
 */
40
class ToolsTreeBuilder
41
{
42
43
    protected $translator;
44
    protected $urlGenerator;
45
46
    public function __construct(TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator)
47
    {
48
        $this->translator = $translator;
49
        $this->urlGenerator = $urlGenerator;
50
    }
51
52
53
    /**
54
     * Generates the tree for the tools menu.
55
     * @return TreeViewNode The array containing all Nodes for the tools menu.
56
     */
57
    public function getTree() : array
58
    {
59
        //TODO: Use proper values
60
61
        $nodes = array();
62
        $nodes[] = new TreeViewNode('Node 1');
63
        $nodes[] = new TreeViewNode('Node 2');
64
65
        $tree[] = new TreeViewNode('test', 'www.google.de', $nodes);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$tree was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tree = array(); before regardless.
Loading history...
66
67
        $show_nodes = array();
68
        $show_nodes[] = new TreeViewNode($this->translator->trans('tree.tools.show.all_parts'),
69
            $this->urlGenerator->generate('parts_show_all')
70
        );
71
72
        $tree[] = new TreeViewNode($this->translator->trans('tree.tools.show'), null, $show_nodes);
73
74
        return $tree;
75
    }
76
}
77