PackageRemove   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 28 3
1
<?php
2
3
namespace Cherrypulp\LaravelPackageGenerator\Commands;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\InteractsWithUser;
8
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\ChangesComposerJson;
9
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\InteractsWithComposer;
10
use Cherrypulp\LaravelPackageGenerator\Commands\Traits\ManipulatesPackageFolder;
11
12
class PackageRemove extends Command
13
{
14
    use ChangesComposerJson;
15
    use ManipulatesPackageFolder;
16
    use InteractsWithUser;
17
    use InteractsWithComposer;
18
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'package:remove
25
                            {vendor : The vendor part of the namespace}
26
                            {package : The name of package for the namespace}
27
                            {--i|interactive : Interactive mode}';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Remove the existing package.';
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        $vendor = $this->getVendor();
44
        $package = $this->getPackage();
45
46
        $vendorFolderName = $this->getVendorFolderName($vendor);
47
        $packageFolderName = $this->getPackageFolderName($package);
48
49
        $relPackagePath = "packages/$vendorFolderName/$packageFolderName";
50
        $packagePath = base_path($relPackagePath);
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

50
        $packagePath = /** @scrutinizer ignore-call */ base_path($relPackagePath);
Loading history...
51
52
        if (getcwd() !== base_path()) {
53
            $packagePath = getcwd()."/".$relPackagePath;
54
            chdir(getcwd());
55
            define("LARAVEL_PACKAGE_CLI_MODE", getcwd());
56
        }
57
58
        try {
59
            $this->composerRemovePackage($vendorFolderName, $packageFolderName);
60
            $this->removePackageFolder($packagePath);
61
            $this->unregisterPackage($vendor, $package, "packages/$vendorFolderName/$packageFolderName");
62
            $this->composerDumpAutoload();
63
64
            return 0;
65
        } catch (Exception $e) {
66
            $this->error($e->getMessage());
67
68
            return -1;
69
        }
70
    }
71
}
72