Completed
Push — 2.0 ( 090eab...b837a7 )
by Nicolas
14:41
created

CacheUserTokenDecorator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A allForUser() 0 10 1
A generateFor() 0 6 1
1
<?php namespace Modules\User\Repositories\Cache;
2
3
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
4
use Modules\User\Repositories\UserTokenRepository;
5
6
class CacheUserTokenDecorator extends BaseCacheDecorator implements UserTokenRepository
7
{
8
    /**
9
     * @var UserTokenRepository
10
     */
11
    protected $repository;
12
13
    public function __construct(UserTokenRepository $repository)
14
    {
15
        parent::__construct();
16
        $this->entityName = 'user-tokens';
17
        $this->repository = $repository;
18
    }
19
20
    /**
21
     * Get all tokens for the given user
22
     * @param int $userId
23
     * @return \Illuminate\Database\Eloquent\Collection
24
     */
25
    public function allForUser($userId)
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}.allForUser.{$userId}", $this->cacheTime,
30
                function () use ($userId) {
31
                    return $this->repository->allForUser($userId);
32
                }
33
            );
34
    }
35
36
    /**
37
     * @param int $userId
38
     * @return \Modules\User\Entities\UserToken
39
     */
40
    public function generateFor($userId)
41
    {
42
        $this->clearCache();
43
44
        return $this->repository->generateFor($userId);
45
    }
46
}
47