Completed
Push — master ( 522f52...afb82c )
by Zlatin
02:06
created

MediaServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Media;
4
5
use Pimple\Container;
6
use Silex\Application;
7
use Pimple\ServiceProviderInterface;
8
use Silex\Api\BootableProviderInterface;
9
use Media\Exception\InvalidConfigurationException;
10
11
class MediaServiceProvider implements ServiceProviderInterface, BootableProviderInterface
12
{
13
14
    public function boot(Application $app)
15
    {
16
17
        if (!$app->offsetExists('upload.path')) {
18
            throw new InvalidConfigurationException;
19
        }
20
    }
21
22 2
    public function register(Container $app)
23
    {
24
25 2
        if ($app->offsetExists('form.factory')) {
26
            $app['form.types'] = $app->extend('form.types', function($types) use ($app) {
27
                $types[] = new Form\Type\MediaType($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...
28
                return $types;
29
            });
30
        }
31
32 2
        if ($app->offsetExists('twig')) {
33
            $app['twig'] = $app->extend('twig', function(\Twig_Environment $twig) use ($app) {
34
                $twig->addExtension(new Twig\MediaExtension($app));
35
                return $twig;
36
            });
37
38
            $app['twig.path'] = array_merge($app['twig.path'], array(
39
                __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'
40
            ));
41
42
            $app['twig.form.templates'] = array_merge($app['twig.form.templates'], array("media.type.html.twig"));
43
        }
44 2
    }
45
46
}
47