DescribedBy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 5
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