Passed
Push — master ( 22c836...715de5 )
by Jan
03:12
created

TreeController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A categoryTree() 0 10 2
A tools() 0 6 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\Controller;
31
32
use App\Entity\Category;
33
use App\Helpers\TreeViewNode;
34
use App\Services\ToolsTreeBuilder;
35
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
36
use Symfony\Component\Routing\Annotation\Route;
37
38
/**
39
 * This controller has the purpose to provide the data for all treeviews.
40
 *
41
 * @package App\Controller
42
 */
43
class TreeController extends AbstractController
44
{
45
    /**
46
     * @Route("/tree/tools/", name="tree_tools")
47
     */
48
    public function tools(ToolsTreeBuilder $builder)
49
    {
50
        $tree = $builder->getTree();
51
52
        //Ignore null values, to save data
53
        return $this->json($tree, 200, [], ['skip_null_values' => true]);
54
    }
55
56
    /**
57
     * @Route("/tree/category/{id}", name="tree_category")
58
     */
59
    public function categoryTree(TreeBuilder $builder, Category $category = null)
60
    {
61
        if($category != null) {
62
            $tree[] = $builder->elementToTreeNode($category);
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...
63
        } else {
64
            $tree = $builder->typeToTree(Category::class);
0 ignored issues
show
Bug introduced by
App\Entity\Category::class of type string is incompatible with the type App\Entity\StructuralDBElement expected by parameter $class_name of App\Controller\TreeBuilder::typeToTree(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
            $tree = $builder->typeToTree(/** @scrutinizer ignore-type */ Category::class);
Loading history...
65
        }
66
67
68
        return $this->json($tree, 200, [], ['skip_null_values' => true]);
69
    }
70
71
72
73
74
}
75