| Conditions | 10 |
| Paths | 528 |
| Total Lines | 48 |
| 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 |
||
| 48 | public function processCommand() |
||
| 49 | { |
||
| 50 | $this->drafts = $this->getRoute()->getMatchedParam('drafts', false); |
||
| 51 | $this->verbose = $this->getRoute()->getMatchedParam('verbose', false); |
||
| 52 | $this->quiet = $this->getRoute()->getMatchedParam('quiet', false); |
||
| 53 | $this->baseurl = $this->getRoute()->getMatchedParam('baseurl'); |
||
| 54 | $this->destination = $this->getRoute()->getMatchedParam('destination'); |
||
| 55 | $this->dryrun = $this->getRoute()->getMatchedParam('dry-run', false); |
||
| 56 | |||
| 57 | $config = []; |
||
| 58 | $options = []; |
||
| 59 | $messageOpt = ''; |
||
| 60 | |||
| 61 | if ($this->drafts) { |
||
| 62 | $options['drafts'] = true; |
||
| 63 | $messageOpt .= ' with drafts'; |
||
| 64 | } |
||
| 65 | if ($this->verbose) { |
||
| 66 | $options['verbosity'] = Builder::VERBOSITY_VERBOSE; |
||
| 67 | } else { |
||
| 68 | if ($this->quiet) { |
||
| 69 | $options['verbosity'] = Builder::VERBOSITY_QUIET; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | if ($this->baseurl) { |
||
| 73 | $config['site']['baseurl'] = $this->baseurl; |
||
| 74 | } |
||
| 75 | if ($this->destination) { |
||
| 76 | $config['output']['dir'] = $this->destination; |
||
| 77 | $this->fs->dumpFile($this->getPath().'/'.Serve::$tmpDir.'/output', $this->destination); |
||
| 78 | } |
||
| 79 | if ($this->dryrun) { |
||
| 80 | $options['dry-run'] = true; |
||
| 81 | $messageOpt .= ' dry-run'; |
||
| 82 | } |
||
| 83 | |||
| 84 | try { |
||
| 85 | if (!$this->quiet) { |
||
| 86 | $this->wl(sprintf('Building website%s...', $messageOpt)); |
||
| 87 | } |
||
| 88 | $this->getBuilder($config, $options)->build($options); |
||
| 89 | if ($this->getRoute()->getName() == 'serve') { |
||
| 90 | $this->fs->dumpFile($this->getPath().'/'.Serve::$tmpDir.'/changes.flag', ''); |
||
| 91 | } |
||
| 92 | } catch (\Exception $e) { |
||
| 93 | throw new \Exception(sprintf($e->getMessage())); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |