Passed
Pull Request — master (#17)
by Aleksei
11:42
created

BaseInjectorTest.php$0 ➔ getContainer()   A

Complexity

Conditions 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseInjectorTest.php$0 ➔ has() 0 3 1
A BaseInjectorTest.php$1 ➔ __construct() 0 3 1
A BaseInjectorTest.php$0 ➔ get() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Injector\Tests\Common;
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\Container\ContainerInterface;
9
use Psr\Container\NotFoundExceptionInterface;
10
11
abstract class BaseInjectorTest extends TestCase
12
{
13
    protected function getContainer(array $definitions = []): ContainerInterface
14
    {
15
        return new class($definitions) implements ContainerInterface {
16
            private array $definitions;
17
            public function __construct(array $definitions = [])
18
            {
19
                $this->definitions = $definitions;
20
            }
21
            public function get($id)
22
            {
23
                if (!$this->has($id)) {
24
                    throw new class() extends \Exception implements NotFoundExceptionInterface {
25
                    };
26
                }
27
                return $this->definitions[$id];
28
            }
29
            public function has($id)
30
            {
31
                return array_key_exists($id, $this->definitions);
32
            }
33
        };
34
    }
35
}
36