Test Setup Failed
Pull Request — master (#461)
by Mohamed
07:33
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
        ->having('total','>',1)
49
        ->groupBy('es.nsid')
50
        ->orderBy('es.nsid')
51
        ->chunk($this->argument('limit'),function($Students){
52
            foreach ($Students as $Student) {
53
                $count = Examination_student::where('nsid',$Student->nsid)->count();
54
                if($count> 1){
55
                    Examination_student::where('nsid',$Student->nsid)->update(['nsid'=>'']);
56
                }
57
                $this->output->writeln($Student->nsid .'same ID' . $count . ' records removed');
0 ignored issues
show
Bug introduced by
Are you sure $count of type Illuminate\Database\Eloquent\Builder|integer|mixed can be used in concatenation? ( Ignorable by Annotation )

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

57
                $this->output->writeln($Student->nsid .'same ID' . /** @scrutinizer ignore-type */ $count . ' records removed');
Loading history...
58
            }
59
        }); 
60
    }
61
}
62