Completed
Push — master ( f6cd66...978eaf )
by recca
02:26
created

Cleanup::fire()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 53
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 47
CRAP Score 4

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 4
eloc 42
c 6
b 0
f 0
nc 2
nop 0
dl 0
loc 53
ccs 47
cts 47
cp 1
crap 4
rs 8.9849

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Recca0120\Terminal\Console\Commands;
4
5
use Webmozart\Glob\Glob;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Collection;
8
use Illuminate\Filesystem\Filesystem;
9
10
class Cleanup extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'cleanup';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'cleanup vendor folder';
25
26
    /**
27
     * $files.
28
     *
29
     * @var \Illuminate\Filesystem\Filesystem
30
     */
31
    protected $files;
32
33
    /**
34
     * __construct.
35
     *
36
     * @param \Illuminate\Filesystem\Filesystem $files
37
     */
38 1
    public function __construct(Filesystem $files)
39
    {
40 1
        parent::__construct();
41
42 1
        $this->files = $files;
43 1
    }
44
45
    /**
46
     * fire.
47
     */
48 1
    public function fire()
49
    {
50 1
        set_time_limit(0);
51 1
        $root = function_exists('base_path') === true ? base_path() : getcwd();
52 1
        $root = rtrim($root, '/').'/';
53
54 1
        $docs = ['README*', 'CHANGELOG*', 'FAQ*', 'CONTRIBUTING*', 'HISTORY*', 'UPGRADING*', 'UPGRADE*', 'package*', 'demo', 'example', 'examples', 'doc', 'docs', 'readme*'];
55 1
        $tests = ['.travis.yml', '.scrutinizer.yml', 'phpunit.xml*', 'phpunit.php', 'test', 'Test', 'tests', 'Tests', 'travis'];
56 1
        $vcs = ['.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg'];
57
        $others = [
58 1
            'vendor',
59 1
            '.babelrc',
60 1
            '.editorconfig',
61 1
            '.eslintrc.*',
62 1
            '.gitattributes',
63 1
            '.gitignore',
64 1
            '.nitpick.json',
65 1
            '.php_cs',
66 1
            '.scrutinizer.yml',
67 1
            '.styleci.yml',
68 1
            '.travis.yml',
69 1
            'appveyor.yml',
70 1
            'package.json',
71 1
            'phpcs.xml',
72 1
            'ruleset.xml',
73 1
        ];
74
        $common = [
75 1
            'node_modules',
76 1
        ];
77
78 1
        (new Collection(
79 1
            Glob::glob($root.'{'.(new Collection(Glob::glob($root.'vendor/*/*')))
80
            ->map(function ($item) {
81 1
                return substr($item, strpos($item, 'vendor'));
82 1
            })
83 1
            ->implode(',').'}/**/{'.(implode(',', array_merge($vcs, $common, $others, $tests, $docs))).'}')
84 1
        ))
85 1
        ->merge(Glob::glob($root.'{'.(implode(',', array_merge($vcs, $common))).'}'))
86 1
        ->merge([
87 1
            $root.'vendor/phpunit',
88 1
        ])
89 1
        ->filter()
90 1
        ->each(function ($item) {
91 1
            if ($this->files->isDirectory($item) === true) {
92 1
                $this->files->deleteDirectory($item);
93 1
                $this->info('delete directory: '.$item);
94 1
            } elseif ($this->files->isFile($item)) {
95 1
                $this->files->delete($item);
96 1
                $this->info('delete file: '.$item);
97 1
            }
98 1
        });
99 1
        $this->line('');
100 1
    }
101
}
102