Passed
Pull Request — master (#13)
by Kris
19:43
created

askNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
require_once __DIR__ .'/../vendor/autoload.php';
3
use Kristuff\Mishell\Console;
4
5
Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
6
Console::log("  - Use " . Console::text("int|bool ", 'blue') . Console::text("Console::askInt()", 'lightblue', 'underlined') . " to ask user to enter a number in the console.");
7
Console::log();
8
Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
9
Console::log("   - The method returns " . Console::text("int", 'blue') . " value or " .  Console::text("false", 'blue'). " if the entered value is not a valid int number.");
10
Console::log("   - You can customize colors (foreground and background) and some styles in same way than ");
11
Console::log('     with ' . Console::text("Console::text()", 'lightblue', 'underlined') . 
12
                 ' and ' .  Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
13
Console::log();
14
Console::log(' '. Console::text('Usage:', 'underlined', 'bold'));
15
Console::log('   ' . Console::text("\$value = Console::askInt('Please enter a number > ');", 'lightmagenta')); 
16
Console::log('   ' . Console::text("if (\$value !== false) {", 'lightmagenta')); 
17
Console::log('   ' . Console::text("// Do something with \$value", 'green')); 
18
Console::log();
19
Console::log(' '. Console::text('Sample:', 'underlined', 'bold'));
20
21
// -----------------
22
// sample start here
23
// -----------------
24
$value = Console::askInt('  Please enter a number > ');
25
if ($value !== false){
26
    Console::log('  => The value you entered is [' . Console::text($value, 'yellow') . ']');
27
} else {
28
    Console::log(Console::text('  Error:', 'red'));
29
    Console::log(Console::text('  => the value you entered is not a valid number.', 'red'));
30
}
31
32
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
33