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