Conditions | 8 |
Paths | 34 |
Total Lines | 78 |
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 |
||
99 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
100 | |||
101 | $options = $input->getOptions(); |
||
102 | unset($options['output']); |
||
103 | if (empty(array_filter($options))) { |
||
104 | $this->syncService->syncAll(); |
||
105 | $output->writeln('- Sync done'); |
||
106 | |||
107 | return 0; |
||
108 | } |
||
109 | |||
110 | if ($input->getOption('migration')) { |
||
111 | // TODO: lock using setAppValue() to avoid duplicate process |
||
112 | if (!$this->syncService->migration()) { |
||
113 | throw new MigrationTo22Exception('Migration already performed successfully'); |
||
114 | } |
||
115 | $output->writeln('- Migration went smoothly, enjoy using Circles 22!'); |
||
116 | } |
||
117 | |||
118 | if ($input->getOption('users')) { |
||
119 | $this->syncService->syncNextcloudUsers(); |
||
120 | $output->writeln('- Nextcloud Users synced'); |
||
121 | } |
||
122 | |||
123 | if (($userId = $input->getOption('user')) !== '') { |
||
124 | $federatedUser = $this->syncService->syncNextcloudUser($userId); |
||
125 | $output->writeln( |
||
126 | '- Nextcloud User <info>' . $userId . '</info>/<info>' . $federatedUser->getSingleId() |
||
127 | . '</info> synced' |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | if ($input->getOption('groups')) { |
||
132 | $this->syncService->syncNextcloudGroups(); |
||
133 | $output->writeln('- Nextcloud Groups synced'); |
||
134 | } |
||
135 | |||
136 | if (($groupId = $input->getOption('group')) !== '') { |
||
137 | $circle = $this->syncService->syncNextcloudGroup($groupId); |
||
138 | $output->writeln( |
||
139 | '- Nextcloud Group <info>' . $groupId . '</info>/<info>' . $circle->getSingleId() |
||
140 | . '</info> synced' |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | |||
145 | // |
||
146 | |||
147 | |||
148 | // echo json_encode(array_filter($options), JSON_PRETTY_PRINT) . "\n"; |
||
149 | // $output->writeln(json_encode($result), JSON_PRETTY_PRINT); |
||
150 | |||
151 | // if ($input->getOption('broadcast')) { |
||
152 | // |
||
153 | // return 0; |
||
154 | // } |
||
155 | // |
||
156 | // $circleId = (string)$input->getArgument('circle_id'); |
||
157 | // $instance = $input->getOption('instance'); |
||
158 | // if ($instance === '') { |
||
159 | // try { |
||
160 | // $circle = $this->circleService->getCircle($circleId); |
||
161 | // } catch (CircleNotFoundException $e) { |
||
162 | // throw new CircleNotFoundException( |
||
163 | // 'unknown circle, use --instance to retrieve the data from a remote instance' |
||
164 | // ); |
||
165 | // } |
||
166 | // $instance = $circle->getInstance(); |
||
167 | // } |
||
168 | // |
||
169 | // if ($this->configService->isLocalInstance($instance)) { |
||
170 | // throw new RemoteNotFoundException('Circle is local'); |
||
171 | // } |
||
172 | // |
||
173 | // $this->remoteService->syncRemoteCircle($circleId, $instance); |
||
174 | |||
175 | return 0; |
||
176 | } |
||
177 | |||
180 |