Completed
Push — cecil ( 66a45a )
by Arnaud
02:09
created

Build   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 67
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C processCommand() 0 43 9
1
<?php
2
/*
3
 * This file is part of the PHPoole/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Command;
12
13
use PHPoole\PHPoole;
14
15
class Build extends AbstractCommand
16
{
17
    /**
18
     * @var bool
19
     */
20
    protected $drafts;
21
    /**
22
     * @var string
23
     */
24
    protected $baseurl;
25
    /**
26
     * @var bool
27
     */
28
    protected $verbose;
29
    /**
30
     * @var bool
31
     */
32
    protected $quiet;
33
    /**
34
     * @var bool
35
     */
36
    protected $dryrun;
37
38
    public function processCommand()
39
    {
40
        $this->drafts = $this->route->getMatchedParam('drafts', false);
41
        $this->baseurl = $this->route->getMatchedParam('baseurl');
42
        $this->verbose = $this->route->getMatchedParam('verbose', false);
43
        $this->quiet = $this->route->getMatchedParam('quiet', false);
44
        $this->dryrun = $this->getRoute()->getMatchedParam('dry-run', false);
45
46
        $config = [];
47
        $options = [];
48
        $messageOpt = '';
49
50
        if ($this->baseurl) {
51
            $config['site']['baseurl'] = $this->baseurl;
52
        }
53
        if ($this->dryrun) {
54
            $options['dry-run'] = true;
55
            $messageOpt .= ' dry-run';
56
        }
57
        if ($this->drafts) {
58
            $options['drafts'] = true;
59
            $messageOpt .= ' with drafts';
60
        }
61
        if ($this->verbose) {
62
            $options['verbosity'] = PHPoole::VERBOSITY_VERBOSE;
63
        } else {
64
            if ($this->quiet) {
65
                $options['verbosity'] = PHPoole::VERBOSITY_QUIET;
66
            }
67
        }
68
69
        try {
70
            if (!$this->quiet) {
71
                $this->wl(sprintf('Building website%s...', $messageOpt));
72
            }
73
            $this->getPHPoole($config, $options)->build($options);
74
            if ($this->getRoute()->getName() == 'serve') {
75
                $this->fs->dumpFile($this->getPath().'/'.Serve::$tmpDir.'/changes.flag', '');
76
            }
77
        } catch (\Exception $e) {
78
            throw new \Exception(sprintf($e->getMessage()));
79
        }
80
    }
81
}
82