Passed
Push — master ( 96ef05...f81447 )
by Darko
09:59
created

UpdateBackfill   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 32
c 1
b 0
f 0
dl 0
loc 75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHelpText() 0 10 1
A getNntp() 0 9 2
B handle() 0 24 8
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Blacklight\Backfill;
6
use Blacklight\NNTP;
7
use Illuminate\Console\Command;
8
9
class UpdateBackfill extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'update:backfill
17
                            {mode=all : Mode: all, alph, date, safe, or group name}
18
                            {quantity? : Number of articles to backfill}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Backfill groups by various methods';
26
27
    /**
28
     * Execute the console command.
29
     */
30
    public function handle(): int
31
    {
32
        $mode = $this->argument('mode');
33
        $quantity = $this->argument('quantity');
34
35
        try {
36
            $nntp = $this->getNntp();
37
            $backfill = new Backfill(['NNTP' => $nntp]);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Backfill::__construct() has too many arguments starting with array('NNTP' => $nntp). ( Ignorable by Annotation )

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

37
            $backfill = /** @scrutinizer ignore-call */ new Backfill(['NNTP' => $nntp]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
38
39
            match (true) {
40
                $mode === 'all' && ! isset($quantity) => $backfill->backfillAllGroups(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->backfillAllGroups() targeting Blacklight\Backfill::backfillAllGroups() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
                $mode === 'alph' && is_numeric($quantity) => $backfill->backfillAllGroups('', (int) $quantity, 'normal'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->backfillAllGr...nt)$quantity, 'normal') targeting Blacklight\Backfill::backfillAllGroups() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
                $mode === 'date' && is_numeric($quantity) => $backfill->backfillAllGroups('', (int) $quantity, 'date'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->backfillAllGr...(int)$quantity, 'date') targeting Blacklight\Backfill::backfillAllGroups() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
                $mode === 'safe' && is_numeric($quantity) => $backfill->safeBackfill((int) $quantity),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->safeBackfill((int)$quantity) targeting Blacklight\Backfill::safeBackfill() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44
                preg_match('/^alt\.binaries\..+$/i', $mode) && ! isset($quantity) => $backfill->backfillAllGroups($mode),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->backfillAllGroups($mode) targeting Blacklight\Backfill::backfillAllGroups() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
                preg_match('/^alt\.binaries\..+$/i', $mode) && is_numeric($quantity) => $backfill->backfillAllGroups($mode, (int) $quantity),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $backfill->backfillAllGr...($mode, (int)$quantity) targeting Blacklight\Backfill::backfillAllGroups() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
46
                default => throw new \Exception($this->getHelpText()),
47
            };
48
49
            return self::SUCCESS;
50
        } catch (\Throwable $e) {
51
            $this->error($e->getMessage());
52
53
            return self::FAILURE;
54
        }
55
    }
56
57
    /**
58
     * Get help text.
59
     */
60
    private function getHelpText(): string
61
    {
62
        return "Wrong set of arguments.\n\n"
63
            ."Examples:\n"
64
            ."  php artisan update:backfill all                           - Backfills all groups 1 at a time, by date\n"
65
            ."  php artisan update:backfill alt.binaries.ath              - Backfills a group by name, by date\n"
66
            ."  php artisan update:backfill alt.binaries.ath 200000       - Backfills a group by name by number of articles\n"
67
            ."  php artisan update:backfill alph 200000                   - Backfills all groups (alphabetically) by number of articles\n"
68
            ."  php artisan update:backfill date 200000                   - Backfills all groups (by least backfilled) by number of articles\n"
69
            ."  php artisan update:backfill safe 200000                   - Safe backfill, stops at 2012-06-24\n";
70
    }
71
72
    /**
73
     * Get NNTP connection.
74
     */
75
    private function getNntp(): NNTP
76
    {
77
        $nntp = new NNTP;
78
79
        if ($nntp->doConnect() !== true) {
80
            throw new \Exception('Unable to connect to usenet.');
81
        }
82
83
        return $nntp;
84
    }
85
}
86