MakeNewCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
c 2
b 0
f 0
dl 0
loc 47
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 30 4
A configure() 0 7 1
1
<?php
2
3
namespace UnikCodes\Console\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use UnikCodes\Console\Commander;
9
10
class MakeNewCommand extends Commander
11
{
12
    /**
13
     * Configure the command options.
14
     */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('new')
19
            ->setDescription('Create a new Ark project')
20
            ->addArgument('name', InputArgument::REQUIRED, 'Project name')
21
            ->addArgument('path', InputArgument::OPTIONAL, 'Path of the project to be create');
22
    }
23
24
    /**
25
     * Execute the command.
26
     */
27
    protected function execute(InputInterface $input, OutputInterface $output): int
28
    {
29
        $name = $this->cleanupName($input->getArgument('name'));
30
        $path = $input->getArgument('path')
31
            ? $input->getArgument('path') . DIRECTORY_SEPARATOR . $name
0 ignored issues
show
Bug introduced by
Are you sure $input->getArgument('path') of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            ? /** @scrutinizer ignore-type */ $input->getArgument('path') . DIRECTORY_SEPARATOR . $name
Loading history...
32
            : getcwd() . DIRECTORY_SEPARATOR . $name;
33
34
        if (file_exists($path)) {
35
            $output->writeln('<error>Git: ' . $path . ' already exists!</error>');
36
37
            return 1;
38
        }
39
40
        $output->writeln('<info>Git:</info> Creating new Ark project named ' . $name);
41
        exec('composer create-project unik-codes/ark "' . $path . '" --prefer-dist');
42
43
        if (file_exists($path)) {
44
            chdir($path);
45
            $this->gitInit();
46
            $output->writeln('<info>Git:</info> Initialise, add all files and commit...');
47
            $this->composerUpdate();
48
            $output->writeln('<info>Composer:</info> Update dependencies...');
49
            $this->gitCommitUpdateDependecies();
50
            $output->writeln('<info>Git:</info> Commit dependencies...');
51
        }
52
53
        $output->writeln('<info>New Ark created: </info> ' . $input->getArgument('name') . ' is created at ' . $path);
0 ignored issues
show
Bug introduced by
Are you sure $input->getArgument('name') of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        $output->writeln('<info>New Ark created: </info> ' . /** @scrutinizer ignore-type */ $input->getArgument('name') . ' is created at ' . $path);
Loading history...
54
        $output->writeln('<info>Thank you for using Ark!</info>');
55
56
        return 0;
57
    }
58
}
59