| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 101 |
| Code Lines | 66 |
| 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 |
||
| 89 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 90 | { |
||
| 91 | $config = []; |
||
| 92 | $options = []; |
||
| 93 | $messageOpt = ''; |
||
| 94 | |||
| 95 | if ($input->getOption('baseurl')) { |
||
| 96 | $config['baseurl'] = $input->getOption('baseurl'); |
||
| 97 | } |
||
| 98 | if ($input->getOption('output')) { |
||
| 99 | $config['output']['dir'] = $input->getOption('output'); |
||
| 100 | if ($input->getOption('output') != self::SERVE_OUTPUT) { |
||
| 101 | Util\File::getFS()->dumpFile(Util::joinFile($this->getPath(), self::TMP_DIR, 'output'), (string) $input->getOption('output')); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | if ($input->getOption('optimize') === true) { |
||
| 105 | $config['optimize']['enabled'] = true; |
||
| 106 | } |
||
| 107 | if ($input->getOption('optimize') === false) { |
||
| 108 | $config['optimize']['enabled'] = false; |
||
| 109 | } |
||
| 110 | if ($input->getOption('clear-cache') === null) { |
||
| 111 | $config['cache']['enabled'] = false; |
||
| 112 | } |
||
| 113 | |||
| 114 | $builder = $this->getBuilder($config); |
||
| 115 | |||
| 116 | if ($input->getOption('drafts')) { |
||
| 117 | $options['drafts'] = true; |
||
| 118 | $messageOpt .= ' with drafts'; |
||
| 119 | } |
||
| 120 | if ($input->getOption('dry-run')) { |
||
| 121 | $options['dry-run'] = true; |
||
| 122 | $messageOpt .= ' (dry-run)'; |
||
| 123 | } |
||
| 124 | if ($input->getOption('page')) { |
||
| 125 | $options['page'] = $input->getOption('page'); |
||
| 126 | } |
||
| 127 | if ($input->getOption('render-subset')) { |
||
| 128 | $options['render-subset'] = (string) $input->getOption('render-subset'); |
||
| 129 | } |
||
| 130 | if ($input->getOption('clear-cache')) { |
||
| 131 | if (0 < $removedFiles = (new \Cecil\Cache($this->getBuilder()))->clearByPattern((string) $input->getOption('clear-cache'))) { |
||
| 132 | $output->writeln(\sprintf('<info>%s cache files removed by regular expression "%s"</info>', $removedFiles, $input->getOption('clear-cache'))); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $output->writeln(\sprintf('Building website%s...', $messageOpt)); |
||
| 137 | $output->writeln(\sprintf('<comment>Path: %s</comment>', $this->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE); |
||
| 138 | if (!empty($this->getConfigFiles())) { |
||
| 139 | $output->writeln(\sprintf('<comment>Config: %s</comment>', implode(', ', $this->getConfigFiles())), OutputInterface::VERBOSITY_VERY_VERBOSE); |
||
| 140 | } |
||
| 141 | $output->writeln(\sprintf('<comment>Output: %s</comment>', $this->getBuilder()->getConfig()->getOutputPath()), OutputInterface::VERBOSITY_VERY_VERBOSE); |
||
| 142 | if ($builder->getConfig()->isEnabled('cache') !== false) { |
||
| 143 | $output->writeln(\sprintf('<comment>Cache: %s</comment>', $builder->getConfig()->getCachePath()), OutputInterface::VERBOSITY_VERY_VERBOSE); |
||
| 144 | } |
||
| 145 | |||
| 146 | // build |
||
| 147 | $builder->build($options); |
||
| 148 | $output->writeln('Done 🎉'); |
||
| 149 | |||
| 150 | // show build steps metrics |
||
| 151 | if ($input->getOption('metrics')) { |
||
| 152 | $table = new Table($output); |
||
| 153 | $table |
||
| 154 | ->setHeaderTitle('Build steps metrics') |
||
| 155 | ->setHeaders(['Step', 'Duration', 'Memory']) |
||
| 156 | ->setRows($builder->getMetrics()['steps']) |
||
| 157 | ; |
||
| 158 | $table->setStyle('box')->render(); |
||
| 159 | } |
||
| 160 | |||
| 161 | // show built pages as table |
||
| 162 | if ($input->getOption('show-pages')) { |
||
| 163 | $pagesAsArray = []; |
||
| 164 | foreach ( |
||
| 165 | $this->getBuilder()->getPages()->filter(function (\Cecil\Collection\Page\Page $page) { |
||
| 166 | return $page->getVariable('published'); |
||
| 167 | })->usort(function (\Cecil\Collection\Page\Page $pageA, \Cecil\Collection\Page\Page $pageB) { |
||
| 168 | return strnatcmp((string) $pageA['language'], (string) $pageB['language']); |
||
| 169 | }) as $page |
||
| 170 | ) { |
||
| 171 | /** @var \Cecil\Collection\Page\Page $page */ |
||
| 172 | $pagesAsArray[] = [ |
||
| 173 | $page->getId(), |
||
| 174 | $page->getVariable('language'), |
||
| 175 | \sprintf("%s %s", $page->getType(), $page->getType() !== \Cecil\Collection\Page\Type::PAGE->value ? "(" . \count($page->getPages() ?: []) . ")" : ''), |
||
| 176 | $page->getSection(), |
||
| 177 | $page->isVirtual() ? 'true' : 'false', |
||
| 178 | ]; |
||
| 179 | } |
||
| 180 | $table = new Table($output); |
||
| 181 | $table |
||
| 182 | ->setHeaderTitle(\sprintf("Built pages (%s)", \count($pagesAsArray))) |
||
| 183 | ->setHeaders(['ID', 'Lang', 'Type', 'Section', 'Virtual']) |
||
| 184 | ->setRows($pagesAsArray) |
||
| 185 | ; |
||
| 186 | $table->setStyle('box')->render(); |
||
| 187 | } |
||
| 188 | |||
| 189 | return 0; |
||
| 190 | } |
||
| 192 |