CategoryMenuBoxController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getActiveCategories() 0 18 3
A indexAction() 0 7 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CatalogBundle\Controller\Box;
14
15
use Symfony\Component\HttpFoundation\Response;
16
use WellCommerce\Bundle\CatalogBundle\Entity\Category;
17
use WellCommerce\Bundle\CatalogBundle\Repository\CategoryRepository;
18
use WellCommerce\Bundle\CoreBundle\Controller\Box\AbstractBoxController;
19
use WellCommerce\Component\Layout\Collection\LayoutBoxSettingsCollection;
20
21
/**
22
 * Class CategoryMenuBoxController
23
 *
24
 * @author  Adam Piotrowski <[email protected]>
25
 */
26
final class CategoryMenuBoxController extends AbstractBoxController
27
{
28
    public function indexAction(LayoutBoxSettingsCollection $boxSettings): Response
29
    {
30
        return $this->displayTemplate('index', [
31
            'active'      => $this->getActiveCategories(),
32
            'boxSettings' => $boxSettings,
33
        ]);
34
    }
35
    
36
    private function getActiveCategories(): array
37
    {
38
        $active = [];
39
        if ($this->getCategoryStorage()->hasCurrentCategory()) {
40
            /** @var CategoryRepository $repository */
41
            $repository = $this->manager->getRepository();
42
            $category   = $this->getCategoryStorage()->getCurrentCategory();
43
            $paths      = $repository->getCategoryPath($category);
44
            $active     = [];
45
            
46
            /** @var Category $path */
47
            foreach ($paths as $path) {
48
                $active[] = $path->getId();
49
            }
50
        }
51
        
52
        return $active;
53
    }
54
}
55