Passed
Push — master ( 6af672...0107a4 )
by Peter
07:37
created

BlockLayout::__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\BlockLayout as Entity;
13
use AbterPhp\Website\Form\Factory\BlockLayout as FormFactory;
14
use AbterPhp\Website\Orm\BlockLayoutRepo as Repo;
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 BlockLayout extends FormAbstract
22
{
23
    const ENTITY_PLURAL   = 'blockLayouts';
24
    const ENTITY_SINGULAR = 'blockLayout';
25
26
    const ENTITY_TITLE_SINGULAR = 'website:blockLayout';
27
    const ENTITY_TITLE_PLURAL   = 'website:blockLayouts';
28
29
    const ROUTING_PATH = 'block-layouts';
30
31
    /** @var AssetManager */
32
    protected $assetManager;
33
34
    /** @var string */
35
    protected $resource = 'block_layouts';
36
37
    /**
38
     * BlockLayout 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
    protected function createEntity(string $entityId): IStringerEntity
81
    {
82
        return new Entity($entityId, '', '', '');
83
    }
84
85
    /**
86
     * @param IStringerEntity|null $entity
87
     *
88
     * @throws FilesystemException
89
     */
90
    protected function addCustomAssets(?IStringerEntity $entity = null)
91
    {
92
        parent::addCustomAssets($entity);
93
94
        if (!($entity instanceof Entity)) {
95
            return;
96
        }
97
98
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
99
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
100
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
101
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
102
    }
103
}
104