GetNotificationById   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

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