Passed
Push — master ( 80fed1...32ef61 )
by Peter
09:46
created

User::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Grid\Factory;
6
7
use AbterPhp\Admin\Constant\Route;
8
use AbterPhp\Admin\Grid\Factory\Table\Header\User as HeaderFactory;
9
use AbterPhp\Admin\Grid\Factory\Table\User as TableFactory;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, AbterPhp\Admin\Grid\Factory\TableFactory. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use AbterPhp\Admin\Grid\Filters\User as Filters;
11
use AbterPhp\Framework\Constant\Html5;
12
use AbterPhp\Framework\Grid\Action\Action;
13
use AbterPhp\Framework\Grid\Component\Actions;
14
use Opulence\Routing\Urls\UrlGenerator;
15
16
class User extends BaseFactory
17
{
18
    private const GETTER_USERNAME = 'getUsername';
19
    private const GETTER_EMAIL    = 'getEmail';
20
21
    /**
22
     * User constructor.
23
     *
24
     * @param UrlGenerator      $urlGenerator
25
     * @param PaginationFactory $paginationFactory
26
     * @param TableFactory      $tableFactory
27
     * @param GridFactory       $gridFactory
28
     * @param Filters           $filters
29
     */
30
    public function __construct(
31
        UrlGenerator $urlGenerator,
32
        PaginationFactory $paginationFactory,
33
        TableFactory $tableFactory,
34
        GridFactory $gridFactory,
35
        Filters $filters
36
    ) {
37
        parent::__construct($urlGenerator, $paginationFactory, $tableFactory, $gridFactory, $filters);
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function getGetters(): array
44
    {
45
        return [
46
            HeaderFactory::GROUP_USERNAME => static::GETTER_USERNAME,
47
            HeaderFactory::GROUP_EMAIL    => static::GETTER_EMAIL,
48
        ];
49
    }
50
51
    /**
52
     * @return Actions
53
     */
54
    protected function getRowActions(): Actions
55
    {
56
        $attributeCallbacks = $this->getAttributeCallbacks();
57
58
        $editAttributes = [
59
            Html5::ATTR_HREF => [Route::USERS_EDIT],
60
        ];
61
62
        $deleteAttributes = [
63
            Html5::ATTR_HREF => [Route::USERS_DELETE],
64
        ];
65
66
        $cellActions   = new Actions();
67
        $cellActions[] = new Action(
68
            static::LABEL_EDIT,
69
            $this->editIntents,
70
            $editAttributes,
71
            $attributeCallbacks,
72
            Html5::TAG_A
73
        );
74
        $cellActions[] = new Action(
75
            static::LABEL_DELETE,
76
            $this->deleteIntents,
77
            $deleteAttributes,
78
            $attributeCallbacks,
79
            Html5::TAG_A
80
        );
81
82
        return $cellActions;
83
    }
84
}
85