Container   B
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 17

Importance

Changes 8
Bugs 0 Features 4
Metric Value
wmc 16
c 8
b 0
f 4
lcom 1
cbo 17
dl 0
loc 127
rs 7.8571

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getTravisCiStrategy() 0 12 1
A getJoliCiStrategy() 0 4 1
A getChainStrategy() 0 8 1
A getStrategy() 0 4 1
A getConsoleLogger() 0 19 3
A getVacuum() 0 4 1
A getFilesystem() 0 4 1
A getDocker() 0 8 2
A getExecutor() 0 4 1
A getServiceManager() 0 4 1
A getBuildPath() 0 4 1
A getNaming() 0 4 1
A getLoggerCallback() 0 4 1
1
<?php
2
3
namespace Joli\JoliCi;
4
5
use Docker\Docker;
6
use Joli\JoliCi\BuildStrategy\ChainBuildStrategy;
7
use Joli\JoliCi\Filesystem\Filesystem;
8
use Joli\JoliCi\Log\SimpleFormatter;
9
use Joli\JoliCi\BuildStrategy\TravisCiBuildStrategy;
10
use Joli\JoliCi\BuildStrategy\JoliCiBuildStrategy;
11
use Joli\JoliCi\Builder\DockerfileBuilder;
12
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
13
use Monolog\Handler\FingersCrossedHandler;
14
use Monolog\Logger;
15
use Monolog\Handler\StreamHandler;
16
use TwigGenerator\Builder\Generator;
17
18
class Container
19
{
20
    private $docker;
21
22
    /**
23
     * Strategy based on the ".travis.yml" file
24
     *
25
     * @return TravisCiBuildStrategy
26
     */
27
    public function getTravisCiStrategy()
28
    {
29
        $builder   = new DockerfileBuilder();
30
        $generator = new Generator();
31
        $generator->setTemplateDirs(array(
32
            __DIR__."/../../../resources/templates",
33
        ));
34
        $generator->setMustOverwriteIfExists(true);
35
        $generator->addBuilder($builder);
36
37
        return new TravisCiBuildStrategy($builder, $this->getBuildPath(), $this->getNaming(), $this->getFilesystem());
38
    }
39
40
    /**
41
     * Strategy based on the ".jolici" folder
42
     *
43
     * @return JoliCiBuildStrategy
44
     */
45
    public function getJoliCiStrategy()
46
    {
47
        return new JoliCiBuildStrategy($this->getBuildPath(), $this->getNaming(), $this->getFilesystem());
48
    }
49
50
    /**
51
     * Chain strategy to allow multiples ones
52
     *
53
     * @return ChainBuildStrategy
54
     */
55
    public function getChainStrategy()
56
    {
57
        $strategy = new ChainBuildStrategy();
58
        $strategy->pushStrategy($this->getTravisCiStrategy());
59
        $strategy->pushStrategy($this->getJoliCiStrategy());
60
61
        return $strategy;
62
    }
63
64
    /**
65
     * Alias for the main strategy
66
     *
67
     * @return \Joli\JoliCi\BuildStrategy\BuildStrategyInterface
68
     */
69
    public function getStrategy()
70
    {
71
        return $this->getChainStrategy();
72
    }
73
74
    /**
75
     * Get a console with finger crossed handler
76
     *
77
     * @param bool $verbose
78
     *
79
     * @return Logger
80
     */
81
    public function getConsoleLogger($verbose = false)
82
    {
83
        $logger               = new Logger("standalone-logger");
84
        $handler              = new StreamHandler("php://stdout", $verbose ? Logger::DEBUG : Logger::INFO);
85
        $simpleFormatter      = new SimpleFormatter();
86
87
        $handler->setFormatter($simpleFormatter);
88
        $logger->pushHandler($handler);
89
90
        if (!$verbose) {
91
            $stdErrHandler = new StreamHandler("php://stderr", Logger::DEBUG);
92
            $fingerCrossedHandler = new FingersCrossedHandler($stdErrHandler, new ErrorLevelActivationStrategy(Logger::ERROR), 10);
0 ignored issues
show
Documentation introduced by
$stdErrHandler is of type object<Monolog\Handler\StreamHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
94
            $logger->pushHandler($fingerCrossedHandler);
95
            $stdErrHandler->setFormatter($simpleFormatter);
96
        }
97
98
        return $logger;
99
    }
100
101
    public function getVacuum()
102
    {
103
        return new Vacuum($this->getDocker(), $this->getNaming(), $this->getStrategy(), $this->getFilesystem(), $this->getBuildPath());
104
    }
105
106
    public function getFilesystem()
107
    {
108
        return new Filesystem();
109
    }
110
111
    public function getDocker()
112
    {
113
        if (!$this->docker) {
114
            $this->docker = new Docker();
115
        }
116
117
        return $this->docker;
118
    }
119
120
    public function getExecutor($cache = true, $verbose = false, $timeout = 600)
121
    {
122
        return new Executor($this->getLoggerCallback($verbose), $this->getDocker(), $this->getBuildPath(), $cache, false, $timeout);
123
    }
124
125
    public function getServiceManager($verbose = false)
126
    {
127
        return new ServiceManager($this->getDocker(), $this->getLoggerCallback($verbose));
128
    }
129
130
    public function getBuildPath()
131
    {
132
        return sys_get_temp_dir().DIRECTORY_SEPARATOR.".jolici-builds";
133
    }
134
135
    public function getNaming()
136
    {
137
        return new Naming();
138
    }
139
140
    public function getLoggerCallback($verbose)
141
    {
142
        return new LoggerCallback($this->getConsoleLogger($verbose));
143
    }
144
}
145