Test Setup Failed
Pull Request — master (#461)
by Mohamed
07:05
created

ExaminationCheck::deleteDuplication()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 10
c 2
b 0
f 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
use App\Models\Examination_student;
8
9
class ExaminationCheck extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'examination:removedDuplicated {limit}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'check duplications';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
        $this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Symfony\Component\Co...\Output\ConsoleOutput() of type Symfony\Component\Console\Output\ConsoleOutput is incompatible with the declared type Illuminate\Console\OutputStyle of property $output.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        $this->start_time = microtime(TRUE);
0 ignored issues
show
Bug Best Practice introduced by
The property start_time does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
        $count = DB::table('examination_students')->select('nsid')->distinct()->count();
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
45
        $studentsIdsWithDuplication =   DB::table('examination_students as es')
0 ignored issues
show
Unused Code introduced by
The assignment to $studentsIdsWithDuplication is dead and can be removed.
Loading history...
46
        ->select(DB::raw('count(*) as total'),'es.*')
47
        ->whereNotNull('es.nsid')
48
        ->whereRaw('es.nsid != ""')
49
        ->having('total','>',1)
50
        ->groupBy('es.nsid')
51
        ->orderBy('es.nsid')
52
        ->chunk($this->argument('limit'),function($Students){
53
            foreach ($Students as $Student) {
54
                $count = Examination_student::where('nsid',$Student->nsid)->update(['nsid'=>'']);
55
                $this->output->writeln($Student->nsid .'same ID' . $count . ' records removed');
56
            }
57
        }); 
58
    }
59
}
60