DescribedBy::__invoke()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 3
dl 0
loc 14
ccs 12
cts 12
cp 1
crap 5
rs 9.4888
c 0
b 0
f 0
1
<?php
2
3
namespace JDesrosiers\Silex\Provider;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
9
10
class DescribedBy
11
{
12 5
    public function __invoke(Request $request, Response $response, Application $app)
13
    {
14 5
        if ($app->offsetExists("json-schema.describedBy") && !$response->isEmpty()) {
15 3
            if ($app["json-schema.correlationMechanism"] === "profile") {
16 1
                $contentType = $response->headers->get("Content-Type");
17 1
                $response->headers->set("Content-Type", "$contentType; profile=\"{$app["json-schema.describedBy"]}\"");
18 3
            } elseif ($app["json-schema.correlationMechanism"] === "link") {
19 1
                $response->headers->set("Link", "<{$app["json-schema.describedBy"]}>; rel=\"describedby\"", false);
20 1
            } else {
21 1
                $errorMessage = "json-schema.correlationMechanism must be either \"profile\" or \"link\"";
22 1
                throw new ServiceUnavailableHttpException(null, $errorMessage);
23
            }
24 2
        }
25 4
    }
26
}
27