Completed
Push — master ( 7c7d0a...1d2816 )
by Scott
03:13
created

Repl::promptForInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 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) {
0 ignored issues
show
Bug introduced by
The class Desmond\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
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.0
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