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

CommandNewSite::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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