formatting

This commit is contained in:
Max Nuding 2024-04-10 11:52:35 +02:00
parent 7f16b67d02
commit 2f5aa63306
No known key found for this signature in database
4 changed files with 847 additions and 851 deletions

View File

@ -1,8 +1,12 @@
{ {
"com.thorlaksson.phpcs.formatOnSave" : true,
"com.thorlaksson.phpcs.runOnChange" : "onSave", "com.thorlaksson.phpcs.runOnChange" : "onSave",
"com.thorlaksson.phpcs.standard" : "phpcs.xml", "com.thorlaksson.phpcs.standard" : "phpcs.xml",
"editor.default_syntax" : "php", "editor.default_syntax" : "php",
"php.validate" : "onSave", "php.validate" : "onSave",
"prettier.format-on-save" : "Disable",
"prettier.format-on-save.ignore-remote" : "Disable",
"prettier.format-on-save.ignore-without-config" : "Disable",
"workspace.color" : 1, "workspace.color" : 1,
"workspace.name" : "APnutI" "workspace.name" : "APnutI"
} }

View File

@ -18,10 +18,10 @@
<property name="eolChar" value="\n"/> <property name="eolChar" value="\n"/>
</properties> </properties>
</rule> </rule>
<arg name="tab-width" value="2"/> <arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.ScopeIndent"> <rule ref="Generic.WhiteSpace.ScopeIndent">
<properties> <properties>
<property name="indent" value="2"/> <property name="indent" value="4"/>
</properties> </properties>
</rule> </rule>

View File

@ -7,7 +7,6 @@ use APnutI\Entities\Poll;
use APnutI\Entities\User; use APnutI\Entities\User;
use APnutI\Entities\Channel; use APnutI\Entities\Channel;
use APnutI\Exceptions\PnutException; use APnutI\Exceptions\PnutException;
use APnutI\Exceptions\NotFoundException;
use APnutI\Exceptions\NotAuthorizedException; use APnutI\Exceptions\NotAuthorizedException;
use APnutI\Exceptions\HttpPnutException; use APnutI\Exceptions\HttpPnutException;
use APnutI\Exceptions\HttpPnutRedirectException; use APnutI\Exceptions\HttpPnutRedirectException;
@ -212,7 +211,7 @@ class APnutI
} }
if ($method === 'GET' && isset($parameters['access_token'])) { if ($method === 'GET' && isset($parameters['access_token'])) {
$this->logger->info('Using provided token for auth'); $this->logger->info('Using provided token for auth');
$headers[] = 'Authorization: Bearer ' . $params['access_token']; $headers[] = 'Authorization: Bearer ' . $parameters['access_token'];
} elseif (!empty($this->access_token)) { } elseif (!empty($this->access_token)) {
$this->logger->info('Using access token for auth'); $this->logger->info('Using access token for auth');
$headers[] = 'Authorization: Bearer ' . $this->access_token; $headers[] = 'Authorization: Bearer ' . $this->access_token;
@ -232,7 +231,6 @@ class APnutI
$response = curl_exec($ch); $response = curl_exec($ch);
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT); $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$effectiveURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch); curl_close($ch);
$this->logger->debug( $this->logger->debug(
"{$method} Request to {$url}. Received status: {$http_status}. Response: {$response}" "{$method} Request to {$url}. Received status: {$http_status}. Response: {$response}"
@ -294,9 +292,7 @@ class APnutI
throw new PnutException($response['error']); throw new PnutException($response['error']);
} }
// look for response migration errors // look for response migration errors
} elseif ( } elseif (isset($response['meta'], $response['meta']['error_message'])) {
isset($response['meta'], $response['meta']['error_message'])
) {
throw new PnutException( throw new PnutException(
$response['meta']['error_message'], $response['meta']['error_message'],
$response['meta']['code'] $response['meta']['code']
@ -316,7 +312,7 @@ class APnutI
throw new PnutException( throw new PnutException(
'No response ' . 'No response ' .
json_encode($response) . json_encode($response) .
", http status: ${http_status}" ", http status: {$http_status}"
); );
} }
} }
@ -484,11 +480,7 @@ class APnutI
foreach ($posts as $post) { foreach ($posts as $post) {
$post_obj[] = new Post($post, $this); $post_obj[] = new Post($post, $this);
} }
} while ( } while ($this->meta != null && $this->meta->more && (count($post_obj) < $count || $count !== 0));
$this->meta != null &&
$this->meta->more &&
(count($post_obj) < $count || $count !== 0)
);
return $post_obj; return $post_obj;
} }
@ -570,7 +562,7 @@ class APnutI
'include_html' => false, 'include_html' => false,
'include_post_raw' => true, 'include_post_raw' => true,
]; ];
return $this->getPollFromEndpoint('/posts/' . $post_id, $arg); return $this->getPollFromEndpoint('/posts/' . $post_id, $args);
} else { } else {
$this->logger->debug('Poll token seems to be an actual poll token'); $this->logger->debug('Poll token seems to be an actual poll token');
return $this->getPollFromToken($poll_id, $poll_token); return $this->getPollFromToken($poll_id, $poll_token);
@ -611,10 +603,10 @@ class APnutI
} catch (NotSupportedPollException $e) { } catch (NotSupportedPollException $e) {
$this->logger->error('Poll not supported: ' . json_encode($res)); $this->logger->error('Poll not supported: ' . json_encode($res));
throw $e; throw $e;
} catch (HttpPnutForbiddenException $fe) { } catch (HttpPnutForbiddenException) {
$this->logger->error('Poll token required and not provided!'); $this->logger->error('Poll token required and not provided!');
throw new PollAccessRestrictedException(); throw new PollAccessRestrictedException();
} catch (NotAuthorizedException $nauth) { } catch (NotAuthorizedException) {
$this->logger->error('Not authorized when fetching poll'); $this->logger->error('Not authorized when fetching poll');
throw new PollAccessRestrictedException(); throw new PollAccessRestrictedException();
} }
@ -666,7 +658,7 @@ class APnutI
$p = new Post($this->get('/posts/' . $post_id, $args), $this); $p = new Post($this->get('/posts/' . $post_id, $args), $this);
$this->logger->debug(json_encode($p)); $this->logger->debug(json_encode($p));
return $p; return $p;
} catch (NotAuthorizedException $nae) { } catch (NotAuthorizedException) {
$this->logger->warning( $this->logger->warning(
'NotAuthorizedException when getting post, trying without access token' 'NotAuthorizedException when getting post, trying without access token'
); );
@ -753,7 +745,7 @@ class APnutI
bool $auto_crop = false, bool $auto_crop = false,
array $raw = [] array $raw = []
): Post { ): Post {
return createPost($text, $reply_to, $is_nsfw, $auto_crop, $raw); return $this->createPost($text, $reply_to, $is_nsfw, $auto_crop, $raw);
} }
public function createPost( public function createPost(