| Conditions | 4 | 
| Paths | 4 | 
| Total Lines | 54 | 
| 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  | 
            ||
| 40 | protected function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 41 |     { | 
            ||
| 42 | $io = new SymfonyStyle($input, $output);  | 
            ||
| 43 | |||
| 44 |         $icsCalendarUri = $input->getArgument('icsCalendarUri'); | 
            ||
| 45 |         $pid = $input->getArgument('pid'); | 
            ||
| 46 | |||
| 47 |         if (!\filter_var($icsCalendarUri, FILTER_VALIDATE_URL)) { | 
            ||
| 48 |             $io->error('You have to enter a valid URL to the iCalendar ICS'); | 
            ||
| 49 | |||
| 50 | return 1;  | 
            ||
| 51 | }  | 
            ||
| 52 |         if (!MathUtility::canBeInterpretedAsInteger($pid)) { | 
            ||
| 53 |             $io->error('You have to enter a valid PID for the new created elements'); | 
            ||
| 54 | |||
| 55 | return 2;  | 
            ||
| 56 | }  | 
            ||
| 57 | $pid = (int)$pid;  | 
            ||
| 58 | |||
| 59 | // fetch external URI and write to file  | 
            ||
| 60 |         $io->section('Start to checkout the calendar: ' . $icsCalendarUri); | 
            ||
| 61 | $relativeIcalFile = 'typo3temp/ical.' . GeneralUtility::shortMD5($icsCalendarUri) . '.ical';  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 62 | $absoluteIcalFile = GeneralUtility::getFileAbsFileName($relativeIcalFile);  | 
            ||
| 63 | $content = GeneralUtility::getUrl($icsCalendarUri);  | 
            ||
| 64 | GeneralUtility::writeFile($absoluteIcalFile, $content);  | 
            ||
| 65 | |||
| 66 | // get Events from file  | 
            ||
| 67 | $icalEvents = $this->getIcalEvents($absoluteIcalFile);  | 
            ||
| 68 | $events = $this->prepareEvents($icalEvents, $io);  | 
            ||
| 69 | |||
| 70 |         $io->text('Found ' . \count($events) . ' events in ' . $icsCalendarUri); | 
            ||
| 71 | |||
| 72 | $signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class);  | 
            ||
| 73 | |||
| 74 |         $io->section('Send the ' . __CLASS__ . '::importCommand signal for each event.'); | 
            ||
| 75 | $io->progressStart(\count($events));  | 
            ||
| 76 |         foreach ($events as $event) { | 
            ||
| 77 | $arguments = [  | 
            ||
| 78 | 'event' => $event,  | 
            ||
| 79 | 'io' => $io,  | 
            ||
| 80 | 'pid' => $pid,  | 
            ||
| 81 | 'handled' => false,  | 
            ||
| 82 | ];  | 
            ||
| 83 | $signalSlotDispatcher->dispatch(__CLASS__, 'importCommand', $arguments);  | 
            ||
| 84 | $io->progressAdvance();  | 
            ||
| 85 | }  | 
            ||
| 86 | $io->progressFinish();  | 
            ||
| 87 | |||
| 88 |         $io->section('Run Reindex proces after import'); | 
            ||
| 89 | $indexer = GeneralUtility::makeInstance(IndexerService::class);  | 
            ||
| 90 | $indexer->reindexAll();  | 
            ||
| 91 | |||
| 92 | return 0;  | 
            ||
| 93 | }  | 
            ||
| 94 | |||
| 154 | 
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.