1 | <?php |
||
11 | class BeanstalkdQueueStoreAdapter implements QueueStoreAdapterInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string the queue name |
||
15 | */ |
||
16 | protected $queueName; |
||
17 | /** |
||
18 | * @var int the time to run. Defaults to Pheanstalkd::DEFAULT_TTR. |
||
19 | */ |
||
20 | protected $timeToRun; |
||
21 | /** |
||
22 | * @var BeanstalkdQueueStoreConnection |
||
23 | */ |
||
24 | protected $connection; |
||
25 | /** |
||
26 | * @var int Reserves/locks a ready job in a watched tube. A timeout value of 0 will cause the server to immediately |
||
27 | * return either a response or TIMED_OUT. A positive value of timeout will limit the amount of time the client will |
||
28 | * block on the reserve request until a job becomes available. |
||
29 | * |
||
30 | * We highly recommend a non-zero value. Defaults to 5. |
||
31 | */ |
||
32 | protected $reserveTimeout; |
||
33 | |||
34 | /** |
||
35 | * BeanstalkdQueueStoreAdapter constructor. |
||
36 | * |
||
37 | * @param BeanstalkdQueueStoreConnection $connection |
||
38 | * @param string $queueName |
||
39 | * @param int $timeToRun |
||
40 | * @param int $reserveTimeOut |
||
41 | */ |
||
42 | 4 | public function __construct( |
|
54 | |||
55 | /** |
||
56 | * @return BeanstalkdQueueStoreAdapter |
||
57 | */ |
||
58 | 4 | public function init() |
|
64 | |||
65 | /** |
||
66 | * @return BeanstalkdQueueStoreConnection |
||
67 | */ |
||
68 | 4 | public function getConnection() |
|
72 | |||
73 | /** |
||
74 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
75 | * |
||
76 | * @return int |
||
77 | */ |
||
78 | 3 | public function enqueue(MailJobInterface $mailJob) |
|
89 | |||
90 | /** |
||
91 | * @return BeanstalkdMailJob|null |
||
92 | */ |
||
93 | 3 | public function dequeue() |
|
111 | |||
112 | /** |
||
113 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
114 | */ |
||
115 | 1 | public function ack(MailJobInterface $mailJob) |
|
133 | |||
134 | /** |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | 2 | public function isEmpty() |
|
146 | |||
147 | /** |
||
148 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 3 | protected function createPayload(MailJobInterface $mailJob) |
|
162 | } |
||
163 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: