WidgetCacheRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 48
loc 48
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A all() 6 6 1
A getPublished() 6 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
2
3
namespace Yajra\CMS\Repositories\Widget;
4
5
use Illuminate\Contracts\Cache\Repository as Cache;
6
7 View Code Duplication
class WidgetCacheRepository implements WidgetRepository
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /**
10
     * @var \Yajra\CMS\Repositories\Widget\WidgetRepository
11
     */
12
    protected $repository;
13
14
    /**
15
     * @var \Illuminate\Contracts\Cache\Repository
16
     */
17
    protected $cache;
18
19
    /**
20
     * WidgetCacheRepository constructor.
21
     *
22
     * @param \Yajra\CMS\Repositories\Widget\WidgetRepository $repository
23
     * @param \Illuminate\Contracts\Cache\Repository $cache
24
     */
25
    public function __construct(WidgetRepository $repository, Cache $cache)
26
    {
27
        $this->repository = $repository;
28
        $this->cache      = $cache;
29
    }
30
31
    /**
32
     * Get all widgets.
33
     *
34
     * @return \Illuminate\Database\Eloquent\Collection|static[]
35
     */
36
    public function all()
37
    {
38
        return $this->cache->rememberForever('widgets.all', function () {
39
            return $this->repository->all();
40
        });
41
    }
42
43
    /**
44
     * Get all published widgets.
45
     *
46
     * @return \Illuminate\Database\Eloquent\Collection|static[]
47
     */
48
    public function getPublished()
49
    {
50
        return $this->cache->rememberForever('widgets.published', function () {
51
            return $this->repository->getPublished();
52
        });
53
    }
54
}