Completed
Branch master (5720e6)
by Scott
05:47 queued 02:57
created

Desmond::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 1
crap 3
1
<?php
2
3
namespace Desmond;
4
5
use Desmond\Lexer;
6
use Desmond\Evaluator;
7
8
class Desmond
9
{
10
    private $lexer;
11
    private $eval;
12
13 6
    public function __construct()
14
    {
15 6
        $this->lexer = new Lexer();
16 6
        $this->eval = new Evaluator();
17 6
    }
18
19 6
    public function run($command)
20
    {
21 6
        if (empty($command)) {
22 1
            return '';
23
        }
24
        try {
25 5
            $ast = $this->lexer->readString($command);
26 4
            $value = $this->eval->getReturn($ast);
27 1
        } catch (\Exception $exception) {
28 1
            return $exception->getMessage();
29
        }
30 4
        return $value;
31
    }
32
33 1
    public function loadFile($file)
34
    {
35 1
        $this->run('(load-file "' . $file . '")');
36 1
    }
37
38 2
    public function pretty($value)
39
    {
40 2
        return method_exists('__toString', $value) ? $value->__toString() : $value;
41
    }
42
}
43