Passed
Push — master ( b9f4fb...566a27 )
by Peter
02:31
created

ContactForm::__construct()   A

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 Opulence\Events\Dispatchers\IEventDispatcher;
16
use Opulence\Routing\Urls\UrlGenerator;
17
use Opulence\Sessions\ISession;
18
use Psr\Log\LoggerInterface;
19
20
class ContactForm extends FormAbstract
21
{
22
    const ENTITY_SINGULAR = 'contactForm';
23
    const ENTITY_PLURAL   = 'contactForms';
24
25
    const ENTITY_TITLE_SINGULAR = 'contact:contactForm';
26
    const ENTITY_TITLE_PLURAL   = 'contact:contactForms';
27
28
    const ROUTING_PATH = 'contact-forms';
29
30
    /** @var string */
31
    protected $resource = 'contactforms';
32
33
    /**
34
     * ContactForm constructor.
35
     *
36
     * @param FlashService     $flashService
37
     * @param ITranslator      $translator
38
     * @param UrlGenerator     $urlGenerator
39
     * @param LoggerInterface  $logger
40
     * @param Repo             $repo
41
     * @param ISession         $session
42
     * @param FormFactory      $formFactory
43
     * @param IEventDispatcher $eventDispatcher
44
     * @param AssetManager     $assetManager
45
     */
46
    public function __construct(
47
        FlashService $flashService,
48
        ITranslator $translator,
49
        UrlGenerator $urlGenerator,
50
        LoggerInterface $logger,
51
        Repo $repo,
52
        ISession $session,
53
        FormFactory $formFactory,
54
        IEventDispatcher $eventDispatcher,
55
        AssetManager $assetManager
56
    ) {
57
        parent::__construct(
58
            $flashService,
59
            $translator,
60
            $urlGenerator,
61
            $logger,
62
            $repo,
63
            $session,
64
            $formFactory,
65
            $eventDispatcher
66
        );
67
68
        $this->assetManager = $assetManager;
0 ignored issues
show
Bug Best Practice introduced by
The property assetManager does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
69
    }
70
71
    /**
72
     * @param string $entityId
73
     *
74
     * @return Entity
75
     */
76
    protected function createEntity(string $entityId): IStringerEntity
77
    {
78
        return new Entity($entityId, '', '', '', '', '', '', 0);
79
    }
80
81
    /**
82
     * @param IStringerEntity|null $entity
83
     *
84
     * @throws \League\Flysystem\FileNotFoundException
85
     */
86
    protected function addCustomAssets(?IStringerEntity $entity = null)
87
    {
88
        parent::addCustomAssets($entity);
89
90
        if (!($entity instanceof Entity)) {
91
            return;
92
        }
93
94
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
95
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
96
    }
97
}
98