Profile::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

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\Admin\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Constant\Route;
8
use AbterPhp\Admin\Form\Factory\Profile as FormFactory;
9
use AbterPhp\Admin\Orm\UserRepo as Repo;
10
use AbterPhp\Framework\Assets\AssetManager;
11
use AbterPhp\Framework\Constant\Session;
12
use AbterPhp\Framework\I18n\ITranslator;
13
use AbterPhp\Framework\Session\FlashService;
14
use Casbin\Exceptions\CasbinException;
15
use Opulence\Events\Dispatchers\IEventDispatcher;
16
use Opulence\Routing\Urls\UrlException;
17
use Opulence\Routing\Urls\UrlGenerator;
18
use Opulence\Sessions\ISession;
19
use Psr\Log\LoggerInterface;
20
use Throwable;
21
22
/**
23
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
24
 */
25
class Profile extends User
26
{
27
    /**
28
     * Profile constructor.
29
     *
30
     * @param FlashService     $flashService
31
     * @param LoggerInterface  $logger
32
     * @param ITranslator      $translator
33
     * @param UrlGenerator     $urlGenerator
34
     * @param Repo             $repo
35
     * @param ISession         $session
36
     * @param FormFactory      $formFactory
37
     * @param IEventDispatcher $eventDispatcher
38
     * @param AssetManager     $assetManager
39
     * @param string           $frontendSalt
40
     */
41
    public function __construct(
42
        FlashService $flashService,
43
        LoggerInterface $logger,
44
        ITranslator $translator,
45
        UrlGenerator $urlGenerator,
46
        Repo $repo,
47
        ISession $session,
48
        FormFactory $formFactory,
49
        IEventDispatcher $eventDispatcher,
50
        AssetManager $assetManager,
51
        string $frontendSalt
52
    ) {
53
        parent::__construct(
54
            $flashService,
55
            $logger,
56
            $translator,
57
            $urlGenerator,
58
            $repo,
59
            $session,
60
            $formFactory,
61
            $eventDispatcher,
62
            $assetManager,
63
            $frontendSalt
64
        );
65
    }
66
67
    /**
68
     * @throws Throwable
69
     * @throws CasbinException
70
     * @throws URLException
71
     */
72
    public function profile()
73
    {
74
        $userId = (string)$this->session->get(Session::USER_ID);
75
76
        $this->edit($userId);
77
    }
78
79
    /**
80
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
81
     *
82
     * @param string $id
83
     *
84
     * @return string
85
     * @throws \Opulence\Routing\Urls\URLException
86
     */
87
    protected function getEditUrl(string $id): string
88
    {
89
        $urlGenerator = $this->urlGenerator;
90
91
        $url = $urlGenerator->createFromName(Route::PROFILE_EDIT);
92
93
        return $url;
94
    }
95
}
96