1 | <?php |
||
8 | class SqsQueueStoreAdapter implements QueueStoreAdapterInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var string the name of the queue to store the messages |
||
12 | */ |
||
13 | private $queueName; |
||
14 | /** |
||
15 | * @var string the URL of the queue to store the messages |
||
16 | */ |
||
17 | private $queueUrl; |
||
18 | /** |
||
19 | * @var SqsQueueStoreConnection |
||
20 | */ |
||
21 | protected $connection; |
||
22 | |||
23 | /** |
||
24 | * PdoQueueStoreAdapter constructor. |
||
25 | * |
||
26 | * @param SqsQueueStoreConnection $connection |
||
27 | * @param string $queueName the name of the queue in the SQS where the mail jobs are stored |
||
28 | */ |
||
29 | 5 | public function __construct(SqsQueueStoreConnection $connection, $queueName = 'mail_queue') |
|
35 | |||
36 | /** |
||
37 | * @return SqsQueueStoreAdapter |
||
38 | */ |
||
39 | 5 | public function init() |
|
51 | |||
52 | /** |
||
53 | * @return SqsQueueStoreConnection |
||
54 | */ |
||
55 | 5 | public function getConnection() |
|
59 | |||
60 | /** |
||
61 | * @param MailJobInterface|SqsMailJob $mailJob |
||
62 | * |
||
63 | * @return bool whether it has been successfully queued or not |
||
64 | */ |
||
65 | 3 | public function enqueue(MailJobInterface $mailJob) |
|
77 | |||
78 | /** |
||
79 | * Returns a MailJob fetched from Amazon SQS. |
||
80 | * |
||
81 | * @return MailJobInterface|SqsMailJob |
||
82 | */ |
||
83 | public function dequeue() |
||
100 | |||
101 | /** |
||
102 | * @param MailJobInterface|SqsMailJob $mailJob |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | 1 | public function ack(MailJobInterface $mailJob) |
|
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function isEmpty() |
||
144 | } |
||
145 |
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: