Passed
Push — master ( 24b100...4cf676 )
by Pieter van der
03:25
created
library/tiqr/Tiqr/Message/APNS2.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
         $options = $this->getOptions();
21 21
         if (isset($options['apns.proxy_host_url'])) {
22 22
             // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy
23
-            $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress();
23
+            $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress();
24 24
             $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443;
25 25
             // Use HTTP/1.1 instead of HTTP/2
26 26
             $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
27
-            $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"',  $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL]));
27
+            $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL]));
28 28
         }
29 29
         else {
30 30
             $version_info = curl_version();
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
         // Get the UID from the client certificate we use for authentication, this
37 37
         // is set to the bundle ID.
38
-        $options=$this->getOptions();
38
+        $options = $this->getOptions();
39 39
         $cert_filename = $options['apns.certificate'];
40 40
         if (strlen($cert_filename) == 0) {
41 41
             throw new RuntimeException('apns.certificate option not set');
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
             );
48 48
         }
49 49
 
50
-        $cert=openssl_x509_parse( $cert_file_contents );
50
+        $cert = openssl_x509_parse($cert_file_contents);
51 51
         if (false === $cert) {
52 52
             // Log openssl error information
53 53
             while ($msg = openssl_error_string()) {
54
-                $this->logger->error('openssl_x509_parse(): ' . $msg);
54
+                $this->logger->error('openssl_x509_parse(): '.$msg);
55 55
             }
56 56
             throw new RuntimeException('Error parsing APNS client certificate');
57 57
         }
@@ -76,42 +76,42 @@  discard block
 block discarded – undo
76 76
         $authProvider = AuthProvider\Certificate::create($authProviderOptions);
77 77
 
78 78
         // Create the push message
79
-        $alert=Alert::create();
79
+        $alert = Alert::create();
80 80
         $alert->setBody($this->getText());
81 81
         // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle()
82 82
         //       The tiqr service currently does not implement this.
83
-        $payload=Payload::create()->setAlert($alert);
83
+        $payload = Payload::create()->setAlert($alert);
84 84
         $payload->setSound('default');
85 85
         foreach ($this->getCustomProperties() as $name => $value) {
86 86
             $payload->setCustomValue($name, $value);
87 87
         }
88 88
         $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson()));
89
-        $notification=new Notification($payload, $this->getAddress());
89
+        $notification = new Notification($payload, $this->getAddress());
90 90
         // Set expiration to 30 seconds from now, same as Message_APNS
91 91
         $now = new DateTime();
92
-        $expirationInstant=$now->add(new DateInterval('PT30S'));
92
+        $expirationInstant = $now->add(new DateInterval('PT30S'));
93 93
         $notification->setExpirationAt($expirationInstant);
94 94
 
95 95
         // Send the push message
96 96
         $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options);
97 97
         $client->addNotification($notification);
98
-        $responses=$client->push();
99
-        if ( sizeof($responses) != 1) {
100
-            $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) );
98
+        $responses = $client->push();
99
+        if (sizeof($responses) != 1) {
100
+            $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)));
101 101
             if (sizeof($responses) == 0) {
102 102
                 $this->logger->warning('Could not determine whether the notification was sent');
103 103
                 return;
104 104
             }
105 105
         }
106 106
         /** @var \Pushok\Response $response */
107
-        $response = reset($responses);  // Get first response from the array
108
-        $deviceToken=$response->getDeviceToken() ?? '';
107
+        $response = reset($responses); // Get first response from the array
108
+        $deviceToken = $response->getDeviceToken() ?? '';
109 109
         // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0
110
-        $apnsId=$response->getApnsId() ?? '';
110
+        $apnsId = $response->getApnsId() ?? '';
111 111
         // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.)
112
-        $statusCode=$response->getStatusCode();
112
+        $statusCode = $response->getStatusCode();
113 113
         $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken));
114
-        if ( strcasecmp($deviceToken, $this->getAddress()) ) {
114
+        if (strcasecmp($deviceToken, $this->getAddress())) {
115 115
         $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken));
116 116
         }
117 117
         if ($statusCode == 200) {
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
             return;
120 120
         }
121 121
 
122
-        $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic.
123
-        $errorReason=$response->getErrorReason(); // E.g. Unregistered
124
-        $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic.
122
+        $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic.
123
+        $errorReason = $response->getErrorReason(); // E.g. Unregistered
124
+        $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic.
125 125
 
126 126
         $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription));
127 127
         throw new RuntimeException(
Please login to merge, or discard this patch.