CompositeDataProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 18
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A provide() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\State;
6
7
use LAG\AdminBundle\Exception\Exception;
8
use LAG\AdminBundle\Metadata\OperationInterface;
9
10
class CompositeDataProvider implements DataProviderInterface
11
{
12
    public function __construct(
13
        /** @var DataProviderInterface[] $providers */
14
        private iterable $providers = [],
15
    ) {
16
    }
17
18
    public function provide(OperationInterface $operation, array $uriVariables = [], array $context = []): mixed
19
    {
20
        /** @var DataProviderInterface $provider */
21
        foreach ($this->providers as $provider) {
22
            if ($provider::class === $operation->getProvider()) {
23
                return $provider->provide($operation, $uriVariables, $context);
24
            }
25
        }
26
27
        throw new Exception(sprintf('The admin resource "%s" and operation "%s" is not supported by any provider', $operation->getResource()->getName(), $operation->getName()));
28
    }
29
}
30