JshrinkServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1854

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 3
cts 9
cp 0.3333
rs 9.4286
cc 2
eloc 8
nc 2
nop 1
crap 3.1854
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