1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | namespace EddIriarte\Console\Helpers; |
||
0 ignored issues
–
show
|
|||
3 | |||
4 | use EddIriarte\Console\Handlers\SelectHandler; |
||
5 | use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
||
6 | use Symfony\Component\Console\Helper\HelperInterface; |
||
7 | use Symfony\Component\Console\Helper\HelperSet; |
||
8 | use Symfony\Component\Console\Input\InputInterface; |
||
9 | use Symfony\Component\Console\Output\OutputInterface; |
||
10 | use EddIriarte\Console\Inputs\Interfaces\SelectInput; |
||
11 | |||
12 | /** |
||
13 | * Class SelectionHelper |
||
14 | * |
||
15 | * Its used for registration to symfonys output helpers. |
||
16 | * |
||
17 | * @package EddIriarte\Console\Helpers |
||
0 ignored issues
–
show
|
|||
18 | * @author Eduardo Iriarte <eddiriarte[at]gmail[dot]com> |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
19 | */ |
||
0 ignored issues
–
show
|
|||
20 | class SelectionHelper implements HelperInterface |
||
21 | { |
||
0 ignored issues
–
show
|
|||
22 | use StreamableInput; |
||
23 | |||
24 | /** |
||
0 ignored issues
–
show
|
|||
25 | * @var InputInterface |
||
26 | */ |
||
27 | protected $input; |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | /** |
||
0 ignored issues
–
show
|
|||
30 | * @var OutputInterface |
||
31 | */ |
||
32 | protected $output; |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | /** |
||
0 ignored issues
–
show
|
|||
35 | * @var null |
||
36 | */ |
||
37 | protected $helperSet = null; |
||
0 ignored issues
–
show
|
|||
38 | |||
39 | /** |
||
40 | * SelectionHelper constructor. |
||
41 | * @param InputInterface $input |
||
0 ignored issues
–
show
|
|||
42 | * @param OutputInterface $output |
||
0 ignored issues
–
show
|
|||
43 | */ |
||
44 | 5 | public function __construct(InputInterface $input, OutputInterface $output) |
|
0 ignored issues
–
show
|
|||
45 | { |
||
0 ignored issues
–
show
|
|||
46 | 5 | $this->input = $input; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||
47 | 5 | $this->output = $output; |
|
48 | |||
49 | 5 | $this->checkAnsiSupport(); |
|
50 | 5 | $this->setOutputStyles(); |
|
51 | 5 | } |
|
0 ignored issues
–
show
|
|||
52 | |||
53 | /** |
||
0 ignored issues
–
show
|
|||
54 | * {@inheritdoc} |
||
55 | */ |
||
0 ignored issues
–
show
|
|||
56 | 2 | public function setHelperSet(HelperSet $helperSet = null) |
|
0 ignored issues
–
show
|
|||
57 | { |
||
0 ignored issues
–
show
|
|||
58 | 2 | $this->helperSet = $helperSet; |
|
0 ignored issues
–
show
It seems like
$helperSet can also be of type Symfony\Component\Console\Helper\HelperSet . However, the property $helperSet is declared as type null . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
59 | 2 | } |
|
0 ignored issues
–
show
|
|||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
0 ignored issues
–
show
|
|||
64 | 1 | public function getHelperSet() |
|
65 | { |
||
0 ignored issues
–
show
|
|||
66 | 1 | return $this->helperSet; |
|
67 | } |
||
0 ignored issues
–
show
|
|||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
0 ignored issues
–
show
|
|||
72 | 2 | public function getName() |
|
73 | { |
||
0 ignored issues
–
show
|
|||
74 | 2 | return 'selection'; |
|
75 | } |
||
0 ignored issues
–
show
|
|||
76 | |||
77 | /** |
||
78 | * Allow multiple item selections to user. |
||
79 | * |
||
80 | * @param SelectInput $question |
||
0 ignored issues
–
show
|
|||
81 | * @return array |
||
0 ignored issues
–
show
|
|||
82 | */ |
||
83 | 1 | public function select(SelectInput $question) |
|
84 | { |
||
0 ignored issues
–
show
|
|||
85 | 1 | $select = new SelectHandler($question, $this->output, $this->getInputStream()); |
|
86 | |||
87 | 1 | $responses = $select->handle(); |
|
88 | // TODO: validate responses ??? |
||
0 ignored issues
–
show
|
|||
89 | |||
90 | 1 | return $responses; |
|
91 | } |
||
0 ignored issues
–
show
|
|||
92 | |||
93 | /** |
||
0 ignored issues
–
show
|
|||
94 | * |
||
95 | */ |
||
0 ignored issues
–
show
|
|||
96 | 5 | protected function checkAnsiSupport(): void |
|
97 | { |
||
0 ignored issues
–
show
|
|||
98 | 5 | if ($this->output->isDecorated()) { |
|
99 | 3 | return; |
|
100 | } |
||
101 | |||
102 | // // disable overwrite when output does not support ANSI codes. |
||
103 | // $this->overwrite = false; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
45% 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. ![]() |
|||
104 | // // set a reasonable redraw frequency so output isn't flooded |
||
105 | // $this->setRedrawFrequency(10); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
106 | 2 | } |
|
0 ignored issues
–
show
|
|||
107 | |||
108 | 5 | protected function setOutputStyles() |
|
0 ignored issues
–
show
|
|||
109 | { |
||
0 ignored issues
–
show
|
|||
110 | 5 | if (!$this->output->getFormatter()->hasStyle('hl')) { |
|
0 ignored issues
–
show
|
|||
111 | 3 | $style = new OutputFormatterStyle('black', 'white'); |
|
112 | 3 | $this->output->getFormatter()->setStyle('hl', $style); |
|
113 | } |
||
114 | 5 | } |
|
0 ignored issues
–
show
|
|||
115 | } |
||
0 ignored issues
–
show
|
|||
116 |