Completed
Push — master ( 33476c...427ebd )
by Bertrand
09:14
created

InteractionsQueryByPageAndUser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 1
A __construct() 0 7 1
A getInteractUser() 0 7 2
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Agricultural\Queries;
5
6
7
use App\Src\UseCases\Domain\Agricultural\Model\AnonymousUser;
8
use App\Src\UseCases\Domain\Agricultural\Model\CanInteract;
9
use App\Src\UseCases\Domain\Agricultural\Model\Interaction;
10
use App\Src\UseCases\Domain\Agricultural\Model\RegisteredUser;
11
use App\Src\UseCases\Domain\Ports\InteractionRepository;
12
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway;
13
14
class InteractionsQueryByPageAndUser
15
{
16
    private $interactionRepository;
17
    private $authGateway;
18
19
    public function __construct(
20
        InteractionRepository $interactionRepository,
21
        AuthGateway $authGateway
22
    )
23
    {
24
        $this->interactionRepository = $interactionRepository;
25
        $this->authGateway = $authGateway;
26
    }
27
28
    public function execute(int $pageId):?Interaction
29
    {
30
        $canInteractUser = $this->getInteractUser();
31
        return $this->interactionRepository->getByInteractUser($canInteractUser, $pageId);
32
    }
33
34
    private function getInteractUser():CanInteract
35
    {
36
        $currentUser = $this->authGateway->current();
37
        if (isset($currentUser)) {
38
            return new RegisteredUser($currentUser->id());
39
        }
40
        return new AnonymousUser($this->authGateway->wikiSessionId());
0 ignored issues
show
Bug introduced by
It seems like $this->authGateway->wikiSessionId() can also be of type null; however, parameter $identifier of App\Src\UseCases\Domain\...mousUser::__construct() 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

40
        return new AnonymousUser(/** @scrutinizer ignore-type */ $this->authGateway->wikiSessionId());
Loading history...
41
    }
42
}
43