Passed
Push — PSR-11-2 ( e86d47...dfb1a3 )
by Nikolaos
05:09
created

LazyGet   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 *
11
 * Implementation of this file has been influenced by AuraPHP
12
 *
13
 * @link    https://github.com/auraphp/Aura.Di
14
 * @license https://github.com/auraphp/Aura.Di/blob/4.x/LICENSE
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phalcon\Container\Injection;
20
21
use Psr\Container\ContainerInterface;
22
23
/**
24
 * Returns a Container service when invoked.
25
 *
26
 * @property ContainerInterface $container
27
 * @property string             $service
28
 */
29
class LazyGet implements LazyInterface
30
{
31
    /**
32
     * The service container.
33
     *
34
     * @var ContainerInterface
35
     */
36
    protected $container;
37
38
    /**
39
     * The service name to retrieve.
40
     *
41
     * @var string
42
     */
43
    protected $service;
44
45
    /**
46
     * Constructor.
47
     *
48
     * @param ContainerInterface $container The service container.
49
     * @param string             $service   The service to retrieve.
50
     */
51 3
    public function __construct(ContainerInterface $container, string $service)
52
    {
53 3
        $this->container = $container;
54 3
        $this->service   = $service;
55 3
    }
56
57
    /**
58
     * Invokes the closure to create the instance.
59
     *
60
     * @return object The object created by the closure.
61
     */
62 3
    public function __invoke(): object
63
    {
64 3
        return $this->container->get($this->service);
65
    }
66
}
67