Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#3813)
by Cristian
29:01 queued 14:01
created

PrettyCommandOutput::box()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Console\Commands\Traits;
4
5
use Artisan;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Process\Exception\ProcessFailedException;
8
use Symfony\Component\Process\Process;
9
10
trait PrettyCommandOutput
11
{
12
    /**
13
     * Run a SSH command.
14
     *
15
     * @param  string  $command  The SSH command that needs to be run
16
     * @param  bool  $beforeNotice  Information for the user before the command is run
17
     * @param  bool  $afterNotice  Information for the user after the command is run
18
     * @return mixed Command-line output
19
     */
20
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
21
    {
22
        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : implode(' ', $command));
0 ignored issues
show
Bug introduced by
$command of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : implode(' ', /** @scrutinizer ignore-type */ $command));
Loading history...
Bug introduced by
Are you sure $beforeNotice of type true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        $this->echo('info', $beforeNotice ? ' './** @scrutinizer ignore-type */ $beforeNotice : implode(' ', $command));
Loading history...
23
24
        // make sure the command is an array as per Symphony 4.3+ requirement
25
        $command = is_string($command) ? explode(' ', $command) : $command;
0 ignored issues
show
introduced by
The condition is_string($command) is always true.
Loading history...
26
27
        $process = new Process($command, null, null, null, $this->option('timeout'));
0 ignored issues
show
Bug introduced by
It seems like option() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $process = new Process($command, null, null, null, $this->/** @scrutinizer ignore-call */ option('timeout'));
Loading history...
28
        $process->run(function ($type, $buffer) {
29
            if (Process::ERR === $type) {
30
                $this->echo('comment', $buffer);
31
            } else {
32
                $this->echo('line', $buffer);
33
            }
34
        });
35
36
        // executes after the command finishes
37
        if (! $process->isSuccessful()) {
38
            throw new ProcessFailedException($process);
39
        }
40
41
        if ($this->progressBar) {
42
            $this->progressBar->advance();
43
        }
44
45
        if ($afterNotice) {
46
            $this->echo('info', $afterNotice);
0 ignored issues
show
Bug introduced by
$afterNotice of type true is incompatible with the type string expected by parameter $content of Backpack\CRUD\app\Consol...tyCommandOutput::echo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            $this->echo('info', /** @scrutinizer ignore-type */ $afterNotice);
Loading history...
47
        }
48
    }
49
50
    /**
51
     * Run an artisan command.
52
     *
53
     * @param  string  $command  The artisan command to be run.
54
     * @param  array  $arguments  Key-value array of arguments to the artisan command.
55
     * @param  bool  $beforeNotice  Information for the user before the command is run
56
     * @param  bool  $afterNotice  Information for the user after the command is run
57
     * @return mixed Command-line output
58
     */
59
    public function executeArtisanProcess($command, $arguments = [], $beforeNotice = false, $afterNotice = false)
60
    {
61
        $beforeNotice = $beforeNotice ? ' '.$beforeNotice : 'php artisan '.implode(' ', (array) $command).' '.implode(' ', $arguments);
0 ignored issues
show
Bug introduced by
Are you sure $beforeNotice of type true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $beforeNotice = $beforeNotice ? ' './** @scrutinizer ignore-type */ $beforeNotice : 'php artisan '.implode(' ', (array) $command).' '.implode(' ', $arguments);
Loading history...
62
63
        $this->echo('info', $beforeNotice);
64
65
        try {
66
            Artisan::call($command, $arguments);
67
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type Backpack\CRUD\app\Consol...mmands\Traits\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
68
            throw new ProcessFailedException($e);
69
        }
70
71
        if ($this->progressBar) {
72
            $this->progressBar->advance();
73
        }
74
75
        if ($afterNotice) {
76
            $this->echo('info', $afterNotice);
0 ignored issues
show
Bug introduced by
$afterNotice of type true is incompatible with the type string expected by parameter $content of Backpack\CRUD\app\Consol...tyCommandOutput::echo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
            $this->echo('info', /** @scrutinizer ignore-type */ $afterNotice);
Loading history...
77
        }
78
    }
79
80
    /**
81
     * Write text to the screen for the user to see.
82
     *
83
     * @param  string  $type  line, info, comment, question, error
84
     * @param  string  $content
85
     */
86
    public function echo($type, $content)
87
    {
88
        if ($this->option('debug') == false) {
89
            return;
90
        }
91
92
        // skip empty lines
93
        if (trim($content)) {
94
            $this->{$type}($content);
95
        }
96
    }
97
98
    /**
99
     * Write a title inside a box.
100
     *
101
     * @param  string  $content
102
     */
103
    public function box($content)
104
    {
105
        for ($i = 0, $line = ''; $i < strlen($content); ++$i, $line .= '─');
106
107
        $this->line('');
0 ignored issues
show
Bug introduced by
It seems like line() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        $this->/** @scrutinizer ignore-call */ 
108
               line('');
Loading history...
108
        $this->info("┌───{$line}───┐");
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
        $this->/** @scrutinizer ignore-call */ 
109
               info("┌───{$line}───┐");
Loading history...
109
        $this->info("│   $content   │");
110
        $this->info("└───{$line}───┘");
111
    }
112
113
    /**
114
     * Write a title inside a box.
115
     *
116
     * @param  string  $content
117
     */
118
    public function note($content)
119
    {
120
        $this->line("│ $content");
121
    }
122
}
123