LaravelCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 68
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 33 3
A configure() 0 7 1
A verifyApplicationDoesntExist() 0 4 4
1
<?php
2
3
namespace Scriptura\QuickStart\Console;
4
5
use RuntimeException;
6
use Scriptura\QuickStart\Tasks\GitInit;
7
use Symfony\Component\Console\Command\Command;
8
use Scriptura\QuickStart\Tasks\GitCommit;
9
use Scriptura\QuickStart\Tasks\CodeCleanup;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Scriptura\QuickStart\Tasks\PublishStubs;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Scriptura\QuickStart\Tasks\NewLaravelApp;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Scriptura\QuickStart\Tasks\InstallIdeHelper;
17
use Scriptura\QuickStart\Tasks\InstallTelescope;
18
use Scriptura\QuickStart\Tasks\InstallCodeSniffer;
19
use Scriptura\QuickStart\Tasks\InstallTailwindFrontendPreset;
20
21
class LaravelCommand extends Command
22
{
23
    /**
24
     * Configure the command options.
25
     *
26
     * @return void
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('laravel')
32
            ->setDescription('Quickstart a new Laravel application')
33
            ->addArgument('name', InputArgument::REQUIRED)
34
            ->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists');
35
    }
36
37
    /**
38
     * Execute the command.
39
     *
40
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
41
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
42
     * @return int
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $name = $input->getArgument('name');
47
48
        $directory = getcwd();
49
50
        if (! $input->getOption('force')) {
51
            $this->verifyApplicationDoesntExist($directory);
52
        }
53
54
        $tasks = [
55
            new NewLaravelApp((bool) $input->getOption('force')),
56
            new GitInit(),
57
            new GitCommit('Initial Laravel install'),
58
            new InstallTelescope(),
59
            new GitCommit('Installed Telescope'),
60
            new InstallIdeHelper(),
61
            new GitCommit('Installed Ide Helper'),
62
            new InstallTailwindFrontendPreset(),
63
            new GitCommit('Tailwindcss frontend preset'),
64
            new PublishStubs(),
65
            new GitCommit('Published stubs'),
66
            new CodeCleanup(),
67
            new GitCommit('Code cleanup'),
68
            new InstallCodeSniffer(),
69
            new GitCommit('Installed Code Sniffer'),
70
        ];
71
72
        foreach ($tasks as $task) {
73
            $task($name, $input, $output);
74
        }
75
76
        return 0;
77
    }
78
79
    /**
80
     * Verify that the application does not already exist.
81
     *
82
     * @param  string  $directory
83
     * @return void
84
     */
85
    protected function verifyApplicationDoesntExist($directory)
86
    {
87
        if ((is_dir($directory) || is_file($directory)) && $directory != getcwd()) {
88
            throw new RuntimeException('Application already exists!');
89
        }
90
    }
91
}
92