Test Setup Failed
Push — main ( abdcb9...2e5f68 )
by Slawomir
04:37
created

SecurityApi::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 12
dl 0
loc 23
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\Events\Api\ApplicationEventSubscriber;
7
use App\Infrastructure\Events\Api\EventHandlerReference;
8
use App\Infrastructure\Security\LoggedInUserProviderInterface;
9
use App\Modules\Security\Api\Event\Inbound\CommentsCountUpdatedSecurityIEvent;
10
use App\Modules\Security\Api\Event\Inbound\PostCreatedSecurityIEvent;
11
use App\Modules\Security\Api\Event\Inbound\PostDeletedSecurityIEvent;
12
use App\Modules\Security\Api\Event\Inbound\PostUpdatedSecurityIEvent;
13
use App\Modules\Security\Api\SecurityApiInterface;
14
use App\Modules\Security\Domain\Logic\CommentsEventsHandler;
15
use App\Modules\Security\Domain\Logic\JWTSecurityListener;
16
use App\Modules\Security\Domain\Logic\PostHeadersFinder;
17
use App\Modules\Security\Domain\Logic\PostsEventsHandler;
18
use App\Modules\Security\Domain\Logic\SecurityValidator;
19
use App\Modules\Security\Domain\Logic\UserCreator;
20
use App\Modules\Security\Domain\Logic\UserUpdater;
21
use App\Modules\Security\Domain\Repository\SecurityCommentsEventHandlingRepositoryInterface;
22
use App\Modules\Security\Domain\Repository\SecurityPostEventsHandlingRepositoryInterface;
23
use App\Modules\Security\Domain\Repository\UserCreationRepositoryInterface;
24
use App\Modules\Security\Domain\Repository\UserFindingRepositoryInterface;
25
use App\Modules\Security\Domain\Repository\UserPostHeadersFindingRepositoryInterface;
26
use App\Modules\Security\Domain\Repository\UserUpdatingRepositoryInterface;
27
use App\Modules\Security\Domain\Transactions\SecurityTransactionFactoryInterface;
28
use Psr\Log\LoggerInterface;
29
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
30
use Symfony\Component\Validator\Validator\ValidatorInterface;
31
32
class SecurityApi extends ApplicationEventSubscriber implements SecurityApiInterface
33
{
34
    use UserCreator {
35
        UserCreator::__construct as __userCreatorConstruct;
36
    }
37
38
    use UserUpdater {
39
        UserUpdater::__construct as __userUpdaterConstruct;
40
    }
41
42
    use JWTSecurityListener {
1 ignored issue
show
Bug introduced by
The trait App\Modules\Security\Dom...gic\JWTSecurityListener requires the property $headers which is not provided by App\Modules\Security\Domain\SecurityApi.
Loading history...
43
        JWTSecurityListener::__construct as __jwtTokenDecoratorConstruct;
44
    }
45
46
    use PostsEventsHandler {
47
        PostsEventsHandler::__construct as __postEventsHandlerConstruct;
48
    }
49
50
    use CommentsEventsHandler {
51
        CommentsEventsHandler::__construct as __commentsEventsHandlerConstruct;
52
    }
53
54
    use PostHeadersFinder {
55
        PostHeadersFinder::__construct as __postHeadersFinderConstruct;
56
    }
57
58
59
    /**
60
     * @param SecurityTransactionFactoryInterface $transactionFactory
61
     * @param UserPasswordHasherInterface $passwordHasher
62
     * @param UserCreationRepositoryInterface $creationRepository
63
     * @param LoggedInUserProviderInterface $databaseLoggedInUserProvider
64
     * @param SecurityPostEventsHandlingRepositoryInterface $postEventsSecurityRepository
65
     * @param UserPostHeadersFindingRepositoryInterface $headersFindingRepository
66
     * @param SecurityCommentsEventHandlingRepositoryInterface $commentsEventHandlingRepository
67
     * @param LoggerInterface $logger
68
     */
69
    public function __construct(
70
        SecurityTransactionFactoryInterface              $transactionFactory,
71
        UserPasswordHasherInterface                      $passwordHasher,
72
        UserCreationRepositoryInterface                  $creationRepository,
73
        LoggedInUserProviderInterface                    $databaseLoggedInUserProvider,
74
        SecurityPostEventsHandlingRepositoryInterface    $postEventsSecurityRepository,
75
        UserPostHeadersFindingRepositoryInterface        $headersFindingRepository,
76
        SecurityCommentsEventHandlingRepositoryInterface $commentsEventHandlingRepository,
77
        UserUpdatingRepositoryInterface                  $updatingRepository,
78
        UserFindingRepositoryInterface                   $findingRepository,
79
        LoggerInterface                                  $logger,
80
        ValidatorInterface                               $validator,
81
        ApplicationEventPublisherInterface               $eventPublisher
82
    )
83
    {
84
        parent::__construct($logger);
2 ignored issues
show
Bug introduced by
The call to App\Modules\Security\Dom...rCreator::__construct() has too few arguments starting with transactionFactory. ( Ignorable by Annotation )

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

84
        parent::/** @scrutinizer ignore-call */ 
85
                __construct($logger);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
$logger of type Psr\Log\LoggerInterface is incompatible with the type Symfony\Component\Passwo...PasswordHasherInterface expected by parameter $passwordHasher of App\Modules\Security\Dom...rCreator::__construct(). ( Ignorable by Annotation )

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

84
        parent::__construct(/** @scrutinizer ignore-type */ $logger);
Loading history...
85
        $securityValidator = new SecurityValidator($validator, $findingRepository);
86
        $this->__userUpdaterConstruct($eventPublisher, $transactionFactory, $updatingRepository, $securityValidator, $passwordHasher);
87
        $this->__userCreatorConstruct($passwordHasher, $transactionFactory, $creationRepository, $securityValidator);
88
        $this->__jwtTokenDecoratorConstruct($databaseLoggedInUserProvider);
89
        $this->__postEventsHandlerConstruct($transactionFactory, $postEventsSecurityRepository);
90
        $this->__postHeadersFinderConstruct($headersFindingRepository);
91
        $this->__commentsEventsHandlerConstruct($transactionFactory, $commentsEventHandlingRepository);
92
    }
93
94
    /**
95
     * @return array<string, EventHandlerReference>
96
     */
97
    protected function subscribe(): array
98
    {
99
        return [
100
            PostCreatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostCreated', PostCreatedSecurityIEvent::class),
101
            PostUpdatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostUpdated', PostUpdatedSecurityIEvent::class),
102
            PostDeletedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostDeleted', PostDeletedSecurityIEvent::class),
103
            CommentsCountUpdatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onCommentsCountUpdated', CommentsCountUpdatedSecurityIEvent::class),
104
        ];
105
    }
106
}