Conditions | 6 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 31 |
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 |
||
52 | protected function execute(InputInterface $input, OutputInterface $output) |
||
53 | { |
||
54 | $ymlFile = $this->getConfigurationFile($input); |
||
55 | |||
56 | if ($ymlFile !== NULL && is_file($ymlFile)) { |
||
57 | |||
58 | // Structures check and configuration loading |
||
59 | $configurationManager = new ConfigurationManager($ymlFile); |
||
60 | $configuration = $configurationManager->load(); |
||
61 | |||
62 | |||
63 | // Authentication |
||
64 | $this->tools->authenticate( |
||
65 | $configuration[AppConf::HOST[AppConf::NODE_NAME]], |
||
66 | $configuration[AppConf::USER[AppConf::NODE_NAME]], |
||
67 | $configuration[AppConf::PASSWORD] |
||
68 | ); |
||
69 | |||
70 | $ruleId = $input->getOption(static::OPTION_ID); |
||
71 | |||
72 | $commandInput = new ArrayInput([ |
||
73 | 'command' => 'nat:infos', |
||
74 | '--file' => $input->getOption('file') |
||
75 | ]); |
||
76 | |||
77 | $response = $this->runAnotherCommand($commandInput, $input); |
||
78 | $json = json_decode($response); |
||
79 | |||
80 | if (!empty($json->result) && !empty($json->result->status)) { |
||
81 | $natRules = $json->result->status; |
||
82 | $fullName = NatRule::ORIGIN . '_' . $ruleId; |
||
83 | if (isset($natRules->$fullName)) { |
||
84 | $natRule = NatRule::buildFrom($natRules->$fullName); |
||
85 | |||
86 | // Execute request |
||
87 | $response = $this->tools->createRequest( |
||
88 | Request::METHOD_POST, |
||
89 | "{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws", |
||
90 | [ |
||
91 | "service" => "Firewall", |
||
92 | "method" => "deletePortForwarding", |
||
93 | "parameters" => $natRule->getOutputForDelete() |
||
94 | ] |
||
95 | ); |
||
96 | $output->write($response->getContent()); |
||
97 | } else { |
||
98 | throw new InvalidOptionException("Id argument invalid, can't find it in existing NAT rules."); |
||
99 | } |
||
100 | } else { |
||
101 | throw new LogicException('Wrong format from nat:infos command'); |
||
102 | } |
||
103 | |||
104 | // Handle post command stuff |
||
105 | parent::execute($input, $output); |
||
106 | } |
||
108 | } |