Completed
Push — 1.5 ( c665c6...256abe )
by Kamil
12:34 queued 06:33
created

LazyCustomerLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
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);
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