ClosureLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 3 1
A __construct() 0 5 1
A supports() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\Loader;
19
20
use Rade\DI\AbstractContainer;
21
use Symfony\Component\Config\Loader\Loader;
22
23
/**
24
 * ClosureLoader loads service definitions from a PHP closure.
25
 *
26
 * The Closure has access to the container as its first argument.
27
 *
28
 * @author Divine Niiquaye Ibok <[email protected]>
29
 */
30
class ClosureLoader extends Loader
31
{
32
    private AbstractContainer $container;
33
34 4
    public function __construct(AbstractContainer $container)
35
    {
36 4
        parent::__construct();
37
38 4
        $this->container = $container;
39 4
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function load($resource, string $type = null): void
45
    {
46 2
        $resource($this->container);
47 2
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 2
    public function supports($resource, string $type = null)
53
    {
54 2
        return $resource instanceof \Closure;
55
    }
56
}
57