Completed
Pull Request — master (#47)
by
unknown
11:14
created

CacheUserTokenDecorator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

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 4
nc 1
nop 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