CallableService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle;
3
use Symfony\Component\DependencyInjection\ContainerInterface;
4
5
/**
6
 * This is a class that is callable (through the __invoke method).
7
 * When invoke is called, it resolves the service in the service container.
8
 */
9
class CallableService
10
{
11
    /**
12
     * @var ContainerInterface
13
     */
14
    private $container;
15
16
    /**
17
     * @var string
18
     */
19
    private $serviceName;
20
21
    /**
22
     * Constructs the object that will resolve and return the $serviceName service
23
     * on __invoke.
24
     *
25
     * @param ContainerInterface $container
26
     * @param string $serviceName
27
     */
28
    public function __construct(ContainerInterface $container, $serviceName)
29
    {
30
        $this->container = $container;
31
        $this->serviceName = $serviceName;
32
    }
33
34
    /**
35
     * Returns the $serviceName service.
36
     *
37
     * @return object
38
     */
39
    public function __invoke()
40
    {
41
        return $this->container->get($this->serviceName);
42
    }
43
}
44