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

ContainerStub   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ has() 0 3 1
has() 0 3 ?
A hp$0 ➔ get() 0 9 2
get() 0 9 ?
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