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

Desmond   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 35
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A loadFile() 0 4 1
A pretty() 0 4 2
A run() 0 13 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