MethodInvocationProvider::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\MethodInvocation;
8
use Ray\Di\Exception\MethodInvocationNotAvailable;
9
10
/**
11
 * @implements ProviderInterface<MethodInvocation>
12
 */
13
final class MethodInvocationProvider implements ProviderInterface
14
{
15
    /** @var ?MethodInvocation */
16
    private $invocation;
17
18
    public function set(MethodInvocation $invocation): void
19
    {
20
        $this->invocation = $invocation;
21
    }
22
23
    public function get(): MethodInvocation
24
    {
25
        if ($this->invocation === null) {
26
            throw new MethodInvocationNotAvailable();
27
        }
28
29
        return $this->invocation;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->invocation returns the type Ray\Aop\MethodInvocation which is incompatible with the return type mandated by Ray\Di\ProviderInterface::get() of Ray\Di\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
30
    }
31
}
32