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

PartRepair::handle()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 29
rs 9.4222
cc 5
nc 9
nop 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\UsenetGroup;
6
use Blacklight\Binaries;
7
use Blacklight\NNTP;
8
use Illuminate\Console\Command;
9
use Illuminate\Support\Facades\Log;
10
11
class PartRepair extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'binaries:part-repair {group : Group name}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Do part repair for a group';
26
27
    /**
28
     * Execute the console command.
29
     */
30
    public function handle(): int
31
    {
32
        $groupName = $this->argument('group');
33
34
        try {
35
            $groupMySQL = UsenetGroup::getByName($groupName)->toArray();
36
37
            if ($groupMySQL === null) {
0 ignored issues
show
introduced by
The condition $groupMySQL === null is always false.
Loading history...
38
                $this->error("Group not found: {$groupName}");
39
40
                return self::FAILURE;
41
            }
42
43
            $nntp = $this->getNntp();
44
45
            $data = $nntp->selectGroup($groupMySQL['name']);
46
47
            if (NNTP::isError($data) && $nntp->dataError($nntp, $groupMySQL['name']) === false) {
48
                return self::FAILURE;
49
            }
50
51
            (new Binaries(['NNTP' => $nntp]))->partRepair($groupMySQL);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Binaries::__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

51
            (/** @scrutinizer ignore-call */ new Binaries(['NNTP' => $nntp]))->partRepair($groupMySQL);

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...
52
53
            return self::SUCCESS;
54
        } catch (\Throwable $e) {
55
            Log::error($e->getTraceAsString());
56
            $this->error($e->getMessage());
57
58
            return self::FAILURE;
59
        }
60
    }
61
62
    /**
63
     * Get NNTP connection.
64
     */
65
    private function getNntp(): NNTP
66
    {
67
        $nntp = new NNTP;
68
69
        if ((config('nntmux_nntp.use_alternate_nntp_server') === true
70
            ? $nntp->doConnect(false, true)
71
            : $nntp->doConnect()) !== true) {
72
            throw new \Exception('Unable to connect to usenet.');
73
        }
74
75
        return $nntp;
76
    }
77
}
78