GetNotificationById::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php namespace JobApis\JobsToMail\Jobs\Notifications;
2
3
use Illuminate\Database\Query\Builder;
4
use JobApis\JobsToMail\Models\CustomDatabaseNotification;
5
6
class GetNotificationById
7
{
8
    /**
9
     * @var string $id Notification ID
10
     */
11
    protected $id;
12
13
    /**
14
     * Create a new job instance.
15
     */
16
    public function __construct($id = null)
17
    {
18
        $this->id = $id;
19
    }
20
21
    /**
22
     * Get a single notification by ID
23
     *
24
     * @return Builder
25
     */
26
    public function handle(CustomDatabaseNotification $notifications)
27
    {
28
        return $notifications->with('search')
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

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...
29
            ->where('id', $this->id)
30
            ->first();
31
    }
32
}
33