DescribedBySchemaHandler::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
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