Resolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContainer() 0 4 1
A validate() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the Container package.
5
 *
6
 * Copyright (c) Miloš Đurić <[email protected]>
7
 *
8
 * For full copyright and license information, please refer to the LICENSE file,
9
 * located at the package root folder.
10
 */
11
12
namespace Laganica\Di\Resolver;
13
14
use InvalidArgumentException;
15
use Laganica\Di\Container;
16
use Laganica\Di\Definition\DefinitionInterface;
17
18
/**
19
 * Class Resolver
20
 *
21
 * @package Laganica\Di\Resolver
22
 */
23
abstract class Resolver implements ResolverInterface
24
{
25
    /**
26
     * @var Container
27
     */
28
    private $container;
29
30
    /**
31
     * @param Container $container
32
     */
33 17
    public function __construct(Container $container)
34
    {
35 17
        $this->container = $container;
36 17
    }
37
38
    /**
39
     * @return Container
40
     */
41 11
    protected function getContainer(): Container
42
    {
43 11
        return $this->container;
44
    }
45
46
    /**
47
     * @param DefinitionInterface $definition
48
     * @param string $expectedDefinitionClass
49
     */
50 17
    protected function validate(DefinitionInterface $definition, string $expectedDefinitionClass): void
51
    {
52 17
        if (!$definition instanceof $expectedDefinitionClass) {
53
            $actualType = get_class($definition);
54
55
            throw new InvalidArgumentException("Argument \$definition must be $expectedDefinitionClass, $actualType given");
56
        }
57 17
    }
58
}
59