LanguageAdapter::setLanguage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Maketok\DataMigration\Expression;
4
5
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
6
7
class LanguageAdapter implements LanguageInterface
8
{
9
    /** @var  ExpressionLanguage */
10
    protected $language;
11
12
    /**
13
     * @param ExpressionLanguage $language
14
     */
15 55
    public function __construct($language = null)
16
    {
17 55
        if ($language) {
18 51
            $this->language = $language;
19 51
        }
20 55
    }
21
22
    /**
23
     * @param mixed $expression
24
     * @param array $values
25
     * @return mixed
26
     */
27 35
    public function evaluate($expression, array $values = [])
28
    {
29 35
        if (is_callable($expression)) {
30 12
            return call_user_func_array($expression, $values);
31 31
        } elseif ((is_string($expression) || is_int($expression)) && $this->language) {
32 28
            return $this->language->evaluate($expression, $values);
33
        }
34 3
        throw new \InvalidArgumentException(
35 3
            sprintf("Wrong type of expression given: %s", gettype($expression))
36 3
        );
37
    }
38
39
    /**
40
     * @return ExpressionLanguage
41
     */
42 1
    public function getLanguage()
43
    {
44 1
        return $this->language;
45
    }
46
47
    /**
48
     * @param ExpressionLanguage $language
49
     */
50 1
    public function setLanguage($language)
51
    {
52 1
        $this->language = $language;
53 1
    }
54
}
55