Completed
Push — master ( 492a61...69c8cb )
by Karl
11s
created

GetNotificationById   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
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 30
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 9 1
1
<?php namespace JobApis\JobsToMail\Jobs\Notifications;
2
3
use JobApis\JobsToMail\Filters\JobFilter;
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
     * Generate a CSV a single notification and return the file path
23
     *
24
     * @return string file path for download
25
     */
26
    public function handle(
27
        CustomDatabaseNotification $notifications,
28
        JobFilter $jobFilter
0 ignored issues
show
Unused Code introduced by
The parameter $jobFilter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    ) {
30
        // Get the jobs from the Database
31
        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...
32
            ->where('id', $this->id)
33
            ->first();
34
    }
35
}
36