Completed
Push — master ( 8af693...a60473 )
by Enrico
03:36
created

AddSchema   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 38.46%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 13 3
1
<?php
2
3
namespace Resourceful\ResourcefulServiceProvider;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Doctrine\Common\Cache\Cache;
8
9
class AddSchema
10
{
11
    protected $schema;
12
    protected $template;
13
    protected $replacements;
14
15
    use \Resourceful\StoreHelpers\StoreHelpers;
16
17 2
    public function __construct($schema, $template, $replacements = array())
18
    {
19 2
        $this->schema = $schema;
20 2
        $this->template = $template;
21 2
        $this->replacements = $replacements;
22 2
    }
23
24
    public function __invoke(Request $request, Application $app)
25
    {
26
		$store = $this->getStoreForType('schema', $app);
27
			
28
        if ($app["debug"] && !$store->contains($this->schema)) {
29
            $store->save(
30
                $this->schema,
31
                json_decode($app["twig"]->render("$this->template.json.twig", $this->replacements))
32
            );
33
		}
34
35
        $app["json-schema.schema-store"]->add($this->schema, $store->fetch($this->schema));
36
    }
37
}
38