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 ( bc04e9...08115b )
by Sam
02:47
created

BuildController::options()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace SamIT\Yii2\PhpFpm\controllers;
5
6
7
use Docker\API\Model\BuildInfo;
8
use Docker\Context\Context;
9
use Docker\Context\ContextBuilder;
10
use Docker\Context\ContextInterface;
11
use Docker\Docker;
12
use Docker\Stream\BuildStream;
13
use SamIT\Yii2\PhpFpm\Module;
14
use yii\console\Controller;
15
16
/**
17
 * Class BuildController
18
 * @package SamIT\Yii2\PhpFpm\controllers
19
 * @property Module $module
20
 */
21
class BuildController extends Controller
22
{
23
    public $defaultAction = 'build';
24
25
    /**
26
     * @var string The name of the created image
27
     * If not explicitly set will take its default from module config.
28
     */
29
    public $image;
30
31
    /**
32
     * @var string The tag of the created image
33
     * If not explicitly set will take its default from module config.
34
     */
35
    public $tag;
36
37
    /**
38
     * @var bool whether to push the image after a successful build.
39
     * If not explicitly set will take its default from module config.
40
     */
41
    public $push;
42
43
    public function init(): void
44
    {
45
        parent::init();
46
        $this->push = $this->module->push;
47
        $this->image = $this->module->image;
48
        $this->tag = $this->module->tag;
49
    }
50
51
    public function actionBuild(): void
52
    {
53
54
55
        $params = [];
56
        if (isset($this->image)) {
57
            $params['t'] = "{$this->image}:{$this->tag}";
58
        }
59
        $buildStream = $this->createBuildStream($params);
60
61
        $buildStream->onFrame(function(BuildInfo $buildInfo): void {
62
            echo $buildInfo->getStream();
63
        });
64
65
        $buildStream->wait();
66
        echo "Wait finished\n";
67
        $buildStream->wait();
68
    }
69
70
    public function createBuildStream(array $params = []): BuildStream
71
    {
72
        $docker = Docker::create();
73
        $context = $this->module->createBuildContext();
74
75
        /** @var BuildStream $buildStream */
76
        $buildStream = $docker->imageBuild($context->toStream(), $params, Docker::FETCH_STREAM);
1 ignored issue
show
Documentation introduced by
$context->toStream() is of type resource, but the function expects a string.

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...
77
        return $buildStream;
78
    }
79
80
    public function options($actionID)
81
    {
82
83
        $result = parent::options($actionID);
84
        switch ($actionID) {
85
            case 'build':
86
//                $result[] = 'push';
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
87
                $result[] = 'image';
88
                $result[] = 'tag';
89
                break;
90
91
        }
92
        return $result;
93
    }
94
95
    public function optionAliases()
96
    {
97
        $result = parent::optionAliases();
98
//        $result['p'] = 'push';
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
99
        $result['t'] = 'tag';
100
        $result['i'] = 'image';
101
        return $result;
102
    }
103
104
105
}