CachePageDecorator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 1
cbo 1
dl 20
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A findHomepage() 10 10 1
A countAll() 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\Page\Repositories\Cache;
2
3
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
4
use Modules\Page\Repositories\PageRepository;
5
6
class CachePageDecorator extends BaseCacheDecorator implements PageRepository
7
{
8
    /**
9
     * @var PageRepository
10
     */
11
    protected $repository;
12
13
    public function __construct(PageRepository $page)
14
    {
15
        parent::__construct();
16
        $this->entityName = 'pages';
17
        $this->repository = $page;
18
    }
19
20
    /**
21
     * Find the page set as homepage
22
     *
23
     * @return object
24
     */
25 View Code Duplication
    public function findHomepage()
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...
26
    {
27
        return $this->cache
28
            ->tags($this->entityName, 'global')
29
            ->remember("{$this->locale}.{$this->entityName}.findHomepage", $this->cacheTime,
30
                function () {
31
                    return $this->repository->findHomepage();
32
                }
33
            );
34
    }
35
36
    /**
37
     * Count all records
38
     * @return int
39
     */
40 View Code Duplication
    public function countAll()
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...
41
    {
42
        return $this->cache
43
            ->tags($this->entityName, 'global')
44
            ->remember("{$this->locale}.{$this->entityName}.countAll", $this->cacheTime,
45
                function () {
46
                    return $this->repository->countAll();
47
                }
48
            );
49
    }
50
}
51