MakeComposeCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 28
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 40
rs 9.472
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 MakeComposeCommand extends Commander
11
{
12
    /**
13
     * Configure the command options.
14
     */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('composer')
19
            ->setDescription('Install Ark dependencies')
20
            ->addArgument('path', InputArgument::REQUIRED, 'Path of the Laravel project');
21
    }
22
23
    /**
24
     * Execute the command.
25
     */
26
    protected function execute(InputInterface $input, OutputInterface $output): int
27
    {
28
        $path = $input->getArgument('path');
29
30
        if (! file_exists($path)) {
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type string[]; however, parameter $filename of file_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

30
        if (! file_exists(/** @scrutinizer ignore-type */ $path)) {
Loading history...
31
            $output->writeln('<error>' . $path . ' does not exists!</error>');
0 ignored issues
show
Bug introduced by
Are you sure $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
            $output->writeln('<error>' . /** @scrutinizer ignore-type */ $path . ' does not exists!</error>');
Loading history...
32
33
            return 1;
34
        }
35
36
        $current_directory = getcwd();
37
38
        chdir($path);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type string[]; however, parameter $directory of chdir() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

38
        chdir(/** @scrutinizer ignore-type */ $path);
Loading history...
39
40
        $output->writeln('<info>Installing Ark dependencies.</info>');
41
        exec($this->findComposer() . ' require ' . $this->getPackages() . ' -q -n');
42
43
        $output->writeln('<info>Installing Ark dev dependencies.</info>');
44
        exec($this->findComposer() . ' require ' . $this->getDevPackages() . ' --dev -q -n');
45
46
        chdir($current_directory);
47
48
        $output->writeln('<info>You may need to go to these packages page for further installation setup.</info>');
49
        $output->writeln('<comment>https://github.com/404labfr/laravel-impersonate</comment>');
50
        $output->writeln('<comment>https://github.com/laravel/passport</comment>');
51
        $output->writeln('<comment>https://github.com/owen-it/laravel-auditing</comment>');
52
        $output->writeln('<comment>https://github.com/predis/predis</comment>');
53
        $output->writeln('<comment>https://github.com/realrashid/sweet-alert</comment>');
54
        $output->writeln('<comment>https://github.com/tightenco/ziggy</comment>');
55
        $output->writeln('<comment>https://github.com/yadahan/laravel-authentication-log</comment>');
56
        $output->writeln('<comment>https://github.com/spatie/image-optimizer</comment>');
57
        $output->writeln('<comment>https://github.com/spatie/laravel-medialibrary</comment>');
58
        $output->writeln('<comment>https://github.com/spatie/laravel-permission</comment>');
59
        $output->writeln('<comment>https://github.com/cleaniquecoders/blueprint-macro</comment>');
60
        $output->writeln('<comment>https://github.com/cleaniquecoders/laravel-observers</comment>');
61
        $output->writeln('<comment>https://github.com/cleaniquecoders/laravel-uuid</comment>');
62
        $output->writeln('<comment>https://github.com/cleaniquecoders/laravel-helper</comment>');
63
        $output->writeln('<info>Thank you for using Ark Compose!</info>');
64
65
        return 0;
66
    }
67
68
    private function getPackages()
69
    {
70
        return 'lab404/laravel-impersonate laravel/passport owen-it/laravel-auditing predis/predis realrashid/sweet-alert tightenco/ziggy yadahan/laravel-authentication-log spatie/image-optimizer spatie/laravel-medialibrary spatie/laravel-permission cleaniquecoders/blueprint-macro cleaniquecoders/laravel-observers cleaniquecoders/laravel-uuid cleaniquecoders/laravel-helper';
71
    }
72
73
    private function getDevPackages()
74
    {
75
        return 'barryvdh/laravel-debugbar laravel-frontend-presets/tailwindcss laravel/dusk';
76
    }
77
}
78