Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ChainedDropdownOptionProvider
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supports
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getList
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\CmsApiDropdownOption\DropdownOptionProvider;
3
4use Apie\CmsApiDropdownOption\Lists\DropdownOptionList;
5use Apie\Core\Context\ApieContext;
6
7final class ChainedDropdownOptionProvider implements DropdownOptionProviderInterface
8{
9    /**
10     * @var array<int, DropdownOptionProviderInterface> $providers
11     */
12    private array $providers;
13
14    public function __construct(DropdownOptionProviderInterface... $providers)
15    {
16        $this->providers = $providers;
17    }
18
19    /**
20     * @param iterable<int, DropdownOptionProviderInterface> $providers
21     */
22    public static function create(iterable $providers): self
23    {
24        return new self(...$providers);
25    }
26
27    public function supports(ApieContext $apieContext): bool
28    {
29        foreach ($this->providers as $provider) {
30            if ($provider->supports($apieContext)) {
31                return true;
32            }
33        }
34
35        return false;
36    }
37
38    public function getList(ApieContext $apieContext, string $searchTerm): DropdownOptionList
39    {
40        foreach ($this->providers as $provider) {
41            if ($provider->supports($apieContext)) {
42                return $provider->getList($apieContext, $searchTerm);
43            }
44        }
45
46        return new DropdownOptionList();
47    }
48}