| Conditions | 15 |
| Paths | 1285 |
| Total Lines | 119 |
| Code Lines | 78 |
| 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 |
||
| 72 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 73 | { |
||
| 74 | if ($input->getOption('list-io-configs')) { |
||
| 75 | $this->outputConfiguredHandlers($output); |
||
| 76 | |||
| 77 | return; |
||
| 78 | } |
||
| 79 | |||
| 80 | $output->writeln($this->getProcessedHelp()); |
||
| 81 | |||
| 82 | $fromHandlers = $input->getOption('from') ? explode(',', $input->getOption('from')) : null; |
||
| 83 | $toHandlers = $input->getOption('to') ? explode(',', $input->getOption('to')) : null; |
||
| 84 | if (!$this->areHandlerOptionsValid($fromHandlers, $toHandlers, $output)) { |
||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | if (!$fromHandlers) { |
||
| 89 | $fromHandlers = ['default', 'default']; |
||
| 90 | } |
||
| 91 | if (!$toHandlers) { |
||
| 92 | $toHandlers = [ |
||
| 93 | array_keys($this->configuredMetadataHandlers)[0], |
||
| 94 | array_keys($this->configuredBinarydataHandlers)[0] |
||
| 95 | ]; |
||
| 96 | } |
||
| 97 | |||
| 98 | $output->writeln([ |
||
| 99 | "Migrating from '$fromHandlers[0],$fromHandlers[1]' to '$toHandlers[0],$toHandlers[1]'", |
||
| 100 | '', |
||
| 101 | ]); |
||
| 102 | |||
| 103 | $binaryFilesCount = $mediaFilesCount = $imageFilesCount = 0; |
||
| 104 | if (!$input->getOption('skip-binary-files')) { |
||
| 105 | //TODO |
||
| 106 | $binaryFilesCount = $this->migrationHandlerRegistry |
||
|
|
|||
| 107 | ->getItem('ezpublish.core.io.migration_handler.binary_file') |
||
| 108 | ->countFiles($fromHandlers[0], $fromHandlers[1]); |
||
| 109 | } |
||
| 110 | if (!$input->getOption('skip-media-files')) { |
||
| 111 | //TODO |
||
| 112 | $mediaFilesCount = $this->migrationHandlerRegistry |
||
| 113 | ->getItem('ezpublish.core.io.migration_handler.media_file') |
||
| 114 | ->countFiles($fromHandlers[0], $fromHandlers[1]); |
||
| 115 | } |
||
| 116 | if (!$input->getOption('skip-image-files')) { |
||
| 117 | //TODO |
||
| 118 | $imageFilesCount = $this->migrationHandlerRegistry |
||
| 119 | ->getItem('ezpublish.core.io.migration_handler.image_file') |
||
| 120 | ->countFiles($fromHandlers[0], $fromHandlers[1]); |
||
| 121 | } |
||
| 122 | |||
| 123 | $totalCount = $binaryFilesCount + $mediaFilesCount + $imageFilesCount; |
||
| 124 | $output->writeln([ |
||
| 125 | "Found total files to update: $totalCount", |
||
| 126 | "(binary files: $binaryFilesCount, media files: $mediaFilesCount, image files: $imageFilesCount)", |
||
| 127 | '', |
||
| 128 | ]); |
||
| 129 | |||
| 130 | if ($totalCount == 0) { |
||
| 131 | $output->writeln('Nothing to process.'); |
||
| 132 | |||
| 133 | return; |
||
| 134 | } |
||
| 135 | |||
| 136 | $helper = $this->getHelper('question'); |
||
| 137 | $question = new ConfirmationQuestion( |
||
| 138 | '<question>Are you sure you want to proceed?</question> ', |
||
| 139 | false |
||
| 140 | ); |
||
| 141 | |||
| 142 | if (!$helper->ask($input, $output, $question)) { |
||
| 143 | $output->writeln('Aborting.'); |
||
| 144 | |||
| 145 | return; |
||
| 146 | } |
||
| 147 | |||
| 148 | $bulkCount = $input->getOption('bulk-count'); |
||
| 149 | $dryRun = $input->getOption('dry-run'); |
||
| 150 | |||
| 151 | if (!$input->getOption('skip-binary-files')) { |
||
| 152 | $output->writeln('Migrating binary files'); |
||
| 153 | //TODO |
||
| 154 | $this->migrateFiles( |
||
| 155 | $this->migrationHandlerRegistry->getItem('ezpublish.core.io.migration_handler.binary_file'), |
||
| 156 | $binaryFilesCount, |
||
| 157 | $bulkCount, |
||
| 158 | $dryRun, |
||
| 159 | $fromHandlers, |
||
| 160 | $toHandlers, |
||
| 161 | $output |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | if (!$input->getOption('skip-media-files')) { |
||
| 165 | $output->writeln('Migrating media files'); |
||
| 166 | //TODO |
||
| 167 | $this->migrateFiles( |
||
| 168 | $this->migrationHandlerRegistry->getItem('ezpublish.core.io.migration_handler.media_file'), |
||
| 169 | $mediaFilesCount, |
||
| 170 | $bulkCount, |
||
| 171 | $dryRun, |
||
| 172 | $fromHandlers, |
||
| 173 | $toHandlers, |
||
| 174 | $output |
||
| 175 | ); |
||
| 176 | } |
||
| 177 | if (!$input->getOption('skip-image-files')) { |
||
| 178 | $output->writeln('Migrating image files'); |
||
| 179 | //TODO |
||
| 180 | $this->migrateFiles( |
||
| 181 | $this->migrationHandlerRegistry->getItem('ezpublish.core.io.migration_handler.image_file'), |
||
| 182 | $imageFilesCount, |
||
| 183 | $bulkCount, |
||
| 184 | $dryRun, |
||
| 185 | $fromHandlers, |
||
| 186 | $toHandlers, |
||
| 187 | $output |
||
| 188 | ); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 332 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: