1818
1919class API {
2020
21- private $ protocol ;
21+ private string $ protocol ;
2222 private $ admin ;
2323 private $ allowed ;
2424 private $ apps ;
@@ -32,20 +32,20 @@ class API {
3232 private $ zones ;
3333 private $ ddns ;
3434 private $ log ;
35- private $ conf ;
36- private $ path ;
37- private $ fullPath ;
38- private $ env = [];
35+ private string $ conf ;
36+ private string $ path ;
37+ private string $ fullPath ;
38+ private array $ env = [];
3939 const PREFIX_GET = "&token= " ;
4040 const PREFIX_POST = "?token= " ;
4141
42- public function __construct ($ confPath , $ name = null ){
42+ public function __construct (string $ confPath , ? string $ name = null ){
4343 $ this ->loader ();
4444 $ this ->loadConf ($ confPath , $ name );
4545 $ this ->setProtocol ();
4646 }
4747
48- private function setProtocol (){
48+ private function setProtocol (): void {
4949 if ($ this ->env ["USE_HTTPS " ] == "true " ){
5050 $ this ->protocol = "https " ;
5151 } else {
@@ -59,7 +59,7 @@ private function setProtocol(){
5959 * @param mixed $name The name of the .env file. (optional)
6060 * @return void
6161 */
62- private function loadConf ($ path , $ name = null ){
62+ private function loadConf (string $ path , ? string $ name = null ): void {
6363 $ this ->conf = $ name ?? ".env " ;
6464 if (!isset ($ _SERVER )){
6565 $ path = __DIR__ ;
@@ -90,7 +90,7 @@ private function loadConf($path, $name = null){
9090
9191 }
9292
93- public function loader (){
93+ public function loader (): void {
9494 require_once __DIR__ . "/endpoints/admin/Admin.php " ;
9595 require_once __DIR__ . "/endpoints/allowed/Allowed.php " ;
9696 require_once __DIR__ . "/endpoints/apps/Apps.php " ;
@@ -111,12 +111,12 @@ public function loader(){
111111 * `sendCall()` - Send a request to the Technitium API.
112112 * @param array $data The data to send to the API
113113 * @param string $endpoint The endpoint to send the data to, e.g. "admin/users/list"
114- * @param mixed $method The HTTP method to use. Default is "POST".
115- * @param mixed $skip Set to `true` to skip the authentication URI append.
116- * @param mixed $bypass Set to `true` to bypass the endpoint check allowing to access not (yet) implemented methods.
114+ * @param string $method The HTTP method to use. Default is "POST".
115+ * @param bool $skip Set to `true` to skip the authentication URI append.
116+ * @param bool $bypass Set to `true` to bypass the endpoint check allowing to access not (yet) implemented methods.
117117 * @return array Returns the response from the API or an error (["status" => "error"]) as an array.
118118 */
119- public function sendCall ($ data , $ endpoint , $ method = "POST " , $ skip = false , $ bypass = false ){
119+ public function sendCall (array $ data , string $ endpoint , string $ method = "POST " , bool $ skip = false , bool $ bypass = false ): array {
120120 $ c = curl_init ();
121121 $ endpoint = $ this ->prepareEndpoint ($ endpoint , $ bypass );
122122 if ($ this ->env ["USE_POST " ]){
@@ -161,11 +161,11 @@ public function sendCall($data, $endpoint, $method = "POST", $skip = false, $byp
161161
162162 /**
163163 * `appendAuth()` - Append the authentication token to the URI.
164- * @param mixed $m The HTTP method to use. Default is "POST".
165- * @param mixed $skip Set to `true` to skip the authentication URI append, allowing the use of `API::getPermanentToken()`.
164+ * @param string $m The HTTP method to use. Default is "POST".
165+ * @param bool $skip Set to `true` to skip the authentication URI append, allowing the use of `API::getPermanentToken()`.
166166 * @return string Returns the authentication token URI string or an empty string.
167167 */
168- private function appendAuth ($ m = "POST " , $ skip = false ){
168+ private function appendAuth (string $ m = "POST " , bool $ skip = false ): string {
169169 $ this ->loadConf ($ this ->path , $ this ->conf );
170170 $ authAppend = null ;
171171 if ($ skip ){
@@ -206,7 +206,7 @@ private function appendAuth($m = "POST", $skip = false){
206206 * This function is called when the token is not found in the .env file.
207207 * @return bool Returns `true` if the token was successfully written to the .env file.
208208 */
209- private function getPermanentToken (){
209+ private function getPermanentToken (): bool {
210210 Log::error_rep ("Getting permanent token... | .env: " . $ this ->fullPath );
211211 $ response = $ this ->sendCall ([
212212 "user " => $ this ->env ["USERNAME " ],
@@ -234,10 +234,10 @@ private function getPermanentToken(){
234234 /**
235235 * `checkResponse()` - Check if the Technitium API response is valid.
236236 * If the response status contains either "error" or "invalid-token" it is considered invalid.
237- * @param mixed $response The response returned by `API::sendCall()` function.
237+ * @param string $response The response returned by `API::sendCall()` function.
238238 * @return bool Returns `true` if the response is valid, otherwise `false`.
239239 */
240- private function checkResponse (string $ response ){
240+ private function checkResponse (string $ response ): bool {
241241 if (is_null ($ response )){
242242 return false ;
243243 } else {
@@ -248,11 +248,11 @@ private function checkResponse(string $response){
248248
249249 /**
250250 * `prepareEndpoint()` - Generates the API URI for the endpoint in question.
251- * @param mixed $endpoint The endpoint to generate the URI for.
252- * @param mixed $bypass Set to `true` to bypass the endpoint check allowing to access not (yet) implemented methods.
251+ * @param string $endpoint The endpoint to generate the URI for.
252+ * @param bool $bypass Set to `true` to bypass the endpoint check allowing to access not (yet) implemented methods.
253253 * @return bool|string Returns the URI as string or `false` if the endpoint is not implemented.
254254 */
255- private function prepareEndpoint ($ endpoint , $ bypass = false ){
255+ private function prepareEndpoint (string $ endpoint , bool $ bypass = false ): bool | string {
256256 if ($ bypass ){
257257 return $ this ->protocol . ":// " . $ this ->env ["API_URL " ] . "/api/ " . $ endpoint ;
258258 }
0 commit comments