Completed
Push — symfony-console ( bab453...575c8e )
by Arnaud
02:04
created

CommandNewSite   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 8
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 26 3
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Command;
10
11
use Cecil\Util\Plateform;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputDefinition;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class CommandNewSite extends Command
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('new:site')
27
            ->setDescription('Create a new website')
28
            ->setDefinition(
29
                new InputDefinition([
30
                    new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'),
31
                    new InputOption('force', 'f', InputOption::VALUE_NONE, 'Override the directory if already exist'),
32
                ])
33
            )
34
            ->setHelp('Create a new website in the current directory, or in <path> if provided.');
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $this->force = $input->getOption('force');
0 ignored issues
show
Bug introduced by
The property force does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
44
        try {
45
            /*if ($this->fs->exists($this->getPath() . '/' . self::CONFIG_FILE) && !$this->force) {
46
                if (!Confirm::prompt('Website already exists. Do you want to override it? [y/n]', 'y', 'n')) {
47
                    exit(0);
48
                }
49
            }*/
50
            $root = __DIR__ . '/../../';
51
            if (Plateform::isPhar()) {
52
                $root = Plateform::getPharPath() . '/';
53
            }
54
            $output->writeln('<info>Creating a new website...</info>');
55
            $this->fs->copy($root . 'res/skeleton/config.yml', $this->getPath() . '/' . self::CONFIG_FILE, true);
56
            $this->fs->mirror($root . 'res/skeleton/content', $this->getPath() . '/content');
57
            $this->fs->mirror($root . 'res/skeleton/layouts', $this->getPath() . '/layouts');
58
            $this->fs->mirror($root . 'res/skeleton/static', $this->getPath() . '/static');
59
            $output->writeln('Done!');
60
        } catch (\Exception $e) {
61
            throw new \Exception(sprintf($e->getMessage()));
62
        }
63
64
        return 0;
65
    }
66
}
67