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

MeetingsList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 51
ccs 3
cts 15
cp 0.2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 9 2
A withFilter() 0 10 1
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