These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use PhpSchool\CliMenu\Action\ExitAction; |
||
4 | use PhpSchool\CliMenu\CliMenu; |
||
5 | use PhpSchool\CliMenu\Builder\CliMenuBuilder; |
||
6 | use PhpSchool\CliMenu\MenuItem\SplitItem; |
||
7 | |||
8 | require_once(__DIR__ . '/../vendor/autoload.php'); |
||
9 | |||
10 | $cols = 60; |
||
11 | $rows = 20; |
||
12 | |||
13 | $paint = function (CliMenu $menu) { |
||
14 | $item = $menu->getSelectedItem(); |
||
15 | if ($item->getText() === ' ') { |
||
16 | $item->setText('█'); |
||
17 | } else { |
||
18 | $item->setText(' '); |
||
19 | } |
||
20 | }; |
||
21 | |||
22 | $clear = function (CliMenu $menu) { |
||
23 | foreach ($menu->getItems() as $item) { |
||
24 | if ($item instanceof SplitItem && $item->canSelect()) { |
||
25 | foreach ($item->getItems() as $cell) { |
||
26 | if ($cell->canSelect() && $cell->getText() !== ' ') { |
||
27 | $cell->setText(' '); |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 | $menu->redraw(false); |
||
33 | }; |
||
34 | |||
35 | $builder = (new CliMenuBuilder) |
||
36 | ->disableDefaultItems() |
||
37 | ->setWidth($cols + 10) |
||
38 | ->setBorder(0) |
||
39 | ->setMargin(2) |
||
40 | ->setPadding(2, 5) |
||
41 | ->setSelectedMarker('') |
||
42 | ->setUnselectedMarker('') |
||
43 | ->addAsciiArt('Draw your own art !') |
||
44 | ->addLineBreak(); |
||
45 | |||
46 | for ($i = 0; $i < $rows; $i++) { |
||
47 | $builder->addSplitItem(function() use ($cols, $paint) { |
||
48 | $this->setGutter(0); |
||
0 ignored issues
–
show
|
|||
49 | for ($j = 0; $j < $cols; $j++) { |
||
50 | $this->addItem(' ', $paint); |
||
51 | } |
||
52 | }); |
||
53 | } |
||
54 | |||
55 | $builder->addSplitItem(function() { |
||
56 | $this->addStaticItem('Enter: Toggle draw') |
||
0 ignored issues
–
show
|
|||
57 | ->addStaticItem('C: Clear screen') |
||
58 | ->addStaticItem('X: Exit'); |
||
59 | }); |
||
60 | |||
61 | $menu = $builder->build(); |
||
62 | |||
63 | $menu->addCustomControlMappings(['C' => $clear, 'X' => new ExitAction]); |
||
64 | $menu->open(); |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.