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

NewWebsite::processCommand()   B

Complexity

Conditions 6
Paths 35

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
cc 6
nc 35
nop 0
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 Cecil\Util\Plateform;
14
use Zend\Console\Prompt\Confirm;
15
16
class NewWebsite extends AbstractCommand
17
{
18
    /**
19
     * @var bool
20
     */
21
    protected $force;
22
23
    public function processCommand()
24
    {
25
        $this->force = $this->getRoute()->getMatchedParam('force', false);
26
27
        try {
28
            if ($this->fs->exists($this->getPath().'/'.self::CONFIG_FILE) && !$this->force) {
29
                if (!Confirm::prompt('Website already exists. Do you want to override it? [y/n]', 'y', 'n')) {
30
                    exit(0);
31
                }
32
            }
33
            $root = __DIR__.'/../../';
34
            if (Plateform::isPhar()) {
35
                $root = Plateform::getPharPath().'/';
36
            }
37
            $this->wlAnnonce('Creating a new website...');
38
            $this->fs->copy($root.'skeleton/config.yml', $this->getPath().'/'.self::CONFIG_FILE, true);
39
            $this->fs->mirror($root.'skeleton/content', $this->getPath().'/content');
40
            $this->fs->mirror($root.'skeleton/layouts', $this->getPath().'/layouts');
41
            $this->fs->mirror($root.'skeleton/static', $this->getPath().'/static');
42
            $this->wlDone('Done!');
43
        } catch (\Exception $e) {
44
            throw new \Exception(sprintf($e->getMessage()));
45
        }
46
    }
47
}
48