Skip to content

Commit 40ab172

Browse files
author
Alex
committed
Improve code
1 parent 060a268 commit 40ab172

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/CommentsClient.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
class CommentsClient {
88
const API_URL = 'https://commentanalyzer.googleapis.com/v1alpha1';
99

10-
protected $token;
11-
protected $comment;
12-
protected $languages;
13-
protected $context;
14-
protected $requestedAttributes;
15-
protected $spanAnnotations;
16-
protected $doNotStore;
17-
protected $clientToken;
18-
protected $sessionId;
19-
protected $attributeScores;
20-
protected $communityId;
10+
protected string $token;
11+
protected array $comment;
12+
protected array $languages;
13+
protected array $context;
14+
protected array $requestedAttributes;
15+
protected bool $spanAnnotations;
16+
protected bool $doNotStore;
17+
protected string $clientToken;
18+
protected string $sessionId;
19+
protected array $attributeScores;
20+
protected string $communityId;
2121

2222
public function __construct(string $token) {
2323
$this->token = $token;
@@ -116,7 +116,7 @@ public function doNotStore(bool $doNotStore): void {
116116
* @example string
117117
* @param string $clientToken
118118
*/
119-
public function clientToken(string $clientToken) {
119+
public function clientToken(string $clientToken): void {
120120
$this->clientToken = $clientToken;
121121
}
122122

@@ -126,7 +126,7 @@ public function clientToken(string $clientToken) {
126126
* @example string
127127
* @param string $sessionId
128128
*/
129-
public function sessionId(string $sessionId) {
129+
public function sessionId(string $sessionId): void {
130130
$this->sessionId = $sessionId;
131131
}
132132

@@ -139,7 +139,7 @@ public function sessionId(string $sessionId) {
139139
* }]
140140
* @param array $attributeScores
141141
*/
142-
public function attributeScores(array $attributeScores) {
142+
public function attributeScores(array $attributeScores): void {
143143
$this->attributeScores = $attributeScores;
144144
}
145145

@@ -149,7 +149,7 @@ public function attributeScores(array $attributeScores) {
149149
* @example string
150150
* @param string $communityId
151151
*/
152-
public function communityId(string $communityId) {
152+
public function communityId(string $communityId): void {
153153
$this->communityId = $communityId;
154154
}
155155

@@ -177,14 +177,14 @@ protected function request(string $method, array $fields): CommentsResponse {
177177
}
178178

179179
try {
180-
$response = $client->post(self::API_URL."/comments:{$method}?key={$this->token}", ['json' => $data]);
180+
$response = $client->post(self::API_URL."/comments:$method?key=$this->token", ['json' => $data]);
181181
} catch (ClientException | GuzzleException $e) {
182182
$error = json_decode($e->getResponse()->getBody(), true);
183183

184184
if (isset($error['error'])) {
185185
throw new CommentsException($error['error']['message'], $error['error']['code']);
186186
} else {
187-
throw $e;
187+
throw new CommentsException($e->getMessage(), $e->getCode());
188188
}
189189
}
190190

src/CommentsResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace PerspectiveApi;
22

33
class CommentsResponse {
4-
protected $response;
4+
protected array $response;
55

66
public function __construct(array $response) {
77
$this->response = $response;

0 commit comments

Comments
 (0)