| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class ChainedFormatRetriever implements FormatRetrieverInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var FormatRetrieverInterface[] |
||
| 12 | */ |
||
| 13 | private $formatRetrievers; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param FormatRetrieverInterface[] |
||
| 17 | */ |
||
| 18 | public function __construct(array $formatRetrievers) |
||
| 19 | { |
||
| 20 | $this->formatRetrievers = $formatRetrievers; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $contentType |
||
| 25 | * @return string|null |
||
| 26 | */ |
||
| 27 | public function getFormat(string $contentType): ?string |
||
| 28 | { |
||
| 29 | foreach ($this->formatRetrievers as $formatRetriever) { |
||
| 30 | $res = $formatRetriever->getFormat($contentType); |
||
| 31 | if (!is_null($res)) { |
||
| 32 | return $res; |
||
| 33 | } |
||
| 34 | } |
||
| 35 | throw new NotAcceptableHttpException('"' . $contentType . '" is not accepted'); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $format |
||
| 40 | * @return string|null |
||
| 41 | */ |
||
| 42 | public function getContentType(string $format): ?string |
||
| 51 | } |
||
| 52 | } |
||
| 53 |