7
7
class CommentsClient {
8
8
const API_URL = 'https://commentanalyzer.googleapis.com/v1alpha1 ' ;
9
9
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 ;
21
21
22
22
public function __construct (string $ token ) {
23
23
$ this ->token = $ token ;
@@ -116,7 +116,7 @@ public function doNotStore(bool $doNotStore): void {
116
116
* @example string
117
117
* @param string $clientToken
118
118
*/
119
- public function clientToken (string $ clientToken ) {
119
+ public function clientToken (string $ clientToken ): void {
120
120
$ this ->clientToken = $ clientToken ;
121
121
}
122
122
@@ -126,7 +126,7 @@ public function clientToken(string $clientToken) {
126
126
* @example string
127
127
* @param string $sessionId
128
128
*/
129
- public function sessionId (string $ sessionId ) {
129
+ public function sessionId (string $ sessionId ): void {
130
130
$ this ->sessionId = $ sessionId ;
131
131
}
132
132
@@ -139,7 +139,7 @@ public function sessionId(string $sessionId) {
139
139
* }]
140
140
* @param array $attributeScores
141
141
*/
142
- public function attributeScores (array $ attributeScores ) {
142
+ public function attributeScores (array $ attributeScores ): void {
143
143
$ this ->attributeScores = $ attributeScores ;
144
144
}
145
145
@@ -149,7 +149,7 @@ public function attributeScores(array $attributeScores) {
149
149
* @example string
150
150
* @param string $communityId
151
151
*/
152
- public function communityId (string $ communityId ) {
152
+ public function communityId (string $ communityId ): void {
153
153
$ this ->communityId = $ communityId ;
154
154
}
155
155
@@ -177,14 +177,14 @@ protected function request(string $method, array $fields): CommentsResponse {
177
177
}
178
178
179
179
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 ]);
181
181
} catch (ClientException | GuzzleException $ e ) {
182
182
$ error = json_decode ($ e ->getResponse ()->getBody (), true );
183
183
184
184
if (isset ($ error ['error ' ])) {
185
185
throw new CommentsException ($ error ['error ' ]['message ' ], $ error ['error ' ]['code ' ]);
186
186
} else {
187
- throw $ e ;
187
+ throw new CommentsException ( $ e -> getMessage (), $ e -> getCode ()) ;
188
188
}
189
189
}
190
190
0 commit comments