Completed
Pull Request — master (#245)
by Anton
19:51 queued 15:09
created

Grid   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 35
ccs 12
cts 15
cp 0.8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 22 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/skeleton
5
 */
6
7
/**
8
 * @namespace
9
 */
10
namespace Application\Users;
11
12
use Bluz\Db\Query\Select;
13
use Bluz\Grid\Source\SelectSource;
14
15
/**
16
 * @category Application
17
 * @package  Users
18
 */
19
class Grid extends \Bluz\Grid\Grid
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $uid = 'users';
25
26
    /**
27
     * init
28
     *
29
     * @return self
30
     */
31 1
    public function init()
32
    {
33
        // Create Select
34 1
        $select = new Select();
35 1
        $select->select('u.*, u.id as uid, GROUP_CONCAT( ar.`name` SEPARATOR ", " ) AS rolesList')
36 1
            ->from('users', 'u')
37 1
            ->leftJoin('u', 'acl_users_roles', 'aur', 'u.`id` = aur.`userId`')
38 1
            ->leftJoin('aur', 'acl_roles', 'ar', 'ar.`id` = aur.`roleId`')
39 1
            ->groupBy('u.id');
40
41
42
        // Setup adapter
43 1
        $adapter = new SelectSource();
44 1
        $adapter->setSource($select);
45
46 1
        $this->setAdapter($adapter);
47 1
        $this->setDefaultLimit(25);
48 1
        $this->addAlias('id', 'u.id');
0 ignored issues
show
Documentation Bug introduced by
The method addAlias does not exist on object<Application\Users\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
        $this->setAllowOrders(['login', 'email', 'status', 'id']);
50
        $this->setAllowFilters(['login', 'email', 'status', 'id', 'roleId']);
51
        return $this;
52
    }
53
}
54