Passed
Push — master ( 42e951...6610ba )
by Peter
02:37
created

PageCategory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 9
dl 0
loc 23
rs 9.9332

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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