NntmuxResetTruncate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Release;
6
use App\Models\UsenetGroup;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\DB;
9
10
class NntmuxResetTruncate extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'nntmux:reset-truncate';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'This command removes releases with no NZBs, resets all groups, truncates article tables. All other releases are left alone.';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     */
39
    public function handle(): void
40
    {
41
        UsenetGroup::query()->update(['first_record' => 0, 'first_record_postdate' => null, 'last_record' => 0, 'last_record_postdate' => null, 'last_updated' => null]);
42
        $this->info('Reseting all groups completed.');
43
        DB::statement('SET FOREIGN_KEY_CHECKS = 0;');
44
45
        foreach (['parts', 'missed_parts', 'binaries', 'collections'] as &$value) {
0 ignored issues
show
Bug introduced by
The expression array('parts', 'missed_p...naries', 'collections') cannot be used as a reference.

Let?s assume that you have the following foreach statement:

foreach ($array as &$itemValue) { }

$itemValue is assigned by reference. This is possible because the expression (in the example $array) can be used as a reference target.

However, if we were to replace $array with something different like the result of a function call as in

foreach (getArray() as &$itemValue) { }

then assigning by reference is not possible anymore as there is no target that could be modified.

Available Fixes

1. Do not assign by reference
foreach (getArray() as $itemValue) { }
2. Assign to a local variable first
$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a reference
function &getArray() { $array = array(); return $array; }

foreach (getArray() as &$itemValue) { }
Loading history...
46
            DB::statement("TRUNCATE TABLE $value");
47
            $this->info("Truncating $value completed.");
48
        }
49
        unset($value);
50
51
        $delcount = Release::query()->where('nzbstatus', '=', 0)->delete();
52
        $this->info($delcount.' releases had no nzb, deleted.');
53
        DB::statement('SET FOREIGN_KEY_CHECKS = 1;');
54
    }
55
}
56