Completed
Push — master ( 5909ec...c2adaf )
by Aydin
13s
created

examples/nested-submenu.php (3 issues)

Upgrade to new PHP Analysis Engine

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\CliMenu;
4
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
5
6
require_once(__DIR__ . '/../vendor/autoload.php');
7
8
$itemCallable = function (CliMenu $menu) {
9
    echo $menu->getSelectedItem()->getText();
10
};
11
12
$menu = (new CliMenuBuilder)
0 ignored issues
show
The method end() does not seem to exist on object<PhpSchool\CliMenu\Builder\CliMenuBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
13
    ->setTitle('CLI Menu')
14
    ->addItem('First Item', $itemCallable)
15
    ->addItem('Second Item', $itemCallable)
16
    ->addLineBreak('-')
17
    ->addSubMenu('sub-menu-1', 'Options')
0 ignored issues
show
'Options' is of type string, but the function expects a object<Closure>.

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...
18
        ->setTitle('CLI Menu > Options')
19
        ->addItem('First option', function (CliMenu $menu) {
20
            echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText());
21
        })
22
        ->addSubMenu('sub-menu-nested-1', 'Secret Options')
0 ignored issues
show
'Secret Options' is of type string, but the function expects a object<Closure>.

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...
23
            ->setTitle('CLI Menu > Options > Secret Options')
24
            ->addItem('First secret option', function (CliMenu $menu) {
25
                echo sprintf('Executing secret option: %s', $menu->getSelectedItem()->getText());
26
            })
27
            ->addLineBreak('-')
28
            ->end()
29
        ->addLineBreak('-')
30
        ->end()
31
    ->setWidth(70)
32
    ->setBackgroundColour('yellow')
33
    ->build();
34
35
$menu->open();
36