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

AddSchema::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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