Passed
Push — features/scrutinizer_conf ( cf2d4a...45dfb6 )
by Nicolas
01:09
created

ApplicationCommand::getConfigurationFile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 3
nop 1
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nicolas
5
 * Date: 22/12/17
6
 * Time: 14:34
7
 */
8
9
namespace Devgiants\Model;
10
11
12
use Devgiants\Exception\MissingConfigurationFileException;
13
use Devgiants\Service\LiveboxTools;
14
use Monolog\Logger;
0 ignored issues
show
Bug introduced by
The type Monolog\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Pimple\Container;
0 ignored issues
show
Bug introduced by
The type Pimple\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\Finder\Finder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
abstract class ApplicationCommand extends Command {
23
24
25
	const FILE_OPTION = 'file';
26
27
	/**
28
	 * @var Container
29
	 */
30
	protected $container;
31
32
	/**
33
	 * @var Logger
34
	 */
35
	protected $log;
36
37
	/**
38
	 * @var LiveboxTools
39
	 */
40
	protected $tools;
41
42
	/**
43
	 * @var string $host
44
	 */
45
	protected $host;
46
47
	/**
48
	 * ApplicationCommand constructor.
49
	 *
50
	 * @param null|string $name
51
	 * @param Container $container
52
	 */
53
	public function __construct( $name, Container $container ) {
54
		$this->container = $container;
55
		parent::__construct( $name );
56
57
		// Initiates logging
58
		$this->log = $this->container['main_logger'];
59
		if ( ! $this->log instanceof Logger ) {
60
			throw new \InvalidArgumentException( "Container main_logger entry must be Logger type" );
61
		}
62
63
		$this->tools = $this->container['tools'];
64
		if ( ! $this->tools instanceof LiveboxTools ) {
65
			throw new \InvalidArgumentException( "Container tools entry must be LiveboxTools type" );
66
		}
67
	}
68
69
	/**
70
	 * @inheritdoc
71
	 */
72
	protected function configure() {
73
		$this
74
			->addOption( self::FILE_OPTION, "f", InputOption::VALUE_OPTIONAL, "The YML configuration file" );
75
	}
76
77
	/**
78
	 * @param InputInterface $input
79
	 *
80
	 * @return string
81
	 * @throws MissingConfigurationFileException
82
	 */
83
	public function getConfigurationFile( InputInterface $input ) {
84
		$ymlFile = $input->getOption( self::FILE_OPTION );
85
		if ( $ymlFile === NULL ) {
86
			$finder = new Finder();
87
			$finder
88
				->in( $this->container['app_dir'] )
89
				->files()
90
				->name( '*.yml' );
91
92
			if ( $finder->count() === 1 ) {
93
				foreach ( $finder as $file ) {
94
					$ymlFile = $file->getRealPath();
95
				}
96
			} else {
97
				throw new MissingConfigurationFileException();
98
			}
99
		}
100
101
		return $ymlFile;
102
	}
103
104
	/**
105
	 * @inheritdoc
106
	 */
107
	protected function execute( InputInterface $input, OutputInterface $output ) {
108
		$this->tools->logout( '192.168.1.1' );
109
	}
110
}