Completed
Push — master ( ecde4d...469191 )
by Todd
01:43
created

Reference   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 77
ccs 22
cts 24
cp 0.9167
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 3 1
A setName() 0 3 1
A resolve() 0 13 4
A getArgs() 0 3 1
A setArgs() 0 4 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 16
    public function __construct($name, array $args = []) {
31 16
        $this->setName($name);
32 16
        $this->setArgs($args);
33 16
    }
34
35
    /**
36
     * Get the name of the reference.
37
     *
38
     * @return string|array Returns the name of the reference.
39
     */
40 1
    public function getName() {
41 1
        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 16
    public function setName($name) {
50 16
        $this->name = $name;
51 16
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 13
    public function resolve(Container $container, $_ = null) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $_ is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
57 13
        if (empty($this->name)) {
58 1
            return null;
59 12
        } elseif (is_string($this->name)) {
60 9
            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 3
            }
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 16
    public function setArgs($args) {
86 16
        $this->args = $args;
87 16
        return $this;
88
    }
89
}
90