Passed
Push — master ( a5e8db...945884 )
by Danny
02:33
created

NewCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace PressCLI\Command;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class NewCommand extends Command
11
{
12
    /**
13
     * Configure create command.
14
     */
15
    protected function configure()
16
    {
17
        $this->setName('new')
18
             ->setDescription('Creates a new project directory, configuration and runs the install.')
19
             ->addArgument('project-name', InputArgument::REQUIRED, 'The project name.');
20
    }
21
22
    /**
23
     * Execute create command.
24
     *
25
     * @param  InputInterface  $input
26
     * @param  OutputInterface $output
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        // Configure the install.
31
        $name = $input->getArgument('project-name');
32
        $configure = $this->getApplication()->find('configure');
33
        $configure->run(new ArrayInput(['project-name' => $name]), $output);
34
35
        // Go into the newly configured install.
36
        chdir($name);
37
        $output->writeln('');
38
39
        $install = $this->getApplication()->find('install');
40
        $install->run(new ArrayInput([]), $output);
41
    }
42
43
    /**
44
     * Create project directory.
45
     *
46
     * @return InitCommand
47
     */
48 View Code Duplication
    protected function createProjectDirectory($directory, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $output->writeln("<info>Creating project directory...</info>");
51
52
        if (file_exists($directory)) {
53
            $output->writeln("<comment>Project directory already exists at {$directory}.</comment>");
54
55
            return $this;
56
        }
57
58
        mkdir($directory, 0755, true);
59
60
        $output->writeln("<info>Project directory created at {$directory}!</info>");
61
62
        return $this;
63
    }
64
}
65