| Conditions | 8 | 
| Paths | 12 | 
| Total Lines | 75 | 
| 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  | 
            ||
| 97 | protected function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 98 |     { | 
            ||
| 99 | $io = new SymfonyStyle($input, $output);  | 
            ||
| 100 | |||
| 101 |         $icsCalendarUri = (string)$input->getArgument('icsCalendarUri'); | 
            ||
| 102 |         if (!GeneralUtility::isValidUrl($icsCalendarUri)) { | 
            ||
| 103 |             $io->error('You have to enter a valid URL to the iCalendar ICS'); | 
            ||
| 104 | return 1;  | 
            ||
| 105 | }  | 
            ||
| 106 | |||
| 107 |         $pid = $input->getArgument('pid'); | 
            ||
| 108 |         if (!MathUtility::canBeInterpretedAsInteger($pid)) { | 
            ||
| 109 |             $io->error('You have to enter a valid PID for the new created elements'); | 
            ||
| 110 | return 1;  | 
            ||
| 111 | }  | 
            ||
| 112 | $pid = (int)$pid;  | 
            ||
| 113 | |||
| 114 | // Process skip  | 
            ||
| 115 |         $since = $input->getOption('since'); | 
            ||
| 116 | $ignoreBeforeDate = null;  | 
            ||
| 117 |         if ($since !== null) { | 
            ||
| 118 | $ignoreBeforeDate = new \DateTime($since);  | 
            ||
| 119 |             $io->text('Skipping all events before ' . $ignoreBeforeDate->format(\DateTimeInterface::ATOM)); | 
            ||
| 120 | }  | 
            ||
| 121 | |||
| 122 | // Fetch external URI and write it to a temporary file  | 
            ||
| 123 |         $io->section('Start to checkout the calendar'); | 
            ||
| 124 | |||
| 125 | $content = GeneralUtility::getUrl($icsCalendarUri);  | 
            ||
| 126 |         if ($content === false) { | 
            ||
| 127 |             $io->error('Unable to get the content of ' . $icsCalendarUri . '.'); | 
            ||
| 128 | return 1;  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | $icalFile = Environment::getVarPath() . '/transient/.' . 'ical-' . GeneralUtility::shortMD5($icsCalendarUri) . '.ics';  | 
            ||
| 132 | $tempResult = GeneralUtility::writeFileToTypo3tempDir($icalFile, $content);  | 
            ||
| 133 |         if ($tempResult !== null) { | 
            ||
| 134 |             $io->error('Unable to write to "' . $icalFile . '". Reason: ' . $tempResult); | 
            ||
| 135 | return 1;  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 138 | // Parse calendar  | 
            ||
| 139 | $events = $this->iCalService->getEvents($icalFile);  | 
            ||
| 140 | |||
| 141 | // Remove temporary file  | 
            ||
| 142 | unlink($icalFile);  | 
            ||
| 143 | |||
| 144 |         $io->text('Found ' . \count($events) . ' events in ' . $icsCalendarUri); | 
            ||
| 145 | |||
| 146 |         $io->section('Send ImportSingleIcalEvent for each event'); | 
            ||
| 147 | $io->progressStart(\count($events));  | 
            ||
| 148 | |||
| 149 | $skipCount = $dispatchCount = 0;  | 
            ||
| 150 |         foreach ($events as $event) { | 
            ||
| 151 | // Skip events before given date  | 
            ||
| 152 |             if (($event->getEndDate() ?? $event->getStartDate()) < $ignoreBeforeDate) { | 
            ||
| 153 | $io->progressAdvance();  | 
            ||
| 154 | $skipCount++;  | 
            ||
| 155 | continue;  | 
            ||
| 156 | }  | 
            ||
| 157 | |||
| 158 | $this->eventDispatcher->dispatch(new ImportSingleIcalEvent($event, $pid));  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 159 | $dispatchCount++;  | 
            ||
| 160 | $io->progressAdvance();  | 
            ||
| 161 | }  | 
            ||
| 162 | $io->progressFinish();  | 
            ||
| 163 | |||
| 164 |         $io->text('Dispatched ' . $dispatchCount . ' Events'); | 
            ||
| 165 |         $io->text('Skipped ' . $skipCount . ' Events'); | 
            ||
| 166 | |||
| 167 |         $io->section('Run Reindex process after import'); | 
            ||
| 168 | $this->indexerService->reindexAll();  | 
            ||
| 169 | |||
| 170 | return 0;  | 
            ||
| 171 | }  | 
            ||
| 172 | }  | 
            ||
| 173 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: