MeetingsList   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
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::with(self::withFilter())->findOrFail($companyId)->toArray());
0 ignored issues
show
Bug introduced by
The method toArray does only exist in Illuminate\Database\Eloq...Database\Eloquent\Model, but not in Illuminate\Database\Eloquent\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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