Passed
Pull Request — master (#46)
by Théo
02:11
created

Configurable::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Console\Command;
16
17
use KevinGH\Box\Configuration;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
22
/**
23
 * Allows a configuration file path to be specified for a command.
24
 */
25
abstract class Configurable extends Command
26
{
27
    private const CONFIG_PARAM = 'config';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function configure(): void
33
    {
34
        $this->addOption(
35
            self::CONFIG_PARAM,
36
            'c',
37
            InputOption::VALUE_REQUIRED,
38
            'The alternative configuration file path.'
39
        );
40
    }
41
42
    /**
43
     * Returns the configuration settings.
44
     *
45
     * @param InputInterface $input the input handler
46
     *
47
     * @return Configuration the configuration settings
48
     */
49
    final protected function getConfig(InputInterface $input): Configuration
50
    {
51
        /** @var $helper \KevinGH\Box\Console\ConfigurationHelper */
52
        $helper = $this->getHelper('config');
53
54
        return $helper->loadFile($input->getOption(self::CONFIG_PARAM));
55
    }
56
}
57