Issues (367)

app/Console/Commands/cleanConfig.php (7 issues)

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 App\Http\Controllers\CloneController;
9
10
class cleanConfig extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'clean:clone {year}';
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->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...
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
        $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...
37
        $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...
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $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...
48
        $year = $this->argument('year');
49
        $academicPeriod = $this->academic_period->getAcademicPeriod($year);
50
        $previousAcademicPeriodYear = $academicPeriod->order;
0 ignored issues
show
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
53
        $params = [
54
            'academic_period' => $academicPeriod,
55
            'previous_academic_period' => $previousAcademicPeriod
56
        ];
57
58
        if($year == '2019' || $year == '2018/19'){
59
            die('Academic Year 2019 or earlier can`t be deleted');
0 ignored issues
show
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...
60
        }else{
61
            $this->clone->cleanConfig($params);
62
        }
63
    }
64
}
65