User   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getGetters() 0 5 1
A getRowActions() 0 24 1
A __construct() 0 8 1
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 AbterPhp\Framework\Html\Helper\Attributes;
15
use Opulence\Routing\Urls\UrlGenerator;
16
17
class User extends BaseFactory
18
{
19
    private const GETTER_USERNAME = 'getUsername';
20
    private const GETTER_EMAIL    = 'getEmail';
21
22
    /**
23
     * User constructor.
24
     *
25
     * @param UrlGenerator      $urlGenerator
26
     * @param PaginationFactory $paginationFactory
27
     * @param TableFactory      $tableFactory
28
     * @param GridFactory       $gridFactory
29
     * @param Filters           $filters
30
     */
31
    public function __construct(
32
        UrlGenerator $urlGenerator,
33
        PaginationFactory $paginationFactory,
34
        TableFactory $tableFactory,
35
        GridFactory $gridFactory,
36
        Filters $filters
37
    ) {
38
        parent::__construct($urlGenerator, $paginationFactory, $tableFactory, $gridFactory, $filters);
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getGetters(): array
45
    {
46
        return [
47
            HeaderFactory::GROUP_USERNAME => static::GETTER_USERNAME,
48
            HeaderFactory::GROUP_EMAIL    => static::GETTER_EMAIL,
49
        ];
50
    }
51
52
    /**
53
     * @return Actions
54
     */
55
    protected function getRowActions(): Actions
56
    {
57
        $attributeCallbacks = $this->getAttributeCallbacks();
58
59
        $editAttributes   = Attributes::fromArray([Html5::ATTR_HREF => [Route::USERS_EDIT]]);
60
        $deleteAttributes = Attributes::fromArray([Html5::ATTR_HREF => [Route::USERS_DELETE]]);
61
62
        $cellActions   = new Actions();
63
        $cellActions[] = new Action(
64
            static::LABEL_EDIT,
65
            $this->editIntents,
66
            $editAttributes,
67
            $attributeCallbacks,
68
            Html5::TAG_A
69
        );
70
        $cellActions[] = new Action(
71
            static::LABEL_DELETE,
72
            $this->deleteIntents,
73
            $deleteAttributes,
74
            $attributeCallbacks,
75
            Html5::TAG_A
76
        );
77
78
        return $cellActions;
79
    }
80
}
81