| Conditions | 6 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 27 |
| 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 |
||
| 49 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 50 | { |
||
| 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 | |||
| 61 | // Authentication |
||
| 62 | $this->tools->authenticate( |
||
| 63 | $configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ], |
||
| 64 | $configuration[ AppConf::USER[ AppConf::NODE_NAME ] ], |
||
| 65 | $configuration[ AppConf::PASSWORD ] |
||
| 66 | ); |
||
| 67 | |||
| 68 | $ruleId = $input->getArgument( static::ARGUMENT_ID ); |
||
| 69 | |||
| 70 | $response = $this->getRunOutput(new ArrayInput([ |
||
| 71 | 'command' => 'nat:infos', |
||
| 72 | ])); |
||
| 73 | |||
| 74 | $json = json_decode($response); |
||
| 75 | |||
| 76 | if (!empty($json->result) && !empty($json->result->status)) { |
||
| 77 | $natRules = $json->result->status; |
||
| 78 | $fullName = NatRule::ORIGIN . '_' . $ruleId; |
||
| 79 | if (isset($natRules->$fullName)) { |
||
| 80 | $natRule = NatRule::buildFrom($natRules->$fullName); |
||
| 81 | |||
| 82 | |||
| 83 | // Execute request |
||
| 84 | $response = $this->tools->createRequest( |
||
| 85 | Request::METHOD_POST, |
||
| 86 | "{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws", |
||
| 87 | [ |
||
| 88 | "service" => "Firewall", |
||
| 89 | "method" => "deletePortForwarding", |
||
| 90 | "parameters" => $natRule->getOutputForDelete() |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | $output->write($response->getContent() ); |
||
| 94 | } else { |
||
| 95 | throw new InvalidOptionException( "Id argument invalid, can't find it in existing NAT rules." ); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // Handle post command stuff |
||
| 100 | parent::execute( $input, $output ); |
||
| 101 | } |
||
| 103 | } |