Test Setup Failed
Pull Request — master (#456)
by Mohamed
06:04
created

ExaminationCheck::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 2
b 0
f 1
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';
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
        $students = Examination_student::whereNotNull('nsid')
44
            ->orWhere('nsid', '!=', '')
45
            ->get()->toArray();
46
        $students = array_chunk($students, 10000);
47
        $this->output->writeln(count($students) . 'entries found');
48
        array_walk($students, array($this, 'process'));
49
        $this->output->writeln('All are cleaned');
50
    }
51
52
    public function process($array)
53
    {
54
        array_walk($array, array($this, 'deleteDuplication'));
55
        $this->output->writeln(count($array).'entries cleaned');
56
    }
57
58
    public function deleteDuplication($students)
59
    {
60
        $count =  Examination_student::where('nsid', $students['nsid'])->count();
61
        if ($count > 1) {
62
            Examination_student::where('st_no', $students['st_no'])->update(['nsid' => '']);
63
            $this->output->writeln($students['st_no'] . 'removed');
64
        }
65
    }
66
}
67