| Conditions | 5 |
| Paths | 5 |
| Total Lines | 32 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 5.0042 |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | 17 | protected function processMime(string $mime): MimeProcessResult |
|
| 12 | { |
||
| 13 | 17 | $vendor = (string)$this->getContainer()->get(Application::CONTAINER_ID_VENDOR); |
|
| 14 | 17 | $apiVersion = (string)$this->getContainer()->get(Application::CONTAINER_ID_API_VERSION); |
|
| 15 | 17 | $apiVersionRegExp = Application::API_VERSION_REG_EXP; |
|
| 16 | 17 | $format = null; |
|
| 17 | |||
| 18 | if ( |
||
| 19 | 17 | preg_match( |
|
| 20 | 17 | '#application/vnd\.' . $vendor . '-v' . $apiVersionRegExp . '\+(xml|json)#', |
|
| 21 | $mime, |
||
| 22 | $matches |
||
| 23 | ) |
||
| 24 | ) { |
||
| 25 | 1 | [$mime, $apiVersion, $format] = $matches; |
|
| 26 | } elseif ( |
||
| 27 | preg_match( |
||
| 28 | 16 | '#application/vnd\.' . $vendor . '\+(xml|json).*?version=' . $apiVersionRegExp . '#', |
|
| 29 | $mime, |
||
| 30 | $matches |
||
| 31 | ) |
||
| 32 | ) { |
||
| 33 | 1 | [$mime, $format, $apiVersion] = $matches; |
|
| 34 | 15 | } elseif ('application/json' === $mime) { |
|
| 35 | 3 | $format = 'json'; |
|
| 36 | 3 | $mime = 'application/vnd.' . $vendor . '-v' . $apiVersion . '+json'; |
|
| 37 | 12 | } elseif ('application/xml' === $mime) { |
|
| 38 | 2 | $format = 'xml'; |
|
| 39 | 2 | $mime = 'application/vnd.' . $vendor . '-v' . $apiVersion . '+xml'; |
|
| 40 | } |
||
| 41 | |||
| 42 | 17 | return new MimeProcessResult($mime, $vendor, $apiVersion, $format); |
|
| 43 | } |
||
| 47 |