Passed
Push — master ( 7ba2cb...1d30f9 )
by Peter
02:20
created

UserApiKey   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getWhereConditions() 0 7 1
A getSqlParams() 0 9 1
A __construct() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Service\RepoGrid;
6
7
use AbterPhp\Admin\Grid\Factory\UserApiKey as GridFactory;
8
use AbterPhp\Admin\Orm\UserApiKeyRepo as Repo;
9
use AbterPhp\Framework\Constant\Session;
10
use AbterPhp\Framework\Databases\Queries\FoundRows;
11
use AbterPhp\Framework\Grid\Grid;
12
use AbterPhp\Framework\Http\Service\RepoGrid\RepoGridAbstract;
13
use Casbin\Enforcer;
14
use Opulence\Sessions\ISession;
15
16
class UserApiKey extends RepoGridAbstract
17
{
18
    /** @var ISession */
19
    protected $session;
20
21
    /**
22
     * UserApiKey constructor.
23
     *
24
     * @param Enforcer    $enforcer
25
     * @param Repo        $repo
26
     * @param FoundRows   $foundRows
27
     * @param GridFactory $gridFactory
28
     * @param ISession    $session
29
     */
30
    public function __construct(
31
        Enforcer $enforcer,
32
        Repo $repo,
33
        FoundRows $foundRows,
34
        GridFactory $gridFactory,
35
        ISession $session
36
    ) {
37
        parent::__construct($enforcer, $repo, $foundRows, $gridFactory);
38
39
        $this->session = $session;
40
    }
41
42
    /**
43
     * @param Grid $grid
44
     *
45
     * @return array
46
     */
47
    protected function getWhereConditions(Grid $grid): array
48
    {
49
        $conditions = $grid->getWhereConditions();
50
51
        $conditions[] = 'uak.user_id = ?';
52
53
        return $conditions;
54
    }
55
56
    /**
57
     * @param Grid $grid
58
     *
59
     * @return array
60
     */
61
    protected function getSqlParams(Grid $grid): array
62
    {
63
        $sqlParams = $grid->getSqlParams();
64
65
        $userId = $this->session->get(Session::USER_ID);
66
67
        $sqlParams[] = $userId;
68
69
        return $sqlParams;
70
    }
71
}
72