CacheBlockDecorator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A allOnlineInLang() 10 12 1
A get() 10 12 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
2
3
namespace Modules\Block\Repositories\Cache;
4
5
use Modules\Block\Repositories\BlockRepository;
6
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
7
8
class CacheBlockDecorator extends BaseCacheDecorator implements BlockRepository
9
{
10
    public function __construct(BlockRepository $block)
11
    {
12
        parent::__construct();
13
        $this->entityName = 'block.blocks';
14
        $this->repository = $block;
15
    }
16
17
    /**
18
     * Get all online blocks in the given language
19
     * @param string $lang
20
     * @return object
21
     */
22 View Code Duplication
    public function allOnlineInLang($lang)
23
    {
24
        return $this->cache
25
            ->tags([$this->entityName, 'global'])
26
            ->remember(
27
                "{$this->locale}.{$this->entityName}.allOnlineInLang",
28
                $this->cacheTime,
29
                function () use ($lang) {
30
                    return $this->repository->allOnlineInLang($lang);
31
                }
32
            );
33
    }
34
35
    /**
36
     * Get a block body by its name if it's online
37
     * @param string $name
38
     * @return string
39
     */
40 View Code Duplication
    public function get($name)
41
    {
42
        return $this->cache
43
            ->tags([$this->entityName, 'global'])
44
            ->remember(
45
                "{$this->locale}.{$this->entityName}.get.{$name}",
46
                $this->cacheTime,
47
                function () use ($name) {
48
                    return $this->repository->get($name);
49
                }
50
            );
51
    }
52
}
53