Conditions | 23 |
Paths | 324 |
Total Lines | 93 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
31 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
32 | { |
||
33 | $set = false; |
||
34 | |||
35 | $this->initConfiguration($input->getOption('configFile')); |
||
36 | |||
37 | if ($input->getOption('remote')) { |
||
38 | $value = $input->getOption('remote'); |
||
39 | |||
40 | if ($value == 'on' || $value == 'true' || $value === true) { |
||
41 | $value = true; |
||
42 | } else { |
||
43 | $value = false; |
||
44 | } |
||
45 | |||
46 | $output->writeln(""); |
||
47 | $output->writeln('Remote command mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
||
48 | |||
49 | $this->setRemoteEnabled($value); |
||
50 | |||
51 | $set = true; |
||
52 | } |
||
53 | |||
54 | if ($input->getOption('logfile')) { |
||
55 | $value = $input->getOption('logfile'); |
||
56 | |||
57 | if ($value == 'on' || $value == 'true' || $value === true) { |
||
58 | $value = true; |
||
59 | } else { |
||
60 | $value = false; |
||
61 | } |
||
62 | |||
63 | $output->writeln(""); |
||
64 | $output->writeln('Logfile mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
||
65 | |||
66 | $this->setLogfileEnabled($value); |
||
67 | |||
68 | $set = true; |
||
69 | } |
||
70 | |||
71 | if ($input->getOption('metrics')) { |
||
72 | $value = $input->getOption('metrics'); |
||
73 | |||
74 | if ($value == 'on' || $value == 'true' || $value === true) { |
||
75 | $value = true; |
||
76 | } else { |
||
77 | $value = false; |
||
78 | } |
||
79 | |||
80 | $output->writeln(""); |
||
81 | $output->writeln('Metrics collection mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
||
82 | |||
83 | $this->setCollectEnabled($value); |
||
84 | |||
85 | $set = true; |
||
86 | } |
||
87 | |||
88 | if ($input->getOption('smartCare')) { |
||
89 | $value = $input->getOption('smartCare'); |
||
90 | |||
91 | if ($value == 'on' || $value == 'true' || $value === true) { |
||
92 | $value = true; |
||
93 | } else { |
||
94 | $value = false; |
||
95 | } |
||
96 | |||
97 | $output->writeln(""); |
||
98 | $output->writeln('SmartCare mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
||
99 | |||
100 | $this->setSmartCareEnabled($value); |
||
101 | |||
102 | $set = true; |
||
103 | } |
||
104 | |||
105 | if ($input->getOption('serverApi')) { |
||
106 | $value = $input->getOption('serverApi'); |
||
107 | |||
108 | $output->writeln(""); |
||
109 | $output->writeln('Setting server API to : <info>' . $value . '</info>'); |
||
110 | |||
111 | $this->setServerApi($value); |
||
112 | |||
113 | $set = true; |
||
114 | } |
||
115 | |||
116 | if ($set) { |
||
117 | $output->writeln(""); |
||
118 | $this->getApplication()->find('collect')->run(new ArrayInput([]), $output); |
||
119 | $output->writeln(""); |
||
120 | $output->writeln('If you are running inventorio via SystemD please call: <info>systemctl restart inventorio.service</info>'); |
||
121 | } |
||
122 | |||
123 | return Command::SUCCESS; |
||
124 | } |
||
127 |