1 | <?php |
||
11 | class BeanstalkdQueueStoreAdapter implements QueueStoreAdapterInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string the queue name |
||
15 | */ |
||
16 | private $queueName; |
||
17 | /** |
||
18 | * @var int the time to run. Defaults to Pheanstalkd::DEFAULT_TTR. |
||
19 | */ |
||
20 | private $timeToRun; |
||
21 | /** |
||
22 | * @var BeanstalkdQueueStoreConnection |
||
23 | */ |
||
24 | protected $connection; |
||
25 | |||
26 | /** |
||
27 | * BeanstalkdQueueStoreAdapter constructor. |
||
28 | * |
||
29 | * @param BeanstalkdQueueStoreConnection $connection |
||
30 | * @param string $queueName |
||
31 | * @param int $timeToRun |
||
32 | */ |
||
33 | 4 | public function __construct( |
|
43 | |||
44 | /** |
||
45 | * @return BeanstalkdQueueStoreAdapter |
||
46 | */ |
||
47 | 4 | public function init() |
|
53 | |||
54 | /** |
||
55 | * @return BeanstalkdQueueStoreConnection |
||
56 | */ |
||
57 | 4 | public function getConnection() |
|
61 | |||
62 | /** |
||
63 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | 3 | public function enqueue(MailJobInterface $mailJob) |
|
82 | |||
83 | 3 | public function dequeue() |
|
101 | |||
102 | /** |
||
103 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
104 | */ |
||
105 | 4 | public function ack(MailJobInterface $mailJob) |
|
123 | |||
124 | /** |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | 2 | public function isEmpty() |
|
136 | |||
137 | /** |
||
138 | * @param BeanstalkdMailJob|MailJobInterface $mailJob |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 3 | protected function createPayload(MailJobInterface $mailJob) |
|
152 | } |
||
153 |
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: