CacheMenuItemDecorator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 43.86 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 7
lcom 1
cbo 2
dl 50
loc 114
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A rootsForMenu() 10 10 1
A getForRoutes() 0 10 1
A getRootForMenu() 10 10 1
A getTreeForMenu() 10 10 1
A allRootsForMenu() 10 10 1
A findByUriInLanguage() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Modules\Menu\Repositories\Cache;
2
3
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
4
use Modules\Menu\Repositories\MenuItemRepository;
5
6
class CacheMenuItemDecorator extends BaseCacheDecorator implements MenuItemRepository
7
{
8
    /**
9
     * @var MenuItemRepository
10
     */
11
    protected $repository;
12
13
    public function __construct(MenuItemRepository $menuItem)
14
    {
15
        parent::__construct();
16
        $this->entityName = 'menusItems';
17
        $this->repository = $menuItem;
18
    }
19
20
    /**
21
     * Get all root elements
22
     *
23
     * @param  int   $menuId
24
     * @return mixed
25
     */
26 View Code Duplication
    public function rootsForMenu($menuId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        return $this->cache
29
            ->tags($this->entityName, 'global')
30
            ->remember("{$this->locale}.{$this->entityName}.rootsForMenu.{$menuId}", $this->cacheTime,
31
                function () use ($menuId) {
32
                    return $this->repository->rootsForMenu($menuId);
33
                }
34
            );
35
    }
36
37
    /**
38
     * Get the menu items ready for routes
39
     *
40
     * @return mixed
41
     */
42
    public function getForRoutes()
43
    {
44
        return $this->cache
45
            ->tags($this->entityName, 'global')
46
            ->remember("{$this->locale}.{$this->entityName}.getForRoutes", $this->cacheTime,
47
                function () {
48
                    return $this->repository->getForRoutes();
49
                }
50
            );
51
    }
52
53
    /**
54
     * Get the root menu item for the given menu id
55
     *
56
     * @param  int    $menuId
57
     * @return object
58
     */
59 View Code Duplication
    public function getRootForMenu($menuId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        return $this->cache
62
            ->tags($this->entityName, 'global')
63
            ->remember("{$this->locale}.{$this->entityName}.getRootForMenu.{$menuId}", $this->cacheTime,
64
                function () use ($menuId) {
65
                    return $this->repository->getRootForMenu($menuId);
66
                }
67
            );
68
    }
69
70
    /**
71
     * Return a complete tree for the given menu id
72
     *
73
     * @param  int    $menuId
74
     * @return object
75
     */
76 View Code Duplication
    public function getTreeForMenu($menuId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        return $this->cache
79
            ->tags($this->entityName, 'global')
80
            ->remember("{$this->locale}.{$this->entityName}.getTreeForMenu.{$menuId}", $this->cacheTime,
81
                function () use ($menuId) {
82
                    return $this->repository->getTreeForMenu($menuId);
83
                }
84
            );
85
    }
86
87
    /**
88
     * Get all root elements
89
     *
90
     * @param  int    $menuId
91
     * @return object
92
     */
93 View Code Duplication
    public function allRootsForMenu($menuId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        return $this->cache
96
            ->tags($this->entityName, 'global')
97
            ->remember("{$this->locale}.{$this->entityName}.allRootsForMenu.{$menuId}", $this->cacheTime,
98
                function () use ($menuId) {
99
                    return $this->repository->allRootsForMenu($menuId);
100
                }
101
            );
102
    }
103
104
    /**
105
     * @param  string $uri
106
     * @param  string $locale
107
     * @return object
108
     */
109 View Code Duplication
    public function findByUriInLanguage($uri, $locale)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        return $this->cache
112
            ->tags($this->entityName, 'global')
113
            ->remember("{$this->locale}.{$this->entityName}.findByUriInLanguage.{$uri}.{$locale}", $this->cacheTime,
114
                function () use ($uri, $locale) {
115
                    return $this->repository->findByUriInLanguage($uri, $locale);
116
                }
117
            );
118
    }
119
}
120