Passed
Push — main ( 79e4f1...ed1bb6 )
by Slawomir
04:28
created

SecurityApi::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
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 9
dl 0
loc 16
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 Psr\Log\LoggerInterface;
17
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
18
use Symfony\Component\Validator\Validator\ValidatorInterface;
19
20
class SecurityApi implements SecurityApiInterface
21
{
22
    use UserCreator {
23
        UserCreator::__construct as __userCreatorConstruct;
24
    }
25
26
    use UserUpdater {
27
        UserUpdater::__construct as __userUpdaterConstruct;
28
    }
29
30
    use JWTSecurityListener {
31
        JWTSecurityListener::__construct as __jwtTokenDecoratorConstruct;
32
    }
33
34
    /**
35
     * @param SecurityTransactionFactoryInterface $transactionFactory
36
     * @param UserPasswordHasherInterface $passwordHasher
37
     * @param UserCreationRepositoryInterface $creationRepository
38
     * @param LoggedInUserProviderInterface $databaseLoggedInUserProvider
39
     * @param UserUpdatingRepositoryInterface $updatingRepository
40
     * @param UserFindingRepositoryInterface $findingRepository
41
     * @param LoggerInterface $logger
42
     * @param ValidatorInterface $validator
43
     * @param ApplicationEventPublisherInterface $eventPublisher
44
     */
45
    public function __construct(
46
        SecurityTransactionFactoryInterface $transactionFactory,
47
        UserPasswordHasherInterface         $passwordHasher,
48
        UserCreationRepositoryInterface     $creationRepository,
49
        LoggedInUserProviderInterface       $databaseLoggedInUserProvider,
50
        UserUpdatingRepositoryInterface     $updatingRepository,
51
        UserFindingRepositoryInterface      $findingRepository,
52
        LoggerInterface                     $logger,
0 ignored issues
show
Unused Code introduced by
The parameter $logger 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

52
        /** @scrutinizer ignore-unused */ LoggerInterface                     $logger,

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...
53
        ValidatorInterface                  $validator,
54
        ApplicationEventPublisherInterface  $eventPublisher
55
    )
56
    {
57
        $securityValidator = new SecurityValidator($validator, $findingRepository);
58
        $this->__userUpdaterConstruct($eventPublisher, $transactionFactory, $updatingRepository, $securityValidator, $passwordHasher);
59
        $this->__userCreatorConstruct($passwordHasher, $transactionFactory, $creationRepository, $securityValidator);
60
        $this->__jwtTokenDecoratorConstruct($databaseLoggedInUserProvider);
61
    }
62
}