Desmond::run()   A
last analyzed

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