NatInfosCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A configure() 0 9 1
A execute() 0 32 3
1
<?php
2
namespace Devgiants\Command;
3
4
use Buzz\Message\Request;
5
use Devgiants\Model\ApplicationCommand;
6
use Devgiants\Configuration\ConfigurationManager;
7
use Devgiants\Configuration\ApplicationConfiguration as AppConf;
8
use Pimple\Container;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class NatInfosCommand extends ApplicationCommand
13
{
14
	/**
15
	 * Wan command constructor.
16
	 *
17
	 * @param null|string $name
18
	 * @param Container $container
19
	 */
20
	public function __construct( $name, Container $container ) {
21
		parent::__construct( $name, $container );
22
	}
23
24
    /**
25
     * @inheritdoc
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('nat:infos')
31
            ->setDescription('Read NAT infos')
32
            ->setHelp("This command allows you to read livebox NAT infos")
33
        ;
34
35
        parent::configure();
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
44
	    $ymlFile = $this->getConfigurationFile( $input );
45
46
	    if ( $ymlFile !== NULL && is_file( $ymlFile ) ) {
47
48
		    // Structures check and configuration loading
49
		    $configurationManager = new ConfigurationManager( $ymlFile );
50
		    $configuration        = $configurationManager->load();
51
52
			// Authentication
53
			$this->tools->authenticate(
54
				$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ],
55
				$configuration[ AppConf::USER[ AppConf::NODE_NAME ] ],
56
				$configuration[ AppConf::PASSWORD ]
57
			);
58
59
		    // Execute request
60
		    $response = $this->tools->createRequest(
61
			    Request::METHOD_POST,
62
			    "{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws",
63
			    [
64
				    "service"    => "Firewall",
65
				    "method"     => "getPortForwarding",
66
				    "parameters" => ['origin' => 'webui'],
67
			    ]
68
		    );
69
		    $output->write($response->getContent() );
70
71
		    // Handle post command stuff
72
		    parent::execute( $input, $output );
73
	    }
74
    }
75
}