Completed
Push — master ( df8184...e3b994 )
by Aydin
02:31
created

examples/input-password.php (2 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
    $result = $menu->askPassword()
10
        ->setPlaceholderText('')
11
        ->setValidator(function ($password) {
12
            if ($password === 'password') {
13
                $this->setValidationFailedText('Password is too weak');
0 ignored issues
show
The variable $this does not exist. Did you forget to declare it?

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.

Loading history...
14
                return false;
15
            } else if (strlen($password) <= 6) {
16
                $this->setValidationFailedText('Password is not long enough');
17
                return false;
18
            } 
19
            
20
            return true;
21
        })
22
        ->ask();
23
24
    var_dump($result->fetch());
0 ignored issues
show
Security Debugging Code introduced by Aydin Hassan
var_dump($result->fetch()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
25
};
26
27
$menu = (new CliMenuBuilder)
28
    ->setTitle('Basic CLI Menu')
29
    ->addItem('Enter password', $itemCallable)
30
    ->addItem('Second Item', $itemCallable)
31
    ->addItem('Third Item', $itemCallable)
32
    ->addLineBreak('-')
33
    ->setMarginAuto()
34
    ->build();
35
36
$menu->open();
37