UserGroup::getRowActions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 24
rs 9.7
cc 1
nc 1
nop 0
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\UserGroup as HeaderFactory;
9
use AbterPhp\Admin\Grid\Factory\Table\UserGroup 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\UserGroup 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 UserGroup extends BaseFactory
18
{
19
    private const GETTER_NAME = 'getName';
20
21
    /**
22
     * UserGroup 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_NAME => static::GETTER_NAME,
47
        ];
48
    }
49
50
    /**
51
     * @return Actions
52
     */
53
    protected function getRowActions(): Actions
54
    {
55
        $attributeCallbacks = $this->getAttributeCallbacks();
56
57
        $editAttributes   = Attributes::fromArray([Html5::ATTR_HREF => [Route::USER_GROUPS_EDIT]]);
58
        $deleteAttributes = Attributes::fromArray([Html5::ATTR_HREF => [Route::USER_GROUPS_DELETE]]);
59
60
        $cellActions   = new Actions();
61
        $cellActions[] = new Action(
62
            static::LABEL_EDIT,
63
            $this->editIntents,
64
            $editAttributes,
65
            $attributeCallbacks,
66
            Html5::TAG_A
67
        );
68
        $cellActions[] = new Action(
69
            static::LABEL_DELETE,
70
            $this->deleteIntents,
71
            $deleteAttributes,
72
            $attributeCallbacks,
73
            Html5::TAG_A
74
        );
75
76
        return $cellActions;
77
    }
78
}
79