Repl::welcome()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Desmond;
3
use Desmond\Desmond;
4
use Desmond\data_types\VoidType;
5
6
class Repl
7
{
8
    private $desmond;
9
10
    public function __construct()
11
    {
12
        $this->desmond = new Desmond();
13
    }
14
15
    public function start()
16
    {
17
        $this->welcome();
18
        do {
19
            $input = $this->promptForInput();
20
21
            if ($this->isExitCommand($input)) {
22
                exit("Later, guy.\n");
0 ignored issues
show
Coding Style Compatibility introduced by
The method start() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
23
            }
24
25
            if ($this->shouldBeProcessed($input)) {
26
                try {
27
                    $return = $this->desmond->pretty(
28
                        $this->desmond->run($input));
29
                } catch (\Exception $exception) {
30
                    echo "#! {$exception->getMessage()}\n";
31
                    continue;
32
                }
33
                echo $return . "\n";
34
            }
35
        } while (!feof(STDIN));
36
    }
37
38
    private function welcome()
39
    {
40
        echo "
41
Copyright 2017, Scott Christianson
42
Version 0.3.3
43
Welcome to Desmond's REPL.\n\n";
44
    }
45
46
    private function promptForInput()
47
    {
48
        echo '/user λ ';
49
        return fgets(STDIN);
50
    }
51
52
    private function isExitCommand($input)
53
    {
54
        return $input == "exit\n";
55
    }
56
57
    private function shouldBeProcessed($input)
58
    {
59
        return !empty($input) && !preg_match('/^;/', $input);
60
    }
61
}
62