ContactForm::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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

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\Contact\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
8
use AbterPhp\Contact\Domain\Entities\Form as Entity;
9
use AbterPhp\Contact\Form\Factory\Form as FormFactory;
10
use AbterPhp\Contact\Orm\FormRepo 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 ContactForm extends FormAbstract
22
{
23
    const ENTITY_SINGULAR = 'contactForm';
24
    const ENTITY_PLURAL   = 'contactForms';
25
26
    const ENTITY_TITLE_SINGULAR = 'contact:contactForm';
27
    const ENTITY_TITLE_PLURAL   = 'contact:contactForms';
28
29
    const ROUTING_PATH = 'contact-forms';
30
31
    /** @var AssetManager */
32
    protected $assetManager;
33
34
    /** @var string */
35
    protected $resource = 'contactforms';
36
37
    /**
38
     * ContactForm constructor.
39
     *
40
     * @param FlashService     $flashService
41
     * @param LoggerInterface  $logger
42
     * @param ITranslator      $translator
43
     * @param UrlGenerator     $urlGenerator
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
        LoggerInterface $logger,
53
        ITranslator $translator,
54
        UrlGenerator $urlGenerator,
55
        Repo $repo,
56
        ISession $session,
57
        FormFactory $formFactory,
58
        IEventDispatcher $eventDispatcher,
59
        AssetManager $assetManager
60
    ) {
61
        parent::__construct(
62
            $flashService,
63
            $logger,
64
            $translator,
65
            $urlGenerator,
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, '', '', '', '', '', '', 0);
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