CloneConfigData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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_shift;
8
use Illuminate\Support\Facades\DB;
9
use App\Http\Controllers\CloneController;
10
11
class CloneConfigData extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'clone:config {year} {mode} {max}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Clone configuration data for new year';
26
27
    protected $start_time;
28
    protected  $end_time;
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @return void
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
        $this->shifts = new Institution_shift();
0 ignored issues
show
Bug Best Practice introduced by
The property shifts does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
        $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...
40
        $this->clone = new CloneController();
0 ignored issues
show
Bug Best Practice introduced by
The property clone does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
        $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...
42
    }
43
44
    /**
45
     * Execute the console command.
46
     *
47
     * @return mixed
48
     */
49
    public function handle()
50
    {
51
        DB::statement("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
52
        $this->start_time = microtime(TRUE);
53
        $year = $this->argument('year');
54
        $academicPeriod = $this->academic_period->getAcademicPeriod($year);
55
        $mode = $this->argument('mode') == 'AL' ? true : false; 
56
        $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...
57
        $previousAcademicPeriod = Academic_period::where('order',$previousAcademicPeriodYear+1)->first();
58
        $shift = $this->shifts->getShiftsToClone($previousAcademicPeriod->code,$this->argument(('max')),$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...
59
        $params = [
60
            'year' => $year,
61
            'academic_period' => $academicPeriod,
62
            'previous_academic_period' => $previousAcademicPeriod,
63
            'mode' => $this->argument('mode')
64
        ];
65
66
        $function = array($this->clone, 'process');
67
        if(count($shift) > 0){
68
            // processParallel($function,$shift, $this->argument('max'),$params);
69
            array_walk($shift,$function,$params);
70
        }else{
71
            $this->output->writeln('Nothing to clone');
72
        }
73
        $this->end_time = microtime(TRUE);
74
75
76
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
77
        $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
78
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
79
    }  
80
}
81