SelectHandler::repaint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "SelectHandler.php" doesn't match the expected filename "selecthandler.php"
Loading history...
2
namespace EddIriarte\Console\Handlers;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Symfony\Component\Console\Output\OutputInterface;
5
use Symfony\Component\Console\Terminal;
6
use EddIriarte\Console\Inputs\Interfaces\SelectInput;
7
8
/**
9
 * Class SelectHandler
10
 * @package Lazzier\Helpers
0 ignored issues
show
Coding Style Documentation introduced by
@package tag is not allowed in class comment
Loading history...
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
11
 * @author Eduardo Iriarte <eddiriarte[at]gmail[dot]com>
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
12
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
13
class SelectHandler
14
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class SelectHandler
Loading history...
15
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
16
     * @var resource
17
     */
18
    protected $stream;
0 ignored issues
show
Coding Style introduced by
Protected member variable "stream" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
19
20
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
     * @var OutputInterface
22
     */
23
    protected $output;
0 ignored issues
show
Coding Style introduced by
Protected member variable "output" must contain a leading underscore
Loading history...
24
25
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
     * @var SelectInput
27
     */
28
    protected $question;
0 ignored issues
show
Coding Style introduced by
Protected member variable "question" must contain a leading underscore
Loading history...
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var int
0 ignored issues
show
Bug introduced by
Expected "integer" but found "int" for @var tag in member variable comment
Loading history...
32
     */
33
    protected $row;
0 ignored issues
show
Coding Style introduced by
Protected member variable "row" must contain a leading underscore
Loading history...
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @var int
0 ignored issues
show
Bug introduced by
Expected "integer" but found "int" for @var tag in member variable comment
Loading history...
37
     */
38
    protected $column;
0 ignored issues
show
Coding Style introduced by
Protected member variable "column" must contain a leading underscore
Loading history...
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
42
     */
43
    protected $firstRun;
0 ignored issues
show
Coding Style introduced by
Protected member variable "firstRun" must contain a leading underscore
Loading history...
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @var int
0 ignored issues
show
Bug introduced by
Expected "integer" but found "int" for @var tag in member variable comment
Loading history...
47
     */
48
    protected $terminalWidth;
0 ignored issues
show
Coding Style introduced by
Protected member variable "terminalWidth" must contain a leading underscore
Loading history...
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $stream should have a doc-comment as per coding-style.
Loading history...
51
     * SelectStreamHandler constructor.
52
     * @param SelectInput $question
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
53
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
54
     * @param $stream
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
55
     */
56 7
    public function __construct(SelectInput $question, OutputInterface $output, $stream)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
introduced by
Type hint "stream" missing for
Loading history...
57
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
58 7
        $this->row = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
59 7
        $this->column = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
60 7
        $this->question = $question;
61 7
        $this->output = $output;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
62 7
        $this->stream = $stream;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63 7
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
64
65
    /**
66
     * Navigates through option items.
67
     *
68
     * @return array
69
     */
70 6
    public function handle(): array
71
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
72 6
        $this->firstRun = true;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
73 6
        $this->output->writeln(
74 6
            '<info>' . $this->question->getMessage() . '</info> [<comment>SPACE=select</>, <comment>ENTER=submit</>]'
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
75
        );
76 6
        $this->repaint();
77
78 6
        $sttyMode = shell_exec('stty -g');
79
80
        // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
81 6
        shell_exec('stty -icanon -echo');
82
83
        // Read a keypress
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
84 6
        while (!feof($this->stream)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
85 6
            $char = fread($this->stream, 1);
86 6
            if (" " === $char) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
87 6
                $this->tryCellSelection();
88 6
            } elseif ("\033" === $char) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
89 6
                $this->tryCellNavigation($char);
90 6
            } elseif (10 === ord($char)) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
91
                //TODO handle valid state...
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
Coding Style introduced by
No space found before comment text; expected "// TODO handle valid state..." but found "//TODO handle valid state..."
Loading history...
92 3
                $this->clear();
93 3
                $this->output->write('> ' . join(', ', $this->question->getSelections()));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
94 3
                $this->output->write($char);
95 3
                break;
96
            }
97 6
            $this->repaint();
98
        }
99
100
        // Reset stty so it behaves normally again
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
101 6
        shell_exec(sprintf('stty %s', $sttyMode));
102
103 6
        $this->output->writeln(' ');
104
105 6
        return $this->question->getSelections();
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end handle()
Loading history...
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $row should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $column should have a doc-comment as per coding-style.
Loading history...
109
     * @param $row
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
110
     * @param $column
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
111
     * @return bool
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
112
     */
