Completed
Push — master ( 7d4a72...efe314 )
by Jason
04:42
created

DescribedBy::__invoke()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 12
cts 12
cp 1
rs 8.8571
cc 5
eloc 10
nc 4
nop 3
crap 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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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