From b3f48293fae24df6efb6120e7a6733fc84c2cccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Fri, 28 Apr 2023 18:14:20 +0300 Subject: [PATCH] Added types and fixed a typo (#1176) * Added types and fixed a typo * Types * Types * Types * Update ExtensionManager.php --- src/library/FOSSBilling/ExtensionManager.php | 48 ++++++++++---------- src/library/FOSSBilling/Mail.php | 24 +++++----- src/library/FOSSBilling/Requirements.php | 37 +++++++-------- src/library/FOSSBilling/Version.php | 6 +-- 4 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/library/FOSSBilling/ExtensionManager.php b/src/library/FOSSBilling/ExtensionManager.php index aa144807a..bfa119397 100644 --- a/src/library/FOSSBilling/ExtensionManager.php +++ b/src/library/FOSSBilling/ExtensionManager.php @@ -31,34 +31,34 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface const TYPE_HOOK = 'hook'; const TYPE_TRANSLATION = 'translation'; - private $_url = 'https://extensions.fossbilling.org/api/'; + private string $_url = 'https://extensions.fossbilling.org/api/'; /** * @param \Box_Di $di */ - public function setDi($di) + public function setDi($di): void { $this->di = $di; } /** - * @return \Box_Di + * @return \Box_Di|null */ - public function getDi() + public function getDi(): ?Box_Di { return $this->di; } /** * Fetch extension details from the FOSSBilling extension directory - * + * * @param string $id The extension identifier (e.g. Example) - * + * * @return array The extension details * @example https://extensions.fossbilling.org/api/extension/Example An example of the API response * @throws \Box_Exception */ - public function getExtension($id) + public function getExtension(string $id): array { $manifest = $this->makeRequest('extension/' . $id); @@ -71,19 +71,19 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface /** * Fetch the list of releases of an extension from the FOSSBilling extension directory - * + * * @param string $id The extension identifier (e.g. Example) - * + * * @return array The list of releases of the extension * @example https://extensions.fossbilling.org/api/extension/Example An example of the API response (the "releases" array) * @throws \Box_Exception */ - public function getExtensionReleases($id) + public function getExtensionReleases(string $id): array { $releases = $this->getExtension($id)['releases']; if (empty($releases) || !is_array($releases)) { - throw new \Box_Exception('Unable to fetch the releaes of the extension from the FOSSBilling extension directory.'); + throw new \Box_Exception('Unable to fetch the releases of the extension from the FOSSBilling extension directory.'); } return $releases; @@ -91,14 +91,14 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface /** * Fetch the latest release of an extension from the FOSSBilling extension directory - * + * * @param string $id The extension identifier (e.g. Example) - * + * * @return array The latest release of the extension * @example https://extensions.fossbilling.org/api/extension/Example An example of the API response (the first element in the "releases" array) * @throws \Box_Exception */ - public function getLatestExtensionRelease($id) + public function getLatestExtensionRelease(string $id): array { $releases = $this->getExtensionReleases($id); $latest = reset($releases); @@ -112,13 +112,13 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface /** * Fetch the list of extensions from the FOSSBilling extension directory - * + * * @param string $type The extension type (e.g. mod) - optional - * + * * @return array The list of extensions * @example https://extensions.fossbilling.org/api/list An example of the API response */ - public function getExtensionList($type = null) + public function getExtensionList($type = null): array { $params = []; @@ -131,12 +131,12 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface /** * Check if the latest version of an extension is compatible with the current FOSSBilling version - * + * * @param string $extension The extension identifier (e.g. Example) - * + * * @return bool True if the extension is compatible, false otherwise */ - public function isExtensionCompatible($extension) + public function isExtensionCompatible(string $extension): bool { $latest = $this->getLatestExtensionRelease($extension); @@ -151,14 +151,14 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface /** * Make a request to the FOSSBilling extension directory - * + * * @param string $endpoint The API endpoint to call (e.g. list) * @param array $params The array of parameters to pass to the API endpoint - * + * * @return array The API response * @throws \Box_Exception */ - public function makeRequest($endpoint, array $params = []) + public function makeRequest(string $endpoint, array $params = []): array { $url = $this->_url . $endpoint; @@ -186,4 +186,4 @@ class FOSSBilling_ExtensionManager implements InjectionAwareInterface return $json['result']; } -} \ No newline at end of file +} diff --git a/src/library/FOSSBilling/Mail.php b/src/library/FOSSBilling/Mail.php index 66160fe0c..e16badf2e 100644 --- a/src/library/FOSSBilling/Mail.php +++ b/src/library/FOSSBilling/Mail.php @@ -52,7 +52,7 @@ class FOSSBilling_Mail * @param string $bodyHTML The HTML content of the email body. * @param string|null $transport (optional) The name of the transport to use for sending the email. * @param string|null $dsn (optional) The DSN to use for sending the email. (See: https://symfony.com/doc/current/mailer.html#using-a-3rd-party-transport) - * + * * @return void */ public function __construct(array|string $from, array|string $to, string $subject, string $bodyHTML, string|null $transport, string|null $dsn = null) @@ -89,7 +89,7 @@ class FOSSBilling_Mail * * @return void */ - public function addTo(string|array $toAddresses) + public function addTo(string|array $toAddresses): void { $this->email->addto($toAddresses); } @@ -101,7 +101,7 @@ class FOSSBilling_Mail * * @return void */ - public function addCc(string|array $ccAddresses) + public function addCc(string|array $ccAddresses): void { $this->email->addCc($ccAddresses); } @@ -113,7 +113,7 @@ class FOSSBilling_Mail * * @return void */ - public function addBcc(string|array $bccAddresses) + public function addBcc(string|array $bccAddresses): void { $this->email->addBcc($bccAddresses); } @@ -125,22 +125,22 @@ class FOSSBilling_Mail * * @return void */ - public function addReplyto(string|array $replyToAddresses) + public function addReplyto(string|array $replyToAddresses): void { $this->email->addReplyTo($replyToAddresses); } /** * Set the priority of the email message. Can be an integer between 1 and 5, with 1 being the highest priority. - * It's recomended to use Symfony's pre-defined constants instead of a specific integer, but either should work. (Example: Email::PRIORITY_HIGH) + * It's recommended to use Symfony's pre-defined constants instead of a specific integer, but either should work. (Example: Email::PRIORITY_HIGH) * * @param int $priority The priority of the email message, represented as an integer between 1 and 5. * - * @throws \Box_Exception if the provided priority is invalid. - * + * @throws \Box_Exception if the provided priority is invalid. + * * @return void */ - public function setPriority(int $priority) + public function setPriority(int $priority): void { if (is_int($priority) && $priority >= Email::PRIORITY_HIGHEST && $priority <= Email::PRIORITY_LOWEST) { $this->email->priority($priority); @@ -154,7 +154,7 @@ class FOSSBilling_Mail * * @param array|null $options An optional array of options specific to the chosen transport method. * @throws \Box_Exception If the transport method is unknown or if required options for the selected transport aren't defined - * + * * @return void */ public function send(array|null $options = null) @@ -201,10 +201,10 @@ class FOSSBilling_Mail * @param array $options An associative array of SMTP options including 'smtp_host', 'smtp_port', 'smtp_username', and 'smtp_password'. * * @throws \Box_Exception if the SMTP host or port is not configured. - * + * * @return string A string representing the DSN for the SMTP transport. */ - private function __smtpDsn(array $options) + private function __smtpDsn(array $options): string { if (empty($options['smtp_host']) || empty($options['smtp_port'])) { throw new \Box_Exception('SMTP host or port is not configured'); diff --git a/src/library/FOSSBilling/Requirements.php b/src/library/FOSSBilling/Requirements.php index 3392d9cc2..939dc757a 100644 --- a/src/library/FOSSBilling/Requirements.php +++ b/src/library/FOSSBilling/Requirements.php @@ -27,9 +27,9 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface return $this->di; } - private $_all_ok = true; - private $_app_path = PATH_ROOT; - private $_options = array(); + private bool $_all_ok = true; + private string $_app_path = PATH_ROOT; + private array $_options = array(); public function __construct() { @@ -57,12 +57,12 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface ); } - public function getOptions() + public function getOptions(): array { return $this->_options; } - public function getInfo() + public function getInfo(): array { $data = array(); $data['ip'] = $_SERVER['SERVER_ADDR'] ?? null; @@ -87,7 +87,7 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface PATH_CACHE => substr(sprintf('%o', fileperms(PATH_CACHE)), -4), PATH_LOG => substr(sprintf('%o', fileperms(PATH_LOG)), -4), ); - + $data['extensions'] = array( 'apc' => extension_loaded('apc'), 'pdo_mysql' => extension_loaded('pdo_mysql'), @@ -95,34 +95,30 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface 'mbstring' => extension_loaded('mbstring'), 'openssl' => extension_loaded('openssl'), ); - + //determine php username if(function_exists('posix_getpwuid') && function_exists('posix_geteuid')) { $data['posix_getpwuid'] = posix_getpwuid(posix_geteuid()); } return $data; } - - public function isPhpVersionOk() + + public function isPhpVersionOk(): bool { $current = $this->_options['php']['version']; $required = $this->_options['php']['min_version']; return version_compare($current, $required, '>='); } - public function isFOSSBillingVersionOk() + public function isFOSSBillingVersionOk(): bool { - $current = FOSSBilling_Version::VERSION; - if ($current == "0.0.1") { - return false; - } - return true; + return FOSSBilling_Version::VERSION !== '0.0.1'; } /** * What extensions must be loaded for FOSSBilling to function correctly */ - public function extensions() + public function extensions(): array { $exts = $this->_options['php']['extensions']; @@ -142,7 +138,7 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface /** * Files that must be writable */ - public function files() + public function files(): array { $files = $this->_options['writable_files']; $result = array(); @@ -164,7 +160,7 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface /** * Folders that must be writable */ - public function folders() + public function folders(): array { $folders = $this->_options['writable_folders']; @@ -187,7 +183,7 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface * Check if we can continue with installation * @return bool */ - public function canInstall() + public function canInstall(): bool { $this->extensions(); $this->folders(); @@ -201,11 +197,10 @@ class FOSSBilling_Requirements implements \Box\InjectionAwareInterface * @param string $perm * @return bool */ - public function checkPerms($path, $perm = '0777') + public function checkPerms(string $path, string $perm = '0777'): bool { clearstatcache(); $configmod = substr(sprintf('%o', @fileperms($path)), -4); return ($configmod == $perm); } - } diff --git a/src/library/FOSSBilling/Version.php b/src/library/FOSSBilling/Version.php index 35d6eb226..a67ac2d71 100644 --- a/src/library/FOSSBilling/Version.php +++ b/src/library/FOSSBilling/Version.php @@ -21,13 +21,13 @@ final class FOSSBilling_Version * Compare the specified FOSSBilling version string $version * with the current FOSSBilling_Version::VERSION of FOSSBilling. * - * @param string $version A version string (e.g. "0.7.1"). - * @return integer -1 if the $version is older, + * @param string $version A version string (e.g. "0.7.1"). + * @return integer -1 if the $version is older, * 0 if they are the same, * and +1 if $version is newer. * */ - public static function compareVersion($version) + public static function compareVersion(string $version): int { return version_compare(strtolower($version), strtolower(self::VERSION)); }