| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| 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 |
||
| 57 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 58 | { |
||
| 59 | $io = new SymfonyStyle($input, $output); |
||
| 60 | |||
| 61 | $icsCalendarUri = $input->getArgument('icsCalendarUri'); |
||
| 62 | $pid = $input->getArgument('pid'); |
||
| 63 | |||
| 64 | if (!\filter_var($icsCalendarUri, FILTER_VALIDATE_URL)) { |
||
| 65 | $io->error('You have to enter a valid URL to the iCalendar ICS'); |
||
| 66 | |||
| 67 | return 1; |
||
| 68 | } |
||
| 69 | if (!MathUtility::canBeInterpretedAsInteger($pid)) { |
||
| 70 | $io->error('You have to enter a valid PID for the new created elements'); |
||
| 71 | |||
| 72 | return 2; |
||
| 73 | } |
||
| 74 | $pid = (int)$pid; |
||
| 75 | |||
| 76 | // fetch external URI and write to file |
||
| 77 | $io->section('Start to checkout the calendar: ' . $icsCalendarUri); |
||
| 78 | $relativeIcalFile = 'typo3temp/ical.' . GeneralUtility::shortMD5($icsCalendarUri) . '.ical'; |
||
|
|
|||
| 79 | $absoluteIcalFile = GeneralUtility::getFileAbsFileName($relativeIcalFile); |
||
| 80 | $content = GeneralUtility::getUrl($icsCalendarUri); |
||
| 81 | GeneralUtility::writeFile($absoluteIcalFile, $content); |
||
| 82 | |||
| 83 | $events = $this->iCalService->getEvents($absoluteIcalFile); |
||
| 84 | |||
| 85 | $io->text('Found ' . \count($events) . ' events in ' . $icsCalendarUri); |
||
| 86 | |||
| 87 | $signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class); |
||
| 88 | |||
| 89 | $io->section('Send the ' . __CLASS__ . '::importCommand signal for each event.'); |
||
| 90 | $io->progressStart(\count($events)); |
||
| 91 | foreach ($events as $event) { |
||
| 92 | $arguments = [ |
||
| 93 | 'event' => $event, |
||
| 94 | 'io' => $io, |
||
| 95 | 'pid' => $pid, |
||
| 96 | 'handled' => false, |
||
| 97 | ]; |
||
| 98 | $signalSlotDispatcher->dispatch(__CLASS__, 'importCommand', $arguments); |
||
| 99 | $io->progressAdvance(); |
||
| 100 | } |
||
| 101 | $io->progressFinish(); |
||
| 102 | |||
| 103 | $io->section('Run Reindex proces after import'); |
||
| 104 | $indexer = GeneralUtility::makeInstance(IndexerService::class); |
||
| 105 | $indexer->reindexAll(); |
||
| 106 | |||
| 107 | return 0; |
||
| 108 | } |
||
| 109 | |||
| 111 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.