Completed
Pull Request — master (#397)
by Kristof
03:59
created

Sapi3UserPermissionMatcher::itMatchesOffer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\Security;
4
5
use CultuurNet\UDB3\Role\ReadModel\Constraints\UserConstraintsReadRepositoryInterface;
6
use CultuurNet\UDB3\Role\ValueObjects\Permission;
7
use CultuurNet\UDB3\Search\SearchServiceInterface;
8
use ValueObjects\StringLiteral\StringLiteral;
9
10
class Sapi3UserPermissionMatcher implements UserPermissionMatcherInterface
11
{
12
    /**
13
     * @var UserConstraintsReadRepositoryInterface
14
     */
15
    private $userConstraintsReadRepository;
16
17
    /**
18
     * @var SearchQueryFactoryInterface
19
     */
20
    private $searchQueryFactory;
21
22
    /**
23
     * @var SearchServiceInterface
24
     */
25
    private $searchService;
26
27
    /**
28
     * ConstraintsOfferFilter constructor.
29
     * @param UserConstraintsReadRepositoryInterface $userConstraintsReadRepository
30
     * @param SearchQueryFactoryInterface $searchQueryFactory
31
     * @param SearchServiceInterface $searchService
32
     */
33
    public function __construct(
34
        UserConstraintsReadRepositoryInterface $userConstraintsReadRepository,
35
        SearchQueryFactoryInterface $searchQueryFactory,
36
        SearchServiceInterface $searchService
37
    ) {
38
        $this->userConstraintsReadRepository = $userConstraintsReadRepository;
39
        $this->searchQueryFactory = $searchQueryFactory;
40
        $this->searchService = $searchService;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function itMatchesOffer(
47
        StringLiteral $userId,
48
        Permission $permission,
49
        StringLiteral $offerId
50
    ) {
51
        $constraints = $this->userConstraintsReadRepository->getByUserAndPermission(
52
            $userId,
53
            $permission
54
        );
55
        if (count($constraints) < 1) {
56
            return false;
57
        }
58
59
        $query = $this->searchQueryFactory->createFromConstraints(
60
            $constraints,
61
            $offerId
62
        );
63
64
        $results = $this->searchService->search($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<CultuurNet\Search\Parameter\Query>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
66
        return ($results->getTotalItems()->toNative() === 1);
67
    }
68
}
69