ApiClient   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 53
rs 10

3 Methods

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