Completed
Push — master ( a59a4f...85c920 )
by claudio
06:18
created

MeetingsList::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6667
cc 2
eloc 6
nc 2
nop 0
crap 6
1
<?php
2
3
namespace plunner\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use plunner\Company;
7
8
class MeetingsList extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'meetings:list {companyId?}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'List of all meetings of a company that must be taken';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     */
28 15
    public function __construct()
29
    {
30 15
        parent::__construct();
31 15
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     */
38
    public function handle()
39
    {
40
        //
41
        $companyId = $this->argument('companyId');
42
        if (is_numeric($companyId))
43
            print_r(Company::findOrFail($companyId)->with(self::withFilter())->get()->toArray());
44
        else
45
            print_r(Company::with(self::withFilter())->select('id')->get()->toArray());
46
    }
47
48
    private static function withFilter()
49
    {
50
        return ['groups' => function ($query) {
51
            $query->select('id', 'company_id');
52
        }, 'groups.meetings' => function ($query) {
53
            $query->select('id', 'group_id', 'start_time');
54
        }, 'groups.meetings.employees' => function ($query) {
55
            $query->select('id');
56
        }];
57
    }
58
}
59