Passed
Push — master ( 380517...f13cd3 )
by Peter
09:19
created

FileCategory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 27
c 3
b 0
f 0
dl 0
loc 83
rs 10
wmc 4

3 Methods

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