Completed
Push — feature/fga-allow-raa-swithing... ( e86059...a227dc )
by Michiel
20:33
created

RaListingService::createChoiceListFor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupRa\RaBundle\Service;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\StepupMiddlewareClient\Identity\Dto\RaListingSearchQuery;
23
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\RaListingService as MiddlewareClientBundleRaListingService;
24
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
25
26
class RaListingService
27
{
28
    /**
29
     * @var MiddlewareClientBundleRaListingService
30
     */
31
    private $raListingService;
32
33
    /**
34
     * @var LoggerInterface
35
     */
36
    private $logger;
37
38
    public function __construct(
39
        MiddlewareClientBundleRaListingService $raListingService,
40
        LoggerInterface $logger
41
    ) {
42
        $this->raListingService = $raListingService;
43
        $this->logger = $logger;
44
    }
45
46
    /**
47
     * @param $institution
48
     * @return ArrayChoiceList
49
     */
50
    public function createChoiceListFor($institution)
51
    {
52
        $query = new RaListingSearchQuery($institution, 1);
53
        $query->setIdentityId($institution->getIdentityInstitution());
54
55
        $collection = $this->raListingService->search($query);
56
57
        if ($collection->getTotalItems() === 0) {
58
            $this->logger->warning('No RAA institutions found for identity, unable to build the choice list for the RAA switcher');
59
            return new ArrayChoiceList();
0 ignored issues
show
Bug introduced by
The call to ArrayChoiceList::__construct() misses a required argument $choices.

This check looks for function calls that miss required arguments.

Loading history...
60
        }
61
62
        $choices = [];
63
        foreach ($collection as $item) {
64
            $choices[$item->institution] = $item->institution;
65
        }
66
67
        return new ArrayChoiceList($choices);
0 ignored issues
show
Documentation introduced by
$choices is of type array, but the function expects a object<Symfony\Component...rm\ChoiceList\iterable>.

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...
68
    }
69
}
70