Passed
Push — develop ( 80559e...1e38ed )
by Brent
02:12
created

App::developmentServer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 11
loc 11
ccs 0
cts 5
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher;
4
5
use Pageon\Config;
6
use Stitcher\Application\DevelopmentServer;
7
use Stitcher\Application\ProductionServer;
8
use Stitcher\Exception\InvalidConfiguration;
9
use Symfony\Component\Config\FileLocator;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Definition;
12
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
13
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
14
15
class App
16
{
17
    /** @var ContainerBuilder */
18
    protected static $container;
19
20 1
    public static function init(string $basePath)
21
    {
22 1
        Config::init($basePath);
23
24 1
        self::$container = new ContainerBuilder();
25
26 1
        self::loadConfig();
27 1
        self::loadServices();
28 1
    }
29
30 1
    public static function get(string $id)
31
    {
32 1
        return self::$container->get($id);
33
    }
34
35 View Code Duplication
    public static function developmentServer(): DevelopmentServer
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        try {
38
            /** @var DevelopmentServer $server */
39
            $server = self::get(DevelopmentServer::class);
40
41
            return $server;
42
        } catch (ParameterNotFoundException $e) {
43
            throw InvalidConfiguration::missingParameter($e->getKey());
44
        }
45
    }
46
47 View Code Duplication
    public static function productionServer(): ProductionServer
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        try {
50
            /** @var ProductionServer $server */
51
            $server = self::get(ProductionServer::class);
52
53
            return $server;
54
        } catch (ParameterNotFoundException $e) {
55
            throw InvalidConfiguration::missingParameter($e->getKey());
56
        }
57
    }
58
59 1
    protected static function loadConfig()
60
    {
61 1
        foreach (Config::all() as $key => $value) {
62 1
            self::$container->setParameter($key, $value);
63
        }
64 1
    }
65
66 1
    protected static function loadServices()
67
    {
68 1
        $loader = new YamlFileLoader(self::$container, new FileLocator(__DIR__));
69 1
        $loader->load('services.yaml');
70
71
        /** @var Definition $definition */
72 1
        foreach (self::$container->getDefinitions() as $id => $definition) {
73 1
            self::$container->setAlias($definition->getClass(), $id);
74
        }
75 1
    }
76
}
77