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

WifiStatusCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nicolas
5
 * Date: 05/02/17
6
 * Time: 14:32
7
 */
8
9
namespace Devgiants\Command;
10
11
use Buzz\Message\Request;
0 ignored issues
show
Bug introduced by
The type Buzz\Message\Request 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...
12
use Devgiants\Configuration\ConfigurationManager;
13
use Devgiants\Configuration\ApplicationConfiguration as AppConf;
14
use Devgiants\Model\ApplicationCommand;
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\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument 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\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...
19
20
class WifiStatusCommand extends ApplicationCommand {
21
22
	const STATUS = 'status';
23
24
	/**
25
	 * WifiStatusCommand constructor.
26
	 *
27
	 * @param null|string $name
28
	 * @param Container $container
29
	 */
30
	public function __construct( $name, Container $container ) {
31
		parent::__construct( $name, $container );
32
	}
33
34
	/**
35
	 * @inheritdoc
36
	 */
37
	protected function configure() {
38
		$this
39
			->setName( 'wifi:status' )
40
			->setDescription( 'Get wifi status (1 = ON, 0 = OFF)' )
41
			->addArgument( static::STATUS, InputArgument::OPTIONAL, "Get wifi status" )
42
			->setHelp( "This command allows you to get wifi status" );
43
44
		parent::configure();
45
	}
46
47
	/**
48
	 * @inheritdoc
49
	 */
50
	protected function execute( InputInterface $input, OutputInterface $output ) {
51
52
		$ymlFile = $this->getConfigurationFile( $input );
53
54
		if ( $ymlFile !== NULL && is_file( $ymlFile ) ) {
55
56
			// Structures check and configuration loading
57
			$configurationManager = new ConfigurationManager( $ymlFile );
58
			$configuration        = $configurationManager->load();
59
60
			// Get status
61
			if ( $input->hasArgument( static::STATUS ) ) {
62
				$response = $this->tools->createRequest(
63
					Request::METHOD_POST,
64
					"{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws",
65
					[
66
						"service"    => "NMC.Wifi",
67
						"method"     => "get",
68
						"parameters" => [],
69
					]
70
				);
71
72
				$json = json_decode( $response->getContent() );
73
74
				if ( isset( $json->result->status ) ) {
75
					$output->write( $json->result->status->Status ? 1 : 0 );
76
				}
77
			}
78
79
			// Handle post command stuff
80
			parent::execute( $input, $output );
81
		}
82
	}
83
}