Reference   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 91.3%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 19
c 3
b 0
f 0
dl 0
loc 75
ccs 21
cts 23
cp 0.913
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getArgs() 0 2 1
A setArgs() 0 3 1
A __construct() 0 3 1
A setName() 0 2 1
A resolve() 0 11 4
A getName() 0 2 1
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2017 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Container;
9
10
/**
11
 * A reference to another entry in a {@link Container}.
12
 */
13
class Reference implements ReferenceInterface {
14
    /**
15
     * @var string|array
16
     */
17
    private $name;
18
19
    /**
20
     * @var array
21
     */
22
    private $args;
23
24
    /**
25
     * Construct a new instance of the {@link Reference} class.
26
     *
27
     * @param string|array $name The name of the reference.
28
     * @param array $args Constructor arguments for the reference.
29
     */
30 18
    public function __construct($name, array $args = []) {
31 18
        $this->setName($name);
32 18
        $this->setArgs($args);
33 18
    }
34
35
    /**
36
     * Get the name of the reference.
37
     *
38
     * @return string|array Returns the name of the reference.
39
     */
40 8
    public function getName() {
41 8
        return $this->name;
42
    }
43
44
    /**
45
     * Set the name of the reference.
46
     *
47
     * @param string|array $name The name of the reference.
48
     */
49 18
    public function setName($name) {
50 18
        $this->name = $name;
51 18
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 15
    public function resolve(Container $container, $_ = null) {
57 15
        if (empty($this->name)) {
58 1
            return null;
59 14
        } elseif (is_string($this->name)) {
60 11
            return $container->getArgs($this->name, $this->args);
61
        } else {
62 3
            $result = $container;
63 3
            foreach ($this->name as $name) {
64 3
                $result = $result->get($name);
65
            }
66 3
            return $result;
67
        }
68
    }
69
70
    /**
71
     * Get constructor arguments for the the reference.
72
     *
73
     * @return array Returns the arguments.
74
     */
75
    public function getArgs() {
76
        return $this->args;
77
    }
78
79
    /**
80
     * Set constructor arguments for the the reference.
81
     *
82
     * @param array $args An array of arguments.
83
     * @return $this
84
     */
85 18
    public function setArgs($args) {
86 18
        $this->args = $args;
87 18
        return $this;
88
    }
89
}
90