ContainerParameterLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Loaders\ContainerParameterLoader
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2019 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-cli
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Cli\Loaders;
16
17
use TechDivision\Import\Loaders\LoaderInterface;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
20
/**
21
 * Generic loader implementation for container parameters.
22
 *
23
 * @author    Tim Wagner <[email protected]>
24
 * @copyright 2019 TechDivision GmbH <[email protected]>
25
 * @license   https://opensource.org/licenses/MIT
26
 * @link      https://github.com/techdivision/import-cli
27
 * @link      http://www.techdivision.com
28
 */
29
class ContainerParameterLoader implements LoaderInterface
30
{
31
32
    /**
33
     * The container instance.
34
     *
35
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
36
     */
37
    protected $container;
38
39
    /**
40
     * The parameter name to load the value with.
41
     *
42
     * @var string
43
     */
44
    protected $parameterName;
45
46
    /**
47
     * Initializes the loader with the container and the parameter name to load the value for.
48
     *
49
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container     The container instance
50
     * @param string                                                    $parameterName The container parameter name to return the value for
51
     */
52
    public function __construct(ContainerInterface $container, string $parameterName)
53
    {
54
        $this->container = $container;
55
        $this->parameterName = $parameterName;
56
    }
57
58
    /**
59
     * Return's the container instance.
60
     *
61
     * @return \Symfony\Component\DependencyInjection\ContainerInterface The container instance
62
     */
63
    protected function getContainer() : ContainerInterface
64
    {
65
        return $this->container;
66
    }
67
68
    /**
69
     * Return's the parameter name to load the value for.
70
     *
71
     * @return string The parameter name
72
     */
73
    protected function getParameterName() : string
74
    {
75
        return $this->parameterName;
76
    }
77
78
    /**
79
     * Loads and returns the parameter value from the container configuration.
80
     *
81
     * @return mixed The parameter value from the container configuration
82
     * @see \Symfony\Component\DependencyInjection\ContainerInterface::getParameter()
83
     */
84
    public function load()
85
    {
86
        return $this->getContainer()->getParameter($this->getParameterName());
87
    }
88
}
89