CallPromotionCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 18 2
A callPromotion() 0 2 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Academic_period;
6
use Illuminate\Console\Command;
7
use App\Models\Institution_grade;
8
use Illuminate\Support\Facades\DB;
9
10
class CallPromotionCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'promote:run {year} {mode} {limit}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Command description';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
        $this->instituion_grade = new Institution_grade();
0 ignored issues
show
Bug Best Practice introduced by
The property instituion_grade does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        $this->academic_period = new Academic_period();
0 ignored issues
show
Bug Best Practice introduced by
The property academic_period does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle()
44
    {
45
        DB::statement("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
46
        $year = $this->argument('year');
47
        $limit = $this->argument('limit');
48
        $mode = $this->argument('mode');
49
        $academicPeriod = $this->academic_period->getAcademicPeriod($year);
50
        $previousAcademicPeriodYear = $academicPeriod->order;
0 ignored issues
show
Bug introduced by
The property order does not seem to exist on App\Models\Academic_period. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
51
        $previousAcademicPeriod = Academic_period::where('order',$previousAcademicPeriodYear+1)->first();
52
        $institutions = $this->instituion_grade->getInstitutionGradeList($previousAcademicPeriod->code,$limit,$mode);
0 ignored issues
show
Bug introduced by
The property code does not seem to exist on App\Models\Academic_period. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
53
        $params = [
54
            'year' => $year,
55
            'mode'=> $mode
56
        ];
57
        if(in_array($mode,['AL','1-5','SP','6-11'])){
58
            array_walk($institutions,array($this,'callPromotion'),$params);
59
        }else{
60
            die('The give mode not support');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
61
        }
62
       
63
    }
64
65
    protected function callPromotion($institution,$count,$params){
66
        $this->call('promote:students',['year' => $params['year'],'institution' => $institution['code'],'mode' => $params['mode'] ]);
67
    }
68
}
69