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

Reference   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 50
ccs 12
cts 16
cp 0.75
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setName() 0 3 1
A __construct() 0 3 1
A getName() 0 3 1
A resolve() 0 13 4
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