113 11
    public function exists($row, $column): bool
0 ignored issues
show
introduced by
Type hint "row" missing for
Loading history...
introduced by
Type hint "column" missing for
Loading history...
114
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
115 11
        return $this->question->hasEntryAt($row, $column);
0 ignored issues
show
Bug introduced by
The method hasEntryAt() does not exist on EddIriarte\Console\Inputs\Interfaces\SelectInput. Since it exists in all sub-types, consider adding an abstract or default implementation to EddIriarte\Console\Inputs\Interfaces\SelectInput. ( Ignorable by Annotation )

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

115
        return $this->question->/** @scrutinizer ignore-call */ hasEntryAt($row, $column);
Loading history...
116
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end exists()
Loading history...
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
119
     *
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121 1
    protected function up(): void
122
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
123 1
        if ($this->exists($this->row - 1, $this->column)) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
124 1
            $this->row -= 1;
125
        }
126 1
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end up()
Loading history...
127
128
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
129
     *
130
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
131 2
    protected function down(): void
132
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
133 2
        if ($this->exists($this->row + 1, $this->column)) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
134 2
            $this->row += 1;
135
        }
136 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end down()
Loading history...
137
138
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
139
     *
140
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
141 3
    protected function left(): void
142
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
143 3
        if ($this->exists($this->row, $this->column - 1)) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
144 3
            $this->column -= 1;
145
        }
146 3
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end left()
Loading history...
147
148
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
149
     *
150
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
151 5
    protected function right(): void
152
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
153 5
        if ($this->exists($this->row, $this->column + 1)) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
154 5
            $this->column += 1;
155
        }
156 5
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end right()
Loading history...
157
158
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
159
     *
160
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
161 6
    protected function tryCellSelection(): void
162
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
163
        // Try to select cell.
164 6
        if ($this->exists($this->row, $this->column)) {
165 6
            $option = $this->question->getEntryAt($this->row, $this->column);
0 ignored issues
show
Bug introduced by
The method getEntryAt() does not exist on EddIriarte\Console\Inputs\Interfaces\SelectInput. Since it exists in all sub-types, consider adding an abstract or default implementation to EddIriarte\Console\Inputs\Interfaces\SelectInput. ( Ignorable by Annotation )

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

165
            /** @scrutinizer ignore-call */ 
166
            $option = $this->question->getEntryAt($this->row, $this->column);
Loading history...
166 6
            $this->question->select($option);
167
        }
168 6
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end tryCellSelection()
Loading history...
169
170
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $char should have a doc-comment as per coding-style.
Loading history...
171
     * @param $char
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
172
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
173 6
    protected function tryCellNavigation($char): void
0 ignored issues
show
introduced by
Type hint "char" missing for
Loading history...
174
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
175
        // Did we read an escape sequence?
176 6
        $char .= fread($this->stream, 2);
177 6
        if (empty($char[2]) || !in_array($char[2], ['A', 'B', 'C', 'D'])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
178
            // Input stream was not an arrow key.
179
            return;
180
        }
181
182 6
        switch ($char[2]) {
0 ignored issues
show
Coding Style introduced by
All SWITCH statements must contain a DEFAULT case
Loading history...
183 6
            case 'A': // go up!
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Blank lines are not allowed after CASE statements
Loading history...
Coding Style introduced by
Comments may not appear after statements
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
184 1
                $this->up();
185 1
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
186 6
            case 'B': // go down!
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Blank lines are not allowed after CASE statements
Loading history...
Coding Style introduced by
Comments may not appear after statements
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
187 2
                $this->down();
188 2
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
189 5
            case 'C': // go right!
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Blank lines are not allowed after CASE statements
Loading history...
Coding Style introduced by
Comments may not appear after statements
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
190 5
                $this->right();
191 5
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
192 3
            case 'D': // go left!
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Blank lines are not allowed after CASE statements
Loading history...
Coding Style introduced by
Comments may not appear after statements
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
193 3
                $this->left();
194 3
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement must be indented 4 spaces from SWITCH keyword
Loading history...
195
        }
196 6
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end tryCellNavigation()
Loading history...
197
198
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
199
     *
200
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
201 7
    public function repaint(): void
202
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
203 7
        $message = $this->message();
204 7
        if (!$this->firstRun) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
205 7
            $this->clear();
206
        }
207
208 7
        $this->firstRun = false;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
209 7
        $this->output->write($message);
210 7
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end repaint()
Loading history...
211
212
    /**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
213
     *
214
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
215 7
    public function clear(): void
216
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
217
        // Move the cursor to the beginning of the line
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
218 7
        $this->output->write("\x0D");
219
        // Erase the line
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
220 7
        $this->output->write("\x1B[2K");
221
        // Erase previous lines
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
222 7
        $lines = $this->question->getChunksCount() - 1;
0 ignored issues
show
Bug introduced by
The method getChunksCount() does not exist on EddIriarte\Console\Inputs\Interfaces\SelectInput. Since it exists in all sub-types, consider adding an abstract or default implementation to EddIriarte\Console\Inputs\Interfaces\SelectInput. ( Ignorable by Annotation )

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

222
        $lines = $this->question->/** @scrutinizer ignore-call */ getChunksCount() - 1;
Loading history...
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
223 7
        if ($lines > 0) {
224 2
            $this->output->write(str_repeat("\x1B[1A\x1B[2K", $lines));
225
        }
226 7
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end clear()
Loading history...
227
228
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
229
     * @return string
230
     */
231 7
    protected function message(): string
232
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
233 7
        $chunkSize = $this->chunkSize();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
234 7
        $chunks = $this->question->getChunks($chunkSize);
0 ignored issues
show
Bug introduced by
The method getChunks() does not exist on EddIriarte\Console\Inputs\Interfaces\SelectInput. Since it exists in all sub-types, consider adding an abstract or default implementation to EddIriarte\Console\Inputs\Interfaces\SelectInput. ( Ignorable by Annotation )

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

234
        /** @scrutinizer ignore-call */ 
235
        $chunks = $this->question->getChunks($chunkSize);
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
235 7
        $columnSpace = floor(($this->terminalWidth() - ($chunkSize * 5)) / $chunkSize);
236 7
        return join(PHP_EOL, array_map(function ($entries) use ($chunks, $columnSpace) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
237 7
            $hasCursor = (bool) ($this->row === array_search($entries, $chunks));
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
238 7
            return $this->makeRow($entries, ($hasCursor ? $this->column : -10), $columnSpace);
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Bug introduced by
$columnSpace of type double is incompatible with the type integer expected by parameter $columnSpace of EddIriarte\Console\Handl...electHandler::makeRow(). ( Ignorable by Annotation )

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

238
            return $this->makeRow($entries, ($hasCursor ? $this->column : -10), /** @scrutinizer ignore-type */ $columnSpace);
Loading history...
239 7
        }, $chunks));
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
240
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end message()
Loading history...
241
242
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $columnSpace should have a doc-comment as per coding-style.
Loading history...
243
     * @param array $entries
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
244
     * @param int $activeColumn
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
245
     * @return mixed
246
     */
247
    protected function makeRow(array $entries, int $activeColumn, int $columnSpace)
248
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
249 7
        return array_reduce($entries, function ($carry, $item) use ($entries, $activeColumn, $columnSpace) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
250 7
            $isActive = ($activeColumn === array_search($item, $entries));
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
251 7
            return $carry . $this->makeCell($item, $isActive, $columnSpace);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
252 7
        }, '');
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
253
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end makeRow()
Loading history...
254
255
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
256
     * @param string $option
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
257
     * @param bool $hasCursor
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for parameter type
Loading history...
258
     * @param int $maxWidth
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
259
     * @return string
260
     */
261 7
    protected function makeCell(string $option, bool $hasCursor = false, int $maxWidth = 20): string
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
262
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
263 7
        $selected = $this->question->isSelected($option);
264 7
        $name = substr($option, 0, ($maxWidth - 1));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
265
266 7
        return sprintf(
267 7
            $hasCursor ? ' <hl> %1$s %2$s </hl>' : ' <%3$s> %1$s %2$s </%3$s>',
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
268 7
            ($selected ? '●' : '○'),
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
269 7
            $name . str_repeat(' ', $maxWidth - mb_strlen($name)),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
270 7
            ($selected ? 'info' : 'comment')
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
271
        );
272
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end makeCell()
Loading history...
273
274 7
    public function terminalWidth()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
275
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
276 7
        return (new Terminal)->getWidth();
277
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end terminalWidth()
Loading history...
278
279 7
    public function chunkSize()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
280
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
281 7
        $max = $this->terminalWidth();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
282 7
        $largest = array_reduce($this->question->getOptions(), 'max', 0);
283
284 7
        if ($largest > ($max / 2)) {
285
            return 1;
286 7
        } elseif ($largest > ($max / 3)) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
287
            return 2;
288
        } else {
289 7
            return 3;
290
        }
291
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end chunkSize()
Loading history...
292
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
293