Callback::getCallback()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
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 that uses a callback to resolve.
12
 */
13
class Callback implements ReferenceInterface {
14
    /**
15
     * @var callable $callback
16
     */
17
    private $callback;
18
19
    /**
20
     * Construct a new instance of the {@link Callback} class.
21
     *
22
     * @param callable $callback The callback of the reference.
23
     */
24 2
    public function __construct(callable $callback) {
25 2
        $this->callback = $callback;
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function resolve(Container $container, $instance = null) {
32 1
        return call_user_func($this->callback, $container, $instance);
33
    }
34
35
    /**
36
     * Get the callback.
37
     *
38
     * @return callable Returns the callback.
39
     */
40 1
    public function getCallback() {
41 1
        return $this->callback;
42
    }
43
44
    /**
45
     * Set the callback.
46
     *
47
     * @param callable $callback The new callback to set.
48
     * @return Callback Returns `$this` for fluent calls.
49
     */
50 1
    public function setCallback($callback) {
51 1
        $this->callback = $callback;
52 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Garden\Container\Callback which is incompatible with the documented return type callable.
Loading history...
53
    }
54
}
55