Conditions | 6 |
Paths | 5 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
55 | protected function execute( InputInterface $input, OutputInterface $output ) { |
||
56 | |||
57 | $ymlFile = $this->getConfigurationFile( $input ); |
||
58 | |||
59 | if ( $ymlFile !== NULL && is_file( $ymlFile ) ) { |
||
60 | |||
61 | // Structures check and configuration loading |
||
62 | $configurationManager = new ConfigurationManager( $ymlFile ); |
||
63 | $configuration = $configurationManager->load(); |
||
64 | |||
65 | // Authentication |
||
66 | $this->tools->authenticate( |
||
67 | $configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ], |
||
68 | $configuration[ AppConf::USER[ AppConf::NODE_NAME ] ], |
||
69 | $configuration[ AppConf::PASSWORD ] |
||
70 | ); |
||
71 | |||
72 | // Get status |
||
73 | if ( $input->hasArgument( static::STATUS ) ) { |
||
74 | |||
75 | $status = $input->getArgument( static::STATUS ); |
||
76 | switch ( $status ) { |
||
77 | case static::ON: |
||
78 | $parameters = [ |
||
79 | "Enable" => "True", |
||
80 | ]; |
||
81 | break; |
||
82 | case static::OFF: |
||
83 | $parameters = [ |
||
84 | "Enable" => "False", |
||
85 | ]; |
||
86 | break; |
||
87 | default: |
||
88 | throw new InvalidOptionException( "Status argument get only \"on\" or \"off\" value." ); |
||
89 | } |
||
90 | |||
91 | // Execute request |
||
92 | $response = $this->tools->createRequest( |
||
93 | Request::METHOD_POST, |
||
94 | "{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws", |
||
95 | [ |
||
96 | "service" => "NMC.Wifi", |
||
97 | "method" => "set", |
||
98 | "parameters" => $parameters, |
||
99 | ] |
||
100 | ); |
||
101 | |||
102 | $output->write( $response->getContent() ); |
||
103 | |||
104 | } |
||
105 | |||
106 | |||
107 | // Handle post command stuff |
||
108 | parent::execute( $input, $output ); |
||
109 | } else { |
||
110 | $output->writeln( "<error>Filename is not correct : {$ymlFile}</error>" ); |
||
111 | $this->log->addError( "Filename is not correct : {$ymlFile}" ); |
||
112 | } |
||
115 | } |