CachePostDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 55.74 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A latest() 10 10 1
A getPreviousOf() 12 12 1
A getNextOf() 12 12 1
A __construct() 0 6 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\Blog\Repositories\Cache;
2
3
use Modules\Blog\Repositories\Collection;
4
use Modules\Blog\Repositories\PostRepository;
5
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
6
7
class CachePostDecorator extends BaseCacheDecorator implements PostRepository
8
{
9
    public function __construct(PostRepository $post)
10
    {
11
        parent::__construct();
12
        $this->entityName = 'posts';
13
        $this->repository = $post;
14
    }
15
16
    /**
17
     * Return the latest x blog posts
18
     * @param int $amount
19
     * @return Collection
20
     */
21 View Code Duplication
    public function latest($amount = 5)
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...
22
    {
23
        return $this->cache
24
            ->tags($this->entityName, 'global')
25
            ->remember("{$this->locale}.{$this->entityName}.latest.{$amount}", $this->cacheTime,
26
                function () use ($amount) {
27
                    return $this->repository->latest($amount);
28
                }
29
            );
30
    }
31
32
    /**
33
     * Get the previous post of the given post
34
     * @param object $post
35
     * @return object
36
     */
37 View Code Duplication
    public function getPreviousOf($post)
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...
38
    {
39
        $postId = $post->id;
40
41
        return $this->cache
42
            ->tags($this->entityName, 'global')
43
            ->remember("{$this->locale}.{$this->entityName}.getPreviousOf.{$postId}", $this->cacheTime,
44
                function () use ($post) {
45
                    return $this->repository->getPreviousOf($post);
46
                }
47
            );
48
    }
49
50
    /**
51
     * Get the next post of the given post
52
     * @param object $post
53
     * @return object
54
     */
55 View Code Duplication
    public function getNextOf($post)
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...
56
    {
57
        $postId = $post->id;
58
59
        return $this->cache
60
            ->tags($this->entityName, 'global')
61
            ->remember("{$this->locale}.{$this->entityName}.getNextOf.{$postId}", $this->cacheTime,
62
                function () use ($post) {
63
                    return $this->repository->getNextOf($post);
64
                }
65
            );
66
    }
67
}
68