Evaluator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A visitVariable() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Visitor\Tests\Fixtures;
12
13
use Cubiche\Core\Visitor\LinkedVisitor;
14
15
/**
16
 * Evaluator Class.
17
 *
18
 * @author Karel Osorio Ramírez <[email protected]>
19
 */
20
class Evaluator extends LinkedVisitor
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $variables;
26
27
    /**
28
     * @param Calculator $calculator
29
     * @param array      $variables
30
     */
31
    public function __construct(Calculator $calculator, $variables = array())
32
    {
33
        parent::__construct($calculator);
34
35
        $this->variables = $variables;
36
    }
37
38
    /**
39
     * @param Variable $variable
40
     *
41
     * @throws \Exception
42
     *
43
     * @return mixed
44
     */
45
    public function visitVariable(Variable $variable)
46
    {
47
        if (isset($this->variables[$variable->name()])) {
48
            return $this->variables[$variable->name()];
49
        }
50
51
        throw new \Exception(\sprintf("Unknown variable '%s'", $variable->name()));
52
    }
53
}
54