Passed
Push — master ( 4b0ec9...a33902 )
by Darko
08:19
created

MatchPrefiles   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 19
c 2
b 1
f 0
dl 0
loc 53
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 30 5
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Blacklight\NameFixer;
6
use Exception;
7
use Illuminate\Console\Command;
8
9
class MatchPrefiles extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'match:prefiles
17
                                 {limit=full : Number of releases to process or "full" for all}
18
                                 {--show : Display the changes}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Tries to match release filenames to PreDB filenames';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return int
31
     */
32
    public function handle()
33
    {
34
        $limit = $this->argument('limit');
35
36
        // Validate the limit argument
37
        if ($limit !== 'full' && ! is_numeric($limit)) {
38
            $this->error('Limit must be "full" or a numeric value.');
39
40
            return 1;
41
        }
42
43
        // Build the arguments array for NameFixer
44
        $argv = [
45
            'match_prefiles.php',
46
            $limit,
47
        ];
48
49
        if ($this->option('show')) {
50
            $argv[] = 'show';
51
        }
52
53
        try {
54
            $nameFixer = new NameFixer;
55
            $nameFixer->getPreFileNames($argv);
56
57
            return 0;
58
        } catch (Exception $e) {
59
            $this->error($e->getMessage());
60
61
            return 1;
62
        }
63
    }
64
}
65