Test Failed
Pull Request — master (#17)
by Yo
02:38
created

loadTemplateConfigurationFile()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
c 0
b 0
f 0
rs 9.2
cc 4
eloc 11
nc 4
nop 1
1
<?php
2
namespace Yoanm\ComposerConfigManager\Infrastructure\Command;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputOption;
7
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationFileLoaderInterface;
8
use Yoanm\ComposerConfigManager\Domain\Model\Configuration;
9
10
abstract class AbstractTemplatableCommand extends Command
11
{
12
    const OPTION_TEMPLATE = 'template';
13
14
    /** @var ConfigurationFileLoaderInterface */
15
    private $configurationLoader;
0 ignored issues
show
Unused Code introduced by
The property $configurationLoader is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17
    /**
18
     * @param ConfigurationFileLoaderInterface $configurationFileLoader
19
     */
20
    public function __construct(ConfigurationFileLoaderInterface $configurationFileLoader)
21
    {
22
        parent::__construct();
23
        $this->configurationFileLoader = $configurationFileLoader;
0 ignored issues
show
Bug introduced by
The property configurationFileLoader does not seem to exist. Did you mean configurationLoader?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24
    }
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->addOption(
32
                self::OPTION_TEMPLATE,
33
                null,
34
                InputOption::VALUE_REQUIRED,
35
                'Path of the json template file. Will be used as default values.'
36
            )
37
        ;
38
    }
39
40
    /**
41
     * @return ConfigurationFileLoaderInterface
42
     */
43
    public function getConfigurationFileLoader()
44
    {
45
        return $this->configurationFileLoader;
0 ignored issues
show
Bug introduced by
The property configurationFileLoader does not seem to exist. Did you mean configurationLoader?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
    }
47
48
    /**
49
     * @param InputInterface $input
50
     *
51
     * @return null|Configuration
52
     */
53
    protected function loadTemplateConfigurationFile(InputInterface $input)
54
    {
55
        $templatePath = $input->getOption(self::OPTION_TEMPLATE);
56
        $templateConfiguration = null;
57
        if ($templatePath) {
58
            if (is_dir($templatePath)) {
59
                $templateConfiguration = $this->configurationFileLoader->fromPath($templatePath);
0 ignored issues
show
Bug introduced by
The property configurationFileLoader does not seem to exist. Did you mean configurationLoader?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
            } elseif (is_file($templatePath)) {
61
                $templateConfiguration = $this->configurationFileLoader->fromString(file_get_contents($templatePath));
0 ignored issues
show
Bug introduced by
The property configurationFileLoader does not seem to exist. Did you mean configurationLoader?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
62
            } else {
63
                throw new \UnexpectedValueException('Template path is nor a file or a path !');
64
            }
65
        }
66
67
        return $templateConfiguration;
68
    }
69
}
70