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

examples/input-password.php (1 issue)

Check for forgotten debug code

Debugging Code Security Critical

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');
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