JshrinkServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
ccs 8
cts 14
cp 0.5714
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A boot() 0 13 2
1
<?php
2
3
namespace EmanueleMinotto\JshrinkServiceProvider;
4
5
use Salva\JshrinkBundle\Cache\CachedMinifier;
6
use Salva\JshrinkBundle\Twig\Extension\JshrinkExtension;
7
use Silex\Application;
8
use Silex\ServiceProviderInterface;
9
10
/**
11
 * A jshrink service provider for Silex 1.
12
 *
13
 * @author Emanuele Minotto <[email protected]>
14
 *
15
 * @link http://silex.sensiolabs.org/doc/providers.html#creating-a-provider
16
 */
17
class JshrinkServiceProvider implements ServiceProviderInterface
18
{
19
    /**
20
     * Registers services and parameters on the app.
21
     *
22
     * @param Application $app Silex application.
23
     */
24 3
    public function register(Application $app)
25
    {
26 3
        $app['jshrink.cache_dir'] = sys_get_temp_dir();
27 3
        $app['jshrink.enabled'] = true;
28 3
        $app['jshrink.flagged_comments'] = true;
29 3
    }
30
31
    /**
32
     * Bootstraps the services.
33
     *
34
     * @param Application $app Silex application.
35
     */
36 3
    public function boot(Application $app)
37
    {
38 3
        if (!isset($app['twig'])) {
39 3
            return;
40
        }
41
42
        $cache = new CachedMinifier($app['jshrink.cache_dir']);
43
        $extension = new JshrinkExtension($cache, [
44
            'flaggedComments' => $app['jshrink.flagged_comments'],
45
        ], $app['jshrink.enabled']);
46
47
        $app['twig']->addExtension($extension);
48
    }
49
}
50