UserGroup   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 26
c 2
b 0
f 0
dl 0
loc 79
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createEntity() 0 3 1
A __construct() 0 23 1
A addCustomAssets() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Domain\Entities\UserGroup as Entity;
8
use AbterPhp\Admin\Form\Factory\UserGroup as FormFactory;
9
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
10
use AbterPhp\Admin\Orm\UserGroupRepo as Repo;
11
use AbterPhp\Framework\Assets\AssetManager;
12
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
13
use AbterPhp\Framework\I18n\ITranslator;
14
use AbterPhp\Framework\Session\FlashService;
15
use League\Flysystem\FilesystemException;
16
use Opulence\Events\Dispatchers\IEventDispatcher;
17
use Opulence\Routing\Urls\UrlGenerator;
18
use Opulence\Sessions\ISession;
19
use Psr\Log\LoggerInterface;
20
21
class UserGroup extends FormAbstract
22
{
23
    public const ENTITY_PLURAL   = 'userGroups';
24
    public const ENTITY_SINGULAR = 'userGroup';
25
26
    public const ENTITY_TITLE_SINGULAR = 'admin:userGroup';
27
    public const ENTITY_TITLE_PLURAL   = 'admin:userGroups';
28
29
    public const ROUTING_PATH = 'user-groups';
30
31
    protected AssetManager $assetManager;
32
33
    protected string $resource = 'user_groups';
34
35
    /**
36
     * UserGroup constructor.
37
     *
38
     * @param FlashService     $flashService
39
     * @param LoggerInterface  $logger
40
     * @param ITranslator      $translator
41
     * @param UrlGenerator     $urlGenerator
42
     * @param Repo             $repo
43
     * @param ISession         $session
44
     * @param FormFactory      $formFactory
45
     * @param IEventDispatcher $eventDispatcher
46
     * @param AssetManager     $assetManager
47
     */
48
    public function __construct(
49
        FlashService $flashService,
50
        LoggerInterface $logger,
51
        ITranslator $translator,
52
        UrlGenerator $urlGenerator,
53
        Repo $repo,
54
        ISession $session,
55
        FormFactory $formFactory,
56
        IEventDispatcher $eventDispatcher,
57
        AssetManager $assetManager
58
    ) {
59
        parent::__construct(
60
            $flashService,
61
            $logger,
62
            $translator,
63
            $urlGenerator,
64
            $repo,
65
            $session,
66
            $formFactory,
67
            $eventDispatcher
68
        );
69
70
        $this->assetManager = $assetManager;
71
    }
72
73
    /**
74
     * @param string $entityId
75
     *
76
     * @return Entity
77
     */
78
    protected function createEntity(string $entityId): IStringerEntity
79
    {
80
        return new Entity($entityId, '', '');
81
    }
82
83
    /**
84
     * @param IStringerEntity|null $entity
85
     *
86
     * @throws FilesystemException
87
     */
88
    protected function addCustomAssets(?IStringerEntity $entity = null)
89
    {
90
        parent::addCustomAssets($entity);
91
92
        if (!($entity instanceof Entity)) {
93
            return;
94
        }
95
96
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
97
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
98
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
99
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
100
    }
101
}
102