SecurityApi::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 15
ccs 0
cts 0
cp 0
crap 2
rs 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
namespace App\Modules\Security\Domain;
4
5
use App\Infrastructure\Events\Api\ApplicationEventPublisherInterface;
6
use App\Infrastructure\Security\LoggedInUserProviderInterface;
7
use App\Modules\Security\Api\SecurityApiInterface;
8
use App\Modules\Security\Domain\Logic\JWTSecurityListener;
9
use App\Modules\Security\Domain\Logic\SecurityValidator;
10
use App\Modules\Security\Domain\Logic\UserCreator;
11
use App\Modules\Security\Domain\Logic\UserUpdater;
12
use App\Modules\Security\Domain\Repository\UserCreationRepositoryInterface;
13
use App\Modules\Security\Domain\Repository\UserFindingRepositoryInterface;
14
use App\Modules\Security\Domain\Repository\UserUpdatingRepositoryInterface;
15
use App\Modules\Security\Domain\Transactions\SecurityTransactionFactoryInterface;
16
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
17
use Symfony\Component\Validator\Validator\ValidatorInterface;
18
19
class SecurityApi implements SecurityApiInterface
20
{
21
    use UserCreator {
22
        UserCreator::__construct as __userCreatorConstruct;
23
    }
24
25
    use UserUpdater {
26
        UserUpdater::__construct as __userUpdaterConstruct;
27
    }
28
29
    use JWTSecurityListener {
30
        JWTSecurityListener::__construct as __jwtTokenDecoratorConstruct;
31
    }
32
33
    /**
34
     * @param SecurityTransactionFactoryInterface $transactionFactory
35
     * @param UserPasswordHasherInterface $passwordHasher
36
     * @param UserCreationRepositoryInterface $creationRepository
37
     * @param LoggedInUserProviderInterface $databaseLoggedInUserProvider
38
     * @param UserUpdatingRepositoryInterface $updatingRepository
39
     * @param UserFindingRepositoryInterface $findingRepository
40
     * @param ValidatorInterface $validator
41
     * @param ApplicationEventPublisherInterface $eventPublisher
42
     */
43
    public function __construct(
44
        SecurityTransactionFactoryInterface $transactionFactory,
45
        UserPasswordHasherInterface         $passwordHasher,
46
        UserCreationRepositoryInterface     $creationRepository,
47
        LoggedInUserProviderInterface       $databaseLoggedInUserProvider,
48
        UserUpdatingRepositoryInterface     $updatingRepository,
49
        UserFindingRepositoryInterface      $findingRepository,
50
        ValidatorInterface                  $validator,
51
        ApplicationEventPublisherInterface  $eventPublisher
52
    )
53
    {
54
        $securityValidator = new SecurityValidator($validator, $findingRepository);
55
        $this->__userUpdaterConstruct($eventPublisher, $transactionFactory, $updatingRepository, $securityValidator, $passwordHasher);
56
        $this->__userCreatorConstruct($passwordHasher, $transactionFactory, $creationRepository, $securityValidator);
57
        $this->__jwtTokenDecoratorConstruct($databaseLoggedInUserProvider);
58
    }
59
}