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

ResourcefulServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 30%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 29
ccs 3
cts 10
cp 0.3
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 1
A register() 0 9 1
1
<?php
2
3
namespace Resourceful\ResourcefulServiceProvider;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use Silex\Api\BootableProviderInterface;
8
use Silex\Application;
9
use Twig_Loader_Filesystem;
10
11
class ResourcefulServiceProvider implements ServiceProviderInterface, BootableProviderInterface
12
{
13
    const ERROR_HANDLER_PRIORITY = 0;
14
15
    public function boot(Application $app)
16
    {
17
    	assert( isset($app["twig.loader"]));
18
		
19
        // Error Handling
20
        $schema = $app["url_generator"]->generate("schema", array("id" => "error"));
21
22
        $app["twig.loader"]->addLoader(new Twig_Loader_Filesystem(__DIR__ . "/templates"));
23
        $app->before(new AddSchema($schema, "error"));
24
25
        $app->error(function (\Exception $e, $code) use ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $e is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
            $app["json-schema.describedBy"] = $app["url_generator"]->generate("schema", array("id" => "error"));
27
        }, self::ERROR_HANDLER_PRIORITY);
28
    }
29
30 4
    public function register(Container $app)
31
    {
32 4
        $app["resources_factory"] = $app->protect(new ResourcesFactory($app));
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Silex\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
33
34
        // CreateResourceController
35
        $app["uniqid"] = function () {
36
            return uniqid();
37
        };
38 4
    }
39
}
40