Issues (185)

app/Queue/DatabaseQueue.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Queue;
4
5
use App\Queue\Jobs\DatabaseJob;
6
use App\Services\TenantManager;
7
8
class DatabaseQueue extends \Illuminate\Queue\DatabaseQueue
9
{
10
    /**
11
     * Overrides default method to inject `tenant_id`.
12
     *
13
     * @param string|null $queue
14
     * @param string      $payload
15
     * @param int         $availableAt
16
     * @param int         $attempts
17
     *
18
     * @return array
19
     */
20
    protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
21
    {
22
        $queueRecord = [
23
            'queue'        => $queue,
24
            'attempts'     => $attempts,
25
            'reserved_at'  => null,
26
            'available_at' => $availableAt,
27
            'created_at'   => $this->currentTime(),
28
            'payload'      => $payload,
29
        ];
30
31
        $tenantManager = resolve(TenantManager::class);
32
        if ($tenantManager->getTenant()) {
33
            $queueRecord['tenant_id'] = $tenantManager->getTenant()->id;
34
        }
35
36
        return $queueRecord;
37
    }
38
39
    /**
40
     * Overrides default method to use my own DatabaseJob.
41
     *
42
     * @param string                                   $queue
43
     * @param \Illuminate\Queue\Jobs\DatabaseJobRecord $job
44
     *
45
     * @return DatabaseJob|\Illuminate\Queue\Jobs\DatabaseJob
46
     */
47
    protected function marshalJob($queue, $job)
48
    {
49
        $job = $this->markJobAsReserved($job);
50
51
        return new DatabaseJob(
52
            $this->container,
53
            $this,
54
            $job,
0 ignored issues
show
$job of type Illuminate\Queue\Jobs\DatabaseJobRecord is incompatible with the type stdClass expected by parameter $job of App\Queue\Jobs\DatabaseJob::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            /** @scrutinizer ignore-type */ $job,
Loading history...
55
            $this->connectionName,
56
            $queue
57
        );
58
    }
59
}
60