1 | <?php |
||
23 | class Client |
||
24 | { |
||
25 | /** |
||
26 | * Array of notifications. |
||
27 | * |
||
28 | * @var Notification[] |
||
29 | */ |
||
30 | private $notifications = []; |
||
31 | |||
32 | /** |
||
33 | * Authentication provider. |
||
34 | * |
||
35 | * @var AuthProviderInterface |
||
36 | */ |
||
37 | private $authProvider; |
||
38 | |||
39 | /** |
||
40 | * Production or sandbox environment. |
||
41 | * |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $isProductionEnv; |
||
45 | |||
46 | /** |
||
47 | * Client constructor. |
||
48 | * |
||
49 | * @param AuthProviderInterface $authProvider |
||
50 | * @param bool $isProductionEnv |
||
51 | */ |
||
52 | public function __construct(AuthProviderInterface $authProvider, bool $isProductionEnv = false) |
||
57 | |||
58 | /** |
||
59 | * Push notifications to APNs. |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | public function push(): array |
||
87 | |||
88 | /** |
||
89 | * Add notification in queue for sending. |
||
90 | * |
||
91 | * @param Notification $notification |
||
92 | */ |
||
93 | public function addNotification(Notification $notification) |
||
97 | |||
98 | /** |
||
99 | * Add several notifications in queue for sending. |
||
100 | * |
||
101 | * @param Notification[] $notifications |
||
102 | */ |
||
103 | public function addNotifications(array $notifications) |
||
107 | |||
108 | /** |
||
109 | * Get already added notifications. |
||
110 | * |
||
111 | * @return Notification[] |
||
112 | */ |
||
113 | public function getNotifications() |
||
117 | |||
118 | private function mapResults($results) |
||
132 | |||
133 | private function mapErrorResponse(TransferException $error) |
||
145 | } |
||
146 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: