Passed
Push — master ( 7ba2cb...1d30f9 )
by Peter
02:20
created

Profile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
rs 9.9332
c 0
b 0
f 0
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\Admin\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Constant\Routes;
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 Opulence\Events\Dispatchers\IEventDispatcher;
15
use Opulence\Routing\Urls\UrlGenerator;
16
use Opulence\Sessions\ISession;
17
18
class Profile extends User
19
{
20
    /**
21
     * User constructor.
22
     *
23
     * @param FlashService     $flashService
24
     * @param ITranslator      $translator
25
     * @param UrlGenerator     $urlGenerator
26
     * @param Repo             $repo
27
     * @param ISession         $session
28
     * @param FormFactory      $formFactory
29
     * @param AssetManager     $assetManager
30
     * @param IEventDispatcher $eventDispatcher
31
     * @param string           $frontendSalt
32
     */
33
    public function __construct(
34
        FlashService $flashService,
35
        ITranslator $translator,
36
        UrlGenerator $urlGenerator,
37
        Repo $repo,
38
        ISession $session,
39
        FormFactory $formFactory,
40
        IEventDispatcher $eventDispatcher,
41
        AssetManager $assetManager,
42
        string $frontendSalt
43
    ) {
44
        parent::__construct(
45
            $flashService,
46
            $translator,
47
            $urlGenerator,
48
            $repo,
49
            $session,
50
            $formFactory,
51
            $eventDispatcher,
52
            $assetManager,
53
            $frontendSalt
54
        );
55
    }
56
57
    public function profile()
58
    {
59
        $userId = $this->session->get(Session::USER_ID);
60
61
        $this->edit($userId);
0 ignored issues
show
Bug introduced by
It seems like $userId can also be of type null; however, parameter $entityId of AbterPhp\Framework\Http\...in\FormAbstract::edit() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $this->edit(/** @scrutinizer ignore-type */ $userId);
Loading history...
62
    }
63
64
    /**
65
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
66
     *
67
     * @param string $id
68
     *
69
     * @return string
70
     * @throws URLException
71
     */
72
    protected function getEditUrl(string $id): string
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    protected function getEditUrl(/** @scrutinizer ignore-unused */ string $id): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
        /** @var UrlGenerator $urlGenerator */
75
        $urlGenerator = $this->urlGenerator;
76
77
        $url = $urlGenerator->createFromName(Routes::ROUTE_PROFILE);
78
79
        return $url;
80
    }
81
}
82