Completed
Push — master ( 1c7649...db66e6 )
by Nicolas
03:01
created

CachePageDecorator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 32.79 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A countAll() 10 10 1
A findBySlugInLocale() 0 10 1
A __construct() 0 6 1
A findHomepage() 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')
0 ignored issues
show
Unused Code introduced by
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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')
0 ignored issues
show
Unused Code introduced by
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
44
            ->remember("{$this->locale}.{$this->entityName}.countAll", $this->cacheTime,
45
                function () {
46
                    return $this->repository->countAll();
47
                }
48
            );
49
    }
50
51
    /**
52
     * @param $slug
53
     * @param $locale
54
     * @return object
55
     */
56
    public function findBySlugInLocale($slug, $locale)
57
    {
58
        return $this->cache
59
            ->tags($this->entityName, 'global')
0 ignored issues
show
Unused Code introduced by
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
            ->remember("{$this->locale}.{$this->entityName}.findBySlugInLocale.{$slug}.{$locale}", $this->cacheTime,
61
                function () use ($slug, $locale) {
62
                    return $this->repository->findBySlugInLocale($slug, $locale);
63
                }
64
            );
65
    }
66
}
67