Passed
Push — v2 ( 7b6778...2ad6b9 )
by Brent
05:06
created

App::loadServices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher;
4
5
use Pageon\Config;
6
use Pageon\Html\Image\FixedWidthScaler;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11
12
class App
13
{
14
    /** @var ContainerBuilder */
15
    protected static $container;
16
17 1
    public static function init(string $basePath)
18
    {
19 1
        Config::init($basePath);
20
21 1
        self::$container = new ContainerBuilder();
22
23 1
        self::loadConfig();
24 1
        self::loadServices();
25 1
    }
26
27 1
    public static function get(string $id)
28
    {
29 1
        return self::$container->get($id);
30
    }
31
32 1
    protected static function loadConfig()
33
    {
34 1
        foreach (Config::all() as $key => $value) {
35 1
            self::$container->setParameter($key, $value);
36
        }
37 1
    }
38
39 1
    protected static function loadServices()
40
    {
41 1
        $loader = new YamlFileLoader(self::$container, new FileLocator(__DIR__));
42 1
        $loader->load('services.yaml');
43
44
        /** @var Definition $definition */
45 1
        foreach (self::$container->getDefinitions() as $id => $definition) {
46 1
            self::$container->setAlias($definition->getClass(), $id);
47
        }
48 1
    }
49
}
50