UpdateGroupHeaders::getNntp()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 2
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 UpdateGroupHeaders extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'group:update-headers {group : Group name}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Update a single group\'s article headers';
26
27
    /**
28
     * Execute the console command.
29
     */
30
    public function handle(): int
31
    {
32
        $groupName = $this->argument('group');
33
34
        try {
35
            $nntp = $this->getNntp();
36
            $groupMySQL = UsenetGroup::getByName($groupName)->toArray();
37
38
            if ($groupMySQL === null) {
0 ignored issues
show
introduced by
The condition $groupMySQL === null is always false.
Loading history...
39
                $this->error("Group not found: {$groupName}");
40
41
                return self::FAILURE;
42
            }
43
44
            (new Binaries(['NNTP' => $nntp]))->updateGroup($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

44
            (/** @scrutinizer ignore-call */ new Binaries(['NNTP' => $nntp]))->updateGroup($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...
45
46
            return self::SUCCESS;
47
        } catch (\Throwable $e) {
48
            Log::error($e->getTraceAsString());
49
            $this->error($e->getMessage());
50
51
            return self::FAILURE;
52
        }
53
    }
54
55
    /**
56
     * Get NNTP connection.
57
     */
58
    private function getNntp(): NNTP
59
    {
60
        $nntp = new NNTP;
61
62
        if ((config('nntmux_nntp.use_alternate_nntp_server') === true
63
            ? $nntp->doConnect(false, true)
64
            : $nntp->doConnect()) !== true) {
65
            throw new \Exception('Unable to connect to usenet.');
66
        }
67
68
        return $nntp;
69
    }
70
}
71