Issues (87)

src/Task/SwooleTaskJob.php (3 issues)

1
<?php
2
3
namespace SwooleTW\Http\Task;
4
5
use Illuminate\Queue\Jobs\Job;
6
use Illuminate\Contracts\Container\Container;
7
use Illuminate\Contracts\Queue\Job as JobContract;
8
9
/**
10
 * Class SwooleTaskJob
11
 */
12
class SwooleTaskJob extends Job implements JobContract
13
{
14
    /**
15
     * The Swoole Server instance.
16
     *
17
     * @var \Swoole\Http\Server
18
     */
19
    protected $swoole;
20
21
    /**
22
     * The Swoole async job raw payload.
23
     *
24
     * @var array
25
     */
26
    protected $job;
27
28
    /**
29
     * The Task id
30
     *
31
     * @var int
32
     */
33
    protected $taskId;
34
35
    /**
36
     * The src worker Id
37
     *
38
     * @var int
39
     */
40
    protected $srcWrokerId;
41
42
    /**
43
     * @var int
44
     */
45
    protected $srcWorkderId;
46
47
    /**
48
     * Create a new job instance.
49
     *
50
     * @param \Illuminate\Contracts\Container\Container $container
51
     * @param  \Swoole\Http\Server $swoole
52
     * @param  string $job
53
     * @param  int $taskId
54
     * @param $srcWrokerId
55
     */
56
    public function __construct(Container $container, $swoole, $job, $taskId, $srcWrokerId)
57
    {
58
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type Illuminate\Contracts\Container\Container, but the property $container was declared to be of type Illuminate\Container\Container. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
59
        $this->swoole = $swoole;
60
        $this->job = $job;
0 ignored issues
show
Documentation Bug introduced by
It seems like $job of type string is incompatible with the declared type array of property $job.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
        $this->taskId = $taskId;
62
        $this->srcWorkderId = $srcWrokerId;
63
    }
64
65
    /**
66
     * Fire the job.
67
     *
68
     * @return void
69
     */
70
    public function fire()
71
    {
72
        if (method_exists($this, 'resolveAndFire')) {
73
            $this->resolveAndFire(json_decode($this->getRawBody(), true));
74
        } else {
75
            parent::fire();
76
        }
77
    }
78
79
    /**
80
     * Get the number of times the job has been attempted.
81
     *
82
     * @return int
83
     */
84
    public function attempts()
85
    {
86
        return ($this->job['attempts'] ?? null) + 1;
87
    }
88
89
    /**
90
     * Get the raw body string for the job.
91
     *
92
     * @return string
93
     */
94
    public function getRawBody()
95
    {
96
        return $this->job;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->job returns the type array which is incompatible with the documented return type string.
Loading history...
97
    }
98
99
    /**
100
     * Get the job identifier.
101
     *
102
     * @return string
103
     */
104
    public function getJobId()
105
    {
106
        return $this->taskId;
107
    }
108
109
    /**
110
     * Get the service container instance.
111
     *
112
     * @return \Illuminate\Contracts\Container\Container
113
     */
114
    public function getContainer()
115
    {
116
        return $this->container;
117
    }
118
}
119