| Total Complexity | 10 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class StackableResolver implements ResolverInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var ResolverInterface[] |
||
| 20 | */ |
||
| 21 | protected $resolvers; |
||
| 22 | |||
| 23 | 15 | public function __construct(array $resolvers = []) |
|
| 24 | { |
||
| 25 | 15 | $this->resolvers = $resolvers; |
|
| 26 | 15 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param ResourceRecord[] $question |
||
| 30 | * |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | 11 | public function getAnswer(array $question): array |
|
| 34 | { |
||
| 35 | 11 | foreach ($this->resolvers as $resolver) { |
|
| 36 | 11 | $answer = $resolver->getAnswer($question); |
|
| 37 | 11 | if (!empty($answer)) { |
|
| 38 | 9 | return $answer; |
|
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | 2 | return []; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Check if any of the resolvers supports recursion. |
||
| 47 | * |
||
| 48 | * @return bool true if any resolver supports recursion |
||
| 49 | */ |
||
| 50 | 7 | public function allowsRecursion(): bool |
|
| 51 | { |
||
| 52 | 7 | foreach ($this->resolvers as $resolver) { |
|
| 53 | 7 | if ($resolver->allowsRecursion()) { |
|
| 54 | return true; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | 7 | return false; |
|
| 59 | } |
||
| 60 | |||
| 61 | /* |
||
| 62 | * Check if any resolver knows about a domain |
||
| 63 | * |
||
| 64 | * @param string $domain the domain to check for |
||
| 65 | * @return boolean true if some resolver holds info about $domain |
||
| 66 | */ |
||
| 67 | 6 | public function isAuthority($domain): bool |
|
| 76 | } |
||
| 77 | } |
||
| 78 |