Conditions | 13 |
Paths | 216 |
Total Lines | 57 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
92 | #[\Override] |
||
93 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
||
94 | $helper = new QuestionHelper(); |
||
95 | $fields = self::SCHEMA['fields']; |
||
96 | $fields = array_combine(array_column($fields, 'field'), $fields); |
||
97 | $sender = ''; |
||
98 | while (empty($sender) or substr_count($sender, '@') !== 1) { |
||
99 | $senderQuestion = new Question($fields['sender']['prompt'] . ' '); |
||
100 | $sender = $helper->ask($input, $output, $senderQuestion); |
||
101 | if (empty($sender)) { |
||
102 | $output->writeln('XMPP-JID must not be empty!'); |
||
103 | } elseif (substr_count($sender, '@') !== 1) { |
||
104 | $output->writeln('XMPP-JID not valid!'); |
||
105 | } else { |
||
106 | $username = explode('@', $sender)[0]; |
||
107 | } |
||
108 | } |
||
109 | $output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
||
110 | $password = ''; |
||
111 | while (empty($password)) { |
||
112 | $passwordQuestion = new Question($fields['password']['prompt'] . ' '); |
||
113 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
114 | if (empty($password)) { |
||
115 | $output->writeln('Password must not be empty!'); |
||
116 | } |
||
117 | } |
||
118 | $output->writeln('Password accepted.'); |
||
119 | $server = ''; |
||
120 | while (empty($server)) { |
||
121 | $serverQuestion = new Question($fields['server']['prompt'] . ' '); |
||
122 | $server = $helper->ask($input, $output, $serverQuestion); |
||
123 | if (empty($server)) { |
||
124 | $output->writeln('API path must not be empty!'); |
||
125 | } |
||
126 | } |
||
127 | $output->writeln("Using $server as full URL to access REST/HTTP API."); |
||
128 | $method = 0; |
||
129 | while (intval($method) < 1 or intval($method) > 2) { |
||
130 | echo $fields['method']['prompt'] . PHP_EOL; |
||
131 | echo "(1) prosody with mod_rest\n"; |
||
132 | echo "(2) prosody with mod_post_msg\n"; |
||
133 | $methodQuestion = new Question('Your choice: '); |
||
134 | $method = $helper->ask($input, $output, $methodQuestion); |
||
135 | } |
||
136 | if ($method === '1') { |
||
137 | $output->writeln('Using prosody with mod_rest as XMPP sending option.'); |
||
138 | } elseif ($method === '2') { |
||
139 | $output->writeln('Using prosody with mod_post_msg as XMPP sending option.'); |
||
140 | } |
||
141 | $output->writeln('XMPP Admin Configuration finished.'); |
||
142 | |||
143 | $this->setSender($sender); |
||
144 | $this->setPassword($password); |
||
145 | $this->setServer($server); |
||
146 | $this->setUsername($username); |
||
147 | $this->setMethod($method); |
||
148 | return 0; |
||
149 | } |
||
151 |