Issues (367)

app/Console/Commands/ExaminationCheck.php (6 issues)

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
use App\Http\Controllers\ExaminationStudentsController;
9
10
class ExaminationCheck extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'examination:removedDuplicated {year} {grade} {limit}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'check duplications';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
        $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...
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $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...
45
        $count = DB::table('examination_students')->select('nsid')->distinct()->count();
0 ignored issues
show
The assignment to $count is dead and can be removed.
Loading history...
46
        $this->examinationController = new ExaminationStudentsController($this->argument('year'), $this->argument('grade'));
0 ignored issues
show
Bug Best Practice introduced by
The property examinationController does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
47
        $studentsIdsWithDuplication =   DB::table('examination_students as es')
0 ignored issues
show
The assignment to $studentsIdsWithDuplication is dead and can be removed.
Loading history...
48
        ->select(DB::raw('count(*) as total'),'es.*')
49
        ->whereNotNull('es.nsid')
50
        ->having('total','>',1)
51
        ->groupBy('es.nsid')
52
        ->orderBy('es.nsid')
53
        ->chunk($this->argument('limit'),function($Students){
54
            foreach ($Students as $Student) {
55
                $count = Examination_student::where('nsid',$Student->nsid)->count();
56
                if($count> 1){
57
                    Examination_student::where('nsid',$Student->nsid)->update(['nsid'=>'']);
58
                    $students = (array) json_decode(json_encode($Students), true);
59
                    array_walk($students, array($this->examinationController, 'clone'));
60
                }
61
                $this->output->writeln($Student->nsid .'same ID' . $count . ' records removed');
0 ignored issues
show
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

61
                $this->output->writeln($Student->nsid .'same ID' . /** @scrutinizer ignore-type */ $count . ' records removed');
Loading history...
62
            }
63
        });  
64
    }
65
}
66