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

Evaluator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 50
rs 10
c 1
b 1
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B evaluate() 0 22 4
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