Completed
Push — master ( f0cb70...d7ae81 )
by Ryan
14:28 queued 07:11
created

Evaluator::evaluate()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 22
rs 8.9197
c 1
b 1
f 0
cc 4
eloc 7
nc 3
nop 2
1
<?php namespace Anomaly\Streams\Platform\Support;
2
3
use Illuminate\Contracts\Container\Container;
4
5
/**
6
 * Class Evaluator
7
 *
8
 * @link    http://anomaly.is/streams-platform
9
 * @author  AnomalyLabs, Inc. <[email protected]>
10
 * @author  Ryan Thompson <[email protected]>
11
 * @package Anomaly\Streams\Platform\Support
12
 */
13
class Evaluator
14
{
15
16
    /**
17
     * The IoC container.
18
     *
19
     * @var \Illuminate\Contracts\Container\Container
20
     */
21
    protected $container;
22
23
    /**
24
     * Create a new Evaluator instance.
25
     *
26
     * @param Container $container
27
     */
28
    public function __construct(Container $container)
29
    {
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * Evaluate a target entity with arguments.
35
     *
36
     * @param        $target
37
     * @param  array $arguments
38
     * @return mixed
39
     */
40
    public function evaluate($target, array $arguments = [])
41
    {
42
        /**
43
         * If the target is an instance of Closure then
44
         * call through the IoC it with the arguments.
45
         */
46
        if ($target instanceof \Closure) {
47
            return $this->container->call($target, $arguments);
48
        }
49
50
        /**
51
         * If the target is an array then evaluate
52
         * each of it's values.
53
         */
54
        if (is_array($target)) {
55
            foreach ($target as &$value) {
56
                $value = $this->evaluate($value, $arguments);
57
            }
58
        }
59
60
        return $target;
61
    }
62
}
63