Completed
Pull Request — master (#10)
by Todd
01:51
created

Reference::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.037
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
     * Construct a new instance of the {@link Reference} class.
21
     *
22
     * @param string|array $name The name of the reference.
23
     */
24 6
    public function __construct($name) {
25
        $this->setName($name);
26 6
    }
27
28
    /**
29
     * Get the name of the reference.
30
     *
31
     * @return string|array Returns the name of the reference.
32
     */
33
    public function getName() {
34
        return $this->name;
35
    }
36
37
    /**
38
     * Set the name of the reference.
39
     *
40
     * @param string|array $name The name of the reference.
41
     */
42 5
    public function setName($name) {
43 5
        $this->name = $name;
44 5
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 5
    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...
50 5
        if (empty($this->name)) {
51 1
            return null;
52
        } elseif (is_string($this->name)) {
53
            return $container->get($this->name);
54
        } else {
55 3
            $result = $container;
56 3
            foreach ($this->name as $name) {
57
                $result = $result->get($name);
58
            }
59 3
            return $result;
60
        }
61 5
    }
62
}
63