DescribedBySchemaHandler::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Resourceful;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class DescribedBySchemaHandler
10
{
11
    private $schemaId;
12
	
13
	public function getSchemaId(){ return $this->schemaId;}
14
	
15 1
	public static function apply($schemaId, Application $app, Response $response)
16
	{
17 1
		$handler =new static($schemaId);
18 1
		return $handler(new Request,$response,$app);
19
	}
20
	
21 13
	public function __construct($schemaId=null)
22
    {
23 13
        $this->schemaId = $schemaId;
24 13
    }
25
		
26 3
    public function __invoke(Request $request, Response $response, Application $app)
27
    {
28 3
        if ($response->isSuccessful()) {
29 3
        	$schema= $this->schemaId?SchemaHandler::getSchemaUrl($this->schemaId, $app):'http://json-schema.org/hyper-schema';
30 3
        	$response->headers->set("Content-Type", "application/json; profile=\"$schema\"");
31
        }
32
33 3
		return $response;
34
    }
35
}
36