Passed
Pull Request — master (#2)
by Victor
02:42
created

ContainerStub.php$0 ➔ get()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Mocks;
5
6
use Exception;
7
use Psr\Container\ContainerInterface;
8
use Psr\Container\NotFoundExceptionInterface;
9
10
final class ContainerStub implements ContainerInterface
11
{
12
    /**
13
     * @param string $id
14
     *
15
     * @throws NotFoundExceptionInterface
16
     *
17
     * @return mixed
18
     */
19
    public function get($id)
20
    {
21
        if (!$this->has($id)) {
22
            throw new class extends Exception implements NotFoundExceptionInterface
23
            {
24
            };
25
        }
26
27
        return new $id();
28
    }
29
30
    /**
31
     * @param string $id
32
     *
33
     * @return bool
34
     */
35
    public function has($id): bool
36
    {
37
        return class_exists($id);
38
    }
39
}
40