11<?php
22
3+ declare (strict_types=1 );
4+
35/**
46 * API handler class.
57 *
1921
2022use Exception ;
2123use phpMyFAQ \Configuration ;
22- use phpMyFAQ \Core ;
2324use phpMyFAQ \System ;
2425use stdClass ;
2526use Symfony \Component \HttpClient \HttpClient ;
@@ -47,8 +48,10 @@ class Api
4748 /**
4849 * Api constructor.
4950 */
50- public function __construct (private readonly Configuration $ configuration , private readonly System $ system )
51- {
51+ public function __construct (
52+ private readonly Configuration $ configuration ,
53+ private readonly System $ system ,
54+ ) {
5255 $ this ->setHttpClient (HttpClient::create (['max_redirects ' => 2 , 'timeout ' => 30 ]));
5356 }
5457
@@ -61,10 +64,7 @@ public function __construct(private readonly Configuration $configuration, priva
6164 */
6265 public function getVersions (): array
6366 {
64- $ response = $ this ->httpClient ->request (
65- 'GET ' ,
66- $ this ->apiUrl . 'versions '
67- );
67+ $ response = $ this ->httpClient ->request ('GET ' , $ this ->apiUrl . 'versions ' );
6868
6969 if ($ response ->getStatusCode () === Response::HTTP_OK ) {
7070 try {
@@ -73,18 +73,13 @@ public function getVersions(): array
7373 'installed ' => $ this ->configuration ->getVersion (),
7474 'stable ' => $ content ['stable ' ],
7575 'development ' => $ content ['development ' ],
76- 'nightly ' => $ content ['nightly ' ]
76+ 'nightly ' => $ content ['nightly ' ],
7777 ];
78- } catch (
79- ClientExceptionInterface |
80- RedirectionExceptionInterface |
81- ServerExceptionInterface |
82- TransportExceptionInterface $ exception
83- ) {
78+ } catch (ClientExceptionInterface |RedirectionExceptionInterface |ServerExceptionInterface |TransportExceptionInterface $ exception ) {
8479 throw new Exception (
85- 'phpMyFAQ Verification API is not available: ' . $ exception ->getMessage (),
80+ 'phpMyFAQ Verification API is not available: ' . $ exception ->getMessage (),
8681 $ exception ->getCode (),
87- $ exception
82+ $ exception,
8883 );
8984 }
9085 }
@@ -93,7 +88,7 @@ public function getVersions(): array
9388 'installed ' => $ this ->configuration ->getVersion (),
9489 'stable ' => 'n/a ' ,
9590 'development ' => 'n/a ' ,
96- 'nightly ' => 'n/a '
91+ 'nightly ' => 'n/a ' ,
9792 ];
9893 }
9994
@@ -104,26 +99,18 @@ public function getVersions(): array
10499 */
105100 public function isVerified (): bool
106101 {
107- $ response = $ this ->httpClient ->request (
108- 'GET ' ,
109- $ this ->apiUrl . 'verify/ ' . $ this ->configuration ->getVersion ()
110- );
102+ $ response = $ this ->httpClient ->request ('GET ' , $ this ->apiUrl . 'verify/ ' . $ this ->configuration ->getVersion ());
111103
112104 try {
113105 $ this ->remoteHashes = $ response ->getContent ();
114106 if (json_decode ($ this ->remoteHashes , null , 512 , JSON_THROW_ON_ERROR ) instanceof stdClass) {
115107 return is_array (json_decode ($ this ->remoteHashes , true , 512 , JSON_THROW_ON_ERROR ));
116108 }
117- } catch (
118- ClientExceptionInterface |
119- RedirectionExceptionInterface |
120- ServerExceptionInterface |
121- TransportExceptionInterface $ exception
122- ) {
109+ } catch (ClientExceptionInterface |RedirectionExceptionInterface |ServerExceptionInterface |TransportExceptionInterface $ exception ) {
123110 throw new Exception (
124- 'phpMyFAQ Verification API is not available: ' . $ exception ->getMessage (),
111+ 'phpMyFAQ Verification API is not available: ' . $ exception ->getMessage (),
125112 $ exception ->getCode (),
126- $ exception
113+ $ exception,
127114 );
128115 }
129116
@@ -139,7 +126,7 @@ public function getVerificationIssues(): array
139126 {
140127 return array_diff (
141128 json_decode ($ this ->system ->createHashes (), true , 512 , JSON_THROW_ON_ERROR ),
142- json_decode ((string ) $ this ->remoteHashes , true , 512 , JSON_THROW_ON_ERROR )
129+ json_decode ((string ) $ this ->remoteHashes , true , 512 , JSON_THROW_ON_ERROR ),
143130 );
144131 }
145132
0 commit comments