CacheWidgetDecorator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 48.78 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A findForUser() 10 10 1
A updateOrCreateForUser() 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\Dashboard\Repositories\Cache;
2
3
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
4
use Modules\Dashboard\Repositories\WidgetRepository;
5
6
class CacheWidgetDecorator extends BaseCacheDecorator implements WidgetRepository
7
{
8
    public function __construct(WidgetRepository $widgets)
9
    {
10
        parent::__construct();
11
        $this->entityName = 'dashboard.widgets';
12
        $this->repository = $widgets;
13
    }
14
15
    /**
16
     * Find the saved state of widgets for the given user id
17
     * @param int $userId
18
     * @return string
19
     */
20 View Code Duplication
    public function findForUser($userId)
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...
21
    {
22
        return $this->cache
23
            ->tags($this->entityName, 'global')
24
            ->remember("{$this->locale}.{$this->entityName}.findForUser.{$userId}", $this->cacheTime,
25
                function () use ($userId) {
26
                    return $this->repository->findForUser($userId);
27
                }
28
            );
29
    }
30
31
    /**
32
     * Update or create the given widgets for given user
33
     * @param array $widgets
34
     * @return void
35
     */
36 View Code Duplication
    public function updateOrCreateForUser($widgets, $userId)
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...
37
    {
38
        return $this->cache
39
            ->tags($this->entityName, 'global')
40
            ->remember("{$this->locale}.{$this->entityName}.updateOrCreateForUser.{$userId}", $this->cacheTime,
41
                function () use ($widgets, $userId) {
42
                    return $this->repository->updateOrCreateForUser($widgets, $userId);
43
                }
44
            );
45
    }
46
}
47