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

CacheUserTokenDecorator::generateFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 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