Completed
Push — master ( 69c8cb...bf18be )
by Karl
05:54
created

app/Jobs/Notifications/GetNotificationById.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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