Resolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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