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

MediaServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 19.05%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 36
ccs 4
cts 21
cp 0.1905
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 7 2
A register() 0 23 3
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