| Conditions | 5 | 
| Paths | 2 | 
| Total Lines | 58 | 
| Lines | 13 | 
| Ratio | 22.41 % | 
| 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  | 
            ||
| 93 | protected function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 94 |     { | 
            ||
| 95 | @trigger_error(  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 96 |             sprintf('%s is deprecated since 6.7. Use ezplatform:reindex command instead', $this->getName()), | 
            ||
| 97 | E_USER_DEPRECATED  | 
            ||
| 98 | );  | 
            ||
| 99 | |||
| 100 |         $bulkCount = $input->getArgument('bulk_count'); | 
            ||
| 101 | // Indexing Content  | 
            ||
| 102 | $totalCount = $this->getContentObjectsTotalCount(  | 
            ||
| 103 | $this->databaseHandler, ContentInfo::STATUS_PUBLISHED  | 
            ||
| 104 | );  | 
            ||
| 105 | |||
| 106 | $query = $this->databaseHandler->createSelectQuery();  | 
            ||
| 107 |         $query->select('id', 'current_version') | 
            ||
| 108 |             ->from('ezcontentobject') | 
            ||
| 109 |             ->where($query->expr->eq('status', ContentInfo::STATUS_PUBLISHED)); | 
            ||
| 110 | |||
| 111 | $stmt = $query->prepare();  | 
            ||
| 112 | $stmt->execute();  | 
            ||
| 113 | |||
| 114 | $this->searchHandler->purgeIndex();  | 
            ||
| 115 | |||
| 116 |         $output->writeln('Indexing Content...'); | 
            ||
| 117 | |||
| 118 | /* @var \Symfony\Component\Console\Helper\ProgressHelper $progress */  | 
            ||
| 119 |         $progress = $this->getHelperSet()->get('progress'); | 
            ||
| 120 | $progress->start($output, $totalCount);  | 
            ||
| 121 | $i = 0;  | 
            ||
| 122 |         do { | 
            ||
| 123 | $contentObjects = [];  | 
            ||
| 124 | View Code Duplication |             for ($k = 0; $k <= $bulkCount; ++$k) { | 
            |
| 125 |                 if (!$row = $stmt->fetch(PDO::FETCH_ASSOC)) { | 
            ||
| 126 | break;  | 
            ||
| 127 | }  | 
            ||
| 128 |                 try { | 
            ||
| 129 | $contentObjects[] = $this->persistenceHandler->contentHandler()->load(  | 
            ||
| 130 | $row['id'],  | 
            ||
| 131 | $row['current_version']  | 
            ||
| 132 | );  | 
            ||
| 133 |                 } catch (NotFoundException $e) { | 
            ||
| 134 |                     $this->logWarning($output, $progress, "Could not load current version of Content with id ${row['id']}, so skipped for indexing. Full exception: " . $e->getMessage()); | 
            ||
| 135 | }  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 138 | $this->searchHandler->bulkIndex(  | 
            ||
| 139 | $contentObjects,  | 
            ||
| 140 |                 function (Content $content, NotFoundException $e) use ($output, $progress) { | 
            ||
| 141 | $this->logWarning($output, $progress, 'Content with id ' . $content->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage()  | 
            ||
| 142 | );  | 
            ||
| 143 | }  | 
            ||
| 144 | );  | 
            ||
| 145 | |||
| 146 | $progress->advance($k);  | 
            ||
| 147 | } while (($i += $bulkCount) < $totalCount);  | 
            ||
| 148 | |||
| 149 | $progress->finish();  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 189 | 
If you suppress an error, we recommend checking for the error condition explicitly: