Completed
Push — master ( b1c6ca...52cd2c )
by Kamil
77:57 queued 60:05
created

LazyCustomerLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadChoiceList() 0 4 1
A loadChoicesForValues() 0 4 1
A loadValuesForChoices() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\AdminApiBundle\Form\ChoiceList\Loader;
15
16
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
17
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
18
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
19
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
20
21
final class LazyCustomerLoader implements ChoiceLoaderInterface
22
{
23
    /** @var CustomerRepositoryInterface */
24
    private $customerRepository;
25
26
    public function __construct(CustomerRepositoryInterface $customerRepository)
27
    {
28
        $this->customerRepository = $customerRepository;
29
    }
30
31
    public function loadChoiceList($value = null): ChoiceListInterface
32
    {
33
        return new ArrayChoiceList([], $value);
0 ignored issues
show
Documentation introduced by
array() 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...
34
    }
35
36
    public function loadChoicesForValues(array $values, $value = null): array
37
    {
38
        return $this->customerRepository->findBy(['email' => $values]);
39
    }
40
41
    public function loadValuesForChoices(array $choices, $value = null): array
42
    {
43
        /** Intentionally left blank, as in the only usage of this loader is in the context of api, where we don't need to load choices */
44
        return [];
45
    }
46
}
47