FixReleaseNames::handle()   F
last analyzed

Complexity

Conditions 26
Paths 234

Size

Total Lines 90
Code Lines 76

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 76
c 2
b 1
f 0
dl 0
loc 90
rs 2.9083
cc 26
nc 234
nop 2

How to fix   Long Method    Complexity   

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 App\Console\Commands;
4
5
use Blacklight\NameFixer;
6
use Blacklight\NNTP;
7
use Illuminate\Console\Command;
8
9
class FixReleaseNames extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'releases:fix-names
17
                                 {method : The method number (3-20) to use for fixing names}
18
                                 {--update : Actually update the names, otherwise just display results}
19
                                 {--category=other : Category to process: "other", "all", or "predb_id"}
20
                                 {--set-status : Set releases as checked after processing}
21
                                 {--show : Display detailed release changes rather than just counters}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Fix release names using various methods (NFO, file name, Par2, etc.)';
29
30
    /**
31
     * Execute the console command.
32
     */
33
    public function handle(NameFixer $nameFixer, NNTP $nntp): int
34
    {
35
        $method = $this->argument('method');
36
        $update = $this->option('update');
37
        $setStatus = $this->option('set-status');
38
        $show = $this->option('show') ? 1 : 2;
39
40
        // Set category option
41
        $categoryOption = $this->option('category');
42
        $other = 1;
43
        if ($categoryOption === 'all') {
44
            $other = 2;
45
        } elseif ($categoryOption === 'predb_id') {
46
            $other = 3;
47
        }
48
49
        // Connect to NNTP if method requires it
50
        if ($method === '7' || $method === '8') {
51
            $compressedHeaders = config('nntmux_nntp.compressed_headers');
52
            if ((config('nntmux_nntp.use_alternate_nntp_server') === true ?
53
                $nntp->doConnect($compressedHeaders, true) :
54
                $nntp->doConnect()) !== true) {
55
                $this->error('Unable to connect to usenet.');
56
57
                return 1;
58
            }
59
        }
60
61
        switch ($method) {
62
            case '3':
63
                $nameFixer->fixNamesWithNfo(1, $update, $other, $setStatus, $show);
64
                break;
65
            case '4':
66
                $nameFixer->fixNamesWithNfo(2, $update, $other, $setStatus, $show);
67
                break;
68
            case '5':
69
                $nameFixer->fixNamesWithFiles(1, $update, $other, $setStatus, $show);
70
                break;
71
            case '6':
72
                $nameFixer->fixNamesWithFiles(2, $update, $other, $setStatus, $show);
73
                break;
74
            case '7':
75
                $nameFixer->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp);
76
                break;
77
            case '8':
78
                $nameFixer->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp);
79
                break;
80
            case '9':
81
                $nameFixer->fixNamesWithMedia(1, $update, $other, $setStatus, $show);
82
                break;
83
            case '10':
84
                $nameFixer->fixNamesWithMedia(2, $update, $other, $setStatus, $show);
85
                break;
86
            case '11':
87
                $nameFixer->fixXXXNamesWithFiles(1, $update, $other, $setStatus, $show);
88
                break;
89
            case '12':
90
                $nameFixer->fixXXXNamesWithFiles(2, $update, $other, $setStatus, $show);
91
                break;
92
            case '13':
93
                $nameFixer->fixNamesWithSrr(1, $update, $other, $setStatus, $show);
94
                break;
95
            case '14':
96
                $nameFixer->fixNamesWithSrr(2, $update, $other, $setStatus, $show);
97
                break;
98
            case '15':
99
                $nameFixer->fixNamesWithParHash(1, $update, $other, $setStatus, $show);
100
                break;
101
            case '16':
102
                $nameFixer->fixNamesWithParHash(2, $update, $other, $setStatus, $show);
103
                break;
104
            case '17':
105
                $nameFixer->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, $show);
106
                break;
107
            case '18':
108
                $nameFixer->fixNamesWithMediaMovieName(2, $update, $other, $setStatus, $show);
109
                break;
110
            case '19':
111
                $nameFixer->fixNamesWithCrc(1, $update, $other, $setStatus, $show);
112
                break;
113
            case '20':
114
                $nameFixer->fixNamesWithCrc(2, $update, $other, $setStatus, $show);
115
                break;
116
            default:
117
                $this->showHelp();
118
119
                return 1;
120
        }
121
122
        return 0;
123
    }
124
125
    /**
126
     * Display detailed help information.
127
     */
128
    protected function showHelp(): void
129
    {
130
        $this->info('');
131
        $this->info('Usage Examples:');
132
        $this->info('');
133
        $this->info('php artisan releases:fix-names 3 : Fix release names using NFO in the past 6 hours.');
134
        $this->info('php artisan releases:fix-names 4 : Fix release names using NFO.');
135
        $this->info('php artisan releases:fix-names 5 : Fix release names in misc categories using File Name in the past 6 hours.');
136
        $this->info('php artisan releases:fix-names 6 : Fix release names in misc categories using File Name.');
137
        $this->info('php artisan releases:fix-names 7 : Fix release names in misc categories using Par2 Files in the past 6 hours.');
138
        $this->info('php artisan releases:fix-names 8 : Fix release names in misc categories using Par2 Files.');
139
        $this->info('php artisan releases:fix-names 9 : Fix release names in misc categories using UID in the past 6 hours.');
140
        $this->info('php artisan releases:fix-names 10 : Fix release names in misc categories using UID.');
141
        $this->info('php artisan releases:fix-names 11 : Fix SDPORN XXX release names using specific File Name in the past 6 hours.');
142
        $this->info('php artisan releases:fix-names 12 : Fix SDPORN XXX release names using specific File Name.');
143
        $this->info('php artisan releases:fix-names 13 : Fix release names using SRR files in the past 6 hours.');
144
        $this->info('php artisan releases:fix-names 14 : Fix release names using SRR files.');
145
        $this->info('php artisan releases:fix-names 15 : Fix release names using PAR2 hash_16K block in the past 6 hours.');
146
        $this->info('php artisan releases:fix-names 16 : Fix release names using PAR2 hash_16K block.');
147
        $this->info('php artisan releases:fix-names 17 : Fix release names using Mediainfo in the past 6 hours.');
148
        $this->info('php artisan releases:fix-names 18 : Fix release names using Mediainfo.');
149
        $this->info('php artisan releases:fix-names 19 : Fix release names using CRC32 in the past 6 hours.');
150
        $this->info('php artisan releases:fix-names 20 : Fix release names using CRC32.');
151
        $this->info('');
152
        $this->info('Options:');
153
        $this->info('  --update           Actually update the names (default: only display potential changes)');
154
        $this->info('  --category=VALUE   Process "other" categories (default), "all" categories, or "predb_id" for unmatched');
155
        $this->info('  --set-status       Mark releases as checked so they won\'t be processed again');
156
        $this->info('  --show             Display detailed release changes (default: only show counters)');
157
        $this->info('');
158
    }
159
}
160