ReferenceDefinition::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Definition\Build;
5
6
use Closure;
7
use Habemus\Definition\Definition;
8
use Habemus\Definition\Identifiable\IdentifiableTrait;
9
use Habemus\Definition\MethodCall\CallableMethod;
10
use Habemus\Definition\MethodCall\CallableMethodTrait;
11
use Habemus\Definition\Sharing\Shareable;
12
use Habemus\Definition\Sharing\ShareableTrait;
13
use Habemus\Definition\Tag\Taggable;
14
use Habemus\Definition\Tag\TaggableTrait;
15
use Psr\Container\ContainerInterface;
16
17
class ReferenceDefinition implements Definition, Shareable, CallableMethod, Taggable
18
{
19
    use IdentifiableTrait;
20
    use ShareableTrait;
21
    use CallableMethodTrait;
22
    use TaggableTrait;
23
24
    /**
25
     * @var string
26
     */
27
    protected $id;
28
29
    /**
30
     * @var Closure
31
     */
32
    protected $fn;
33
34
    public function __construct(string $id, Closure $fn = null)
35
    {
36
        $this->id = $id;
37
        $this->fn = $fn;
38
39
        if (! $this->fn instanceof Closure) {
40
            $this->fn = function ($instance, ContainerInterface $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
            $this->fn = function ($instance, /** @scrutinizer ignore-unused */ ContainerInterface $c) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
                return $instance;
42
            };
43
        }
44
    }
45
46
    public function id(): string
47
    {
48
        return $this->id;
49
    }
50
51
    public function getConcrete(ContainerInterface $container)
52
    {
53
        return ($this->fn)($container->get($this->id), $container);
54
    }
55
56
    public function __toString(): string
57
    {
58
        return $this->id;
59
    }
60
}
61