GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 74761d...9c0a76 )
by Sam
08:32
created

BuildController::logBuildInfo()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 7
cts 10
cp 0.7
rs 9.7666
cc 4
nc 8
nop 1
crap 4.432
1
<?php
2
declare(strict_types=1);
3
4
namespace SamIT\Yii2\PhpFpm\controllers;
5
6
7
use SamIT\Yii2\PhpFpm\helpers\Docker;
8
use SamIT\Yii2\PhpFpm\Module;
9
use yii\base\InvalidConfigException;
10
use yii\console\Controller;
11
use yii\helpers\Console;
12
13
/**
14
 * Class BuildController
15
 * @package SamIT\Yii2\PhpFpm\controllers
16
 * @property Module $module
17
 */
18
class BuildController extends Controller
19
{
20
    public $defaultAction = 'build';
21
22
    /**
23
     * @var string The name of the created image
24
     * If not explicitly set will take its default from module config.
25
     */
26
    public $image;
27
28
    /**
29
     * @var string The tag of the created image
30
     * If not explicitly set will take its default from module config.
31
     */
32
    public $tag;
33
34
    /**
35
     * @var bool whether to push the image after a successful build.
36
     * If not explicitly set will take its default from module config.
37
     */
38
    public $push;
39
40
    public function init(): void
41
    {
42
        parent::init();
43
        $this->push = $this->module->push;
44
        $this->image = $this->module->image;
45
        $this->tag = $this->module->tag;
46
    }
47
48
    public function actionBuild(): void
49
    {
50
        if ($this->push && !isset($this->image)) {
51
            throw new InvalidConfigException("When using the push option, you must configure or provide image");
52
        }
53
54
        $params = [];
55
56
        if (isset($this->image)) {
57
            $params['t'] = "{$this->image}:{$this->tag}";
58
        }
59
60
        $context = $this->module->createBuildContext($this->tag);
61 3
62
        $docker = new Docker();
63 3
        $docker->build($context, "{$this->image}:{$this->tag}");
64 3
65 3
        if ($this->push) {
66 3
            $docker->push("{$this->image}:{$this->tag}");
67 3
        }
68
    }
69
70 2
    public function actionTestClient(): void
71
    {
72 2
        $this->stdout("It seems the console client works!\n", Console::FG_GREEN);
73 1
    }
74
75
76 1
    public function options($actionID)
77
    {
78
79 1
        $result = parent::options($actionID);
80 1
        switch ($actionID) {
81
            case 'build':
82 1
                $result[] = 'push';
83 1
                $result[] = 'image';
84 1
                $result[] = 'tag';
85 1
                break;
86 1
87 1
        }
88
        return $result;
89 1
    }
90 1
91
    public function optionAliases()
92
    {
93
        $result = parent::optionAliases();
94 1
        $result['p'] = 'push';
95
        $result['t'] = 'tag';
96 1
        $result['i'] = 'image';
97 1
        return $result;
98 1
    }
99 1
100
    public function stdout($string)
101
    {
102 1
        if ($this->isColorEnabled()) {
103
            $args = \func_get_args();
104
            \array_shift($args);
105 1
            $string = Console::ansiFormat($string, $args);
106
        }
107
108
        echo $string;
109
        return \strlen($string);
110
    }
111
112
113
}