DescribedBySchemaHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchemaId() 0 1 1
A apply() 0 5 1
A __construct() 0 4 1
A __invoke() 0 9 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