Repl   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 56
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B start() 0 22 5
A welcome() 0 7 1
A promptForInput() 0 5 1
A isExitCommand() 0 4 1
A shouldBeProcessed() 0 4 2
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