Conditions | 5 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
91 | protected function execute(InputInterface $input, OutputInterface $output) |
||
92 | { |
||
93 | $bulkCount = $input->getArgument('bulk_count'); |
||
94 | // Indexing Content |
||
95 | $totalCount = $this->getContentObjectsTotalCount( |
||
96 | $this->databaseHandler, ContentInfo::STATUS_PUBLISHED |
||
97 | ); |
||
98 | |||
99 | $query = $this->databaseHandler->createSelectQuery(); |
||
100 | $query->select('id', 'current_version') |
||
101 | ->from('ezcontentobject') |
||
102 | ->where($query->expr->eq('status', ContentInfo::STATUS_PUBLISHED)); |
||
103 | |||
104 | $stmt = $query->prepare(); |
||
105 | $stmt->execute(); |
||
106 | |||
107 | $this->searchHandler->purgeIndex(); |
||
108 | |||
109 | $output->writeln('Indexing Content...'); |
||
110 | |||
111 | /* @var \Symfony\Component\Console\Helper\ProgressHelper $progress */ |
||
112 | $progress = $this->getHelperSet()->get('progress'); |
||
113 | $progress->start($output, $totalCount); |
||
114 | $i = 0; |
||
115 | do { |
||
116 | $contentObjects = []; |
||
117 | for ($k = 0; $k <= $bulkCount; ++$k) { |
||
118 | if (!$row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
||
119 | break; |
||
120 | } |
||
121 | try { |
||
122 | $contentObjects[] = $this->persistenceHandler->contentHandler()->load( |
||
123 | $row['id'], |
||
124 | $row['current_version'] |
||
125 | ); |
||
126 | } catch (NotFoundException $e) { |
||
127 | $this->logWarning($output, $progress, "Could not load current version of Content with id ${row['id']}, so skipped for indexing. Full exception: " . $e->getMessage()); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | $this->searchHandler->bulkIndex( |
||
132 | $contentObjects, |
||
133 | function (Content $content, NotFoundException $e) use ($output, $progress) { |
||
134 | $this->logWarning($output, $progress, 'Content with id ' . $content->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage() |
||
135 | ); |
||
136 | } |
||
137 | ); |
||
138 | |||
139 | $progress->advance($k); |
||
140 | } while (($i += $bulkCount) < $totalCount); |
||
141 | |||
142 | $progress->finish(); |
||
143 | } |
||
144 | |||
182 |