Conditions | 6 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | protected function execute(InputInterface $input, OutputInterface $output) |
||
51 | { |
||
52 | |||
53 | $ymlFile = $this->getConfigurationFile( $input ); |
||
54 | |||
55 | if ( $ymlFile !== NULL && is_file( $ymlFile ) ) { |
||
56 | |||
57 | // Structures check and configuration loading |
||
58 | $configurationManager = new ConfigurationManager( $ymlFile ); |
||
59 | $configuration = $configurationManager->load(); |
||
60 | |||
61 | |||
62 | // Authentication |
||
63 | $this->tools->authenticate( |
||
64 | $configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ], |
||
65 | $configuration[ AppConf::USER[ AppConf::NODE_NAME ] ], |
||
66 | $configuration[ AppConf::PASSWORD ] |
||
67 | ); |
||
68 | |||
69 | $ruleId = $input->getArgument( static::ARGUMENT_ID ); |
||
70 | |||
71 | $response = $this->getRunOutput(new ArrayInput([ |
||
72 | 'command' => 'nat:infos', |
||
73 | ])); |
||
74 | |||
75 | $json = json_decode($response); |
||
76 | |||
77 | if (!empty($json->result) && !empty($json->result->status)) { |
||
78 | $natRules = $json->result->status; |
||
79 | $fullName = NatRule::ORIGIN . '_' . $ruleId; |
||
80 | if (isset($natRules->$fullName)) { |
||
81 | $natRule = NatRule::buildFrom($natRules->$fullName); |
||
82 | |||
83 | |||
84 | // Execute request |
||
85 | $response = $this->tools->createRequest( |
||
86 | Request::METHOD_POST, |
||
87 | "{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws", |
||
88 | [ |
||
89 | "service" => "Firewall", |
||
90 | "method" => "deletePortForwarding", |
||
91 | "parameters" => $natRule->getOutputForDelete() |
||
92 | ] |
||
93 | ); |
||
94 | $output->write($response->getContent() ); |
||
95 | } else { |
||
96 | throw new InvalidOptionException( "Id argument invalid, can't find it in existing NAT rules." ); |
||
97 | } |
||
98 | } else { |
||
99 | throw new LogicException('Wrong format from nat:infos command'); |
||
100 | } |
||
101 | |||
102 | // Handle post command stuff |
||
103 | parent::execute( $input, $output ); |
||
104 | } |
||
106 | } |