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

App   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 35.48 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 22
loc 62
ccs 18
cts 28
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 1
A get() 0 4 1
A developmentServer() 11 11 2
A productionServer() 11 11 2
A loadConfig() 0 6 2
A loadServices() 0 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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