diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index df6f0e51e..9f4dd7ea2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,4 +1,4 @@ -name: PHP Composer +name: PHP Composer & PHPStan on: push: @@ -69,3 +69,7 @@ jobs: - name: Run test suite for library run: | php ./src/vendor/bin/phpunit ./tests/library/ + + - name: Run PHPStan analysis + uses: php-actions/phpstan@v3 + configuration: phpstan.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..e62ff6343 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,71 @@ +parameters: + ignoreErrors: + - + message: "#^Caught class Stripe\\\\Error\\\\ApiConnection not found\\.$#" + count: 1 + path: src/library/Payment/Adapter/Stripe.php + + - + message: "#^Caught class Stripe\\\\Error\\\\Authentication not found\\.$#" + count: 1 + path: src/library/Payment/Adapter/Stripe.php + + - + message: "#^Caught class Stripe\\\\Error\\\\Card not found\\.$#" + count: 1 + path: src/library/Payment/Adapter/Stripe.php + + - + message: "#^Caught class Stripe\\\\Error\\\\InvalidRequest not found\\.$#" + count: 1 + path: src/library/Payment/Adapter/Stripe.php + + - + message: "#^Call to an undefined method Payment_AdapterAbstract\\:\\:init\\(\\)\\.$#" + count: 1 + path: src/library/Payment/AdapterAbstract.php + + - + message: "#^Method Registrar_Adapter_Internetbs\\:\\:_process\\(\\) should return array but return statement is missing\\.$#" + count: 1 + path: src/library/Registrar/Adapter/Internetbs.php + + - + message: "#^Method Registrar_Adapter_Internetbs\\:\\:getDomainDetails\\(\\) should return Registrar_Domain but return statement is missing\\.$#" + count: 1 + path: src/library/Registrar/Adapter/Internetbs.php + + - + message: "#^Undefined variable\\: \\$client_id$#" + count: 1 + path: src/library/Server/Manager/Ispconfig3.php + + - + message: "#^Undefined variable\\: \\$section$#" + count: 1 + path: src/library/Server/Manager/Ispconfig3.php + + - + message: "#^Access to an undefined property Server_Manager_Plesk\\:\\:\\$_client\\.$#" + count: 23 + path: src/library/Server/Manager/Plesk.php + + - + message: "#^Method Server_Manager_Plesk\\:\\:changeAccountDomain\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/library/Server/Manager/Plesk.php + + - + message: "#^Method Server_Manager_Plesk\\:\\:testConnection\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/library/Server/Manager/Plesk.php + + - + message: "#^Undefined variable\\: \\$client$#" + count: 10 + path: src/library/Server/Manager/Plesk.php + + - + message: "#^Undefined variable\\: \\$domainId$#" + count: 1 + path: src/library/Server/Manager/Plesk.php diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..1170d0f12 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,26 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 0 + paths: + - src + excludePaths: + analyse: + - src/vendor + - src/rb.php + - src/library/Registrar/Adapter/srsx.php + - src/library/Box/Request.php + - src/library/Server/Manager/Custom.php + ignoreErrors: + - '#^Function __trans not found\.$#' + - message: '#^Function rmAllDir not found\.$#' + path: src/install/install.php + - message: '#^Access to an undefined property FOSSPatchAbstract\:\:\$di\.$#' + path: src/foss-update.php + - '#^Inner named functions are not supported by PHPStan\. Consider refactoring to an anonymous function, class method, or a top\-level\-defined function\. See issue \#165 \(https\://github\.com/phpstan/phpstan/issues/165\) for more details\.$#' + - message: '#^Result of function curl_close \(void\) is used\.$#' + path: src/modules/Spamchecker/akismet.curl.class.php + - message: '#^Result of function header \(void\) is used\.$#' + path: src/modules/Custompages/Controller/Client.php + - '#^Method Box\\Mod\\Currency\\Service\:\:_getRate\(\) should return float but return statement is missing\.$#' diff --git a/src/di.php b/src/di.php index 7573efc89..230b00c3b 100644 --- a/src/di.php +++ b/src/di.php @@ -389,12 +389,6 @@ $di['license_server'] = function () use ($di) { return $server; }; -$di['service_boxbilling'] = $di->protect(function ($config) { - $service = new \Box\Mod\Serviceboxbillinglicense\ServiceBoxbilling($config); - - return $service; -}); - $di['ftp'] = $di->protect(function ($params) { return new \Box_Ftp($params); }); $di['geoip'] = function () { return new \GeoIp2\Database\Reader(PATH_LIBRARY . '/GeoLite2-Country.mmdb'); }; diff --git a/src/library/Box/DbLoggedPDOStatement.php b/src/library/Box/DbLoggedPDOStatement.php index 65b3b23ea..12d61f350 100644 --- a/src/library/Box/DbLoggedPDOStatement.php +++ b/src/library/Box/DbLoggedPDOStatement.php @@ -15,9 +15,9 @@ class Box_DbLoggedPDOStatement extends PDOStatement { - public function execute ($input_parameters = null) + public function execute ($input_parameters = null): bool { error_log($this->queryString); - parent::execute($input_parameters); + return parent::execute($input_parameters); } } \ No newline at end of file diff --git a/src/library/Box/Extension.php b/src/library/Box/Extension.php index 7b3911d93..e3151ab35 100644 --- a/src/library/Box/Extension.php +++ b/src/library/Box/Extension.php @@ -63,7 +63,7 @@ $params = array(); $params['type'] = $type; $params['id'] = $id; - return $this->_request('extension/' . $params['id'] . '/version'); + return $this->_request('extension/' . $params['id'] . '/version', $params); } public function getLatest($type = null) diff --git a/src/library/Server/Manager/Vesta.php b/src/library/Server/Manager/Vesta.php index 2cc18fdcd..6e8a5dc6c 100644 --- a/src/library/Server/Manager/Vesta.php +++ b/src/library/Server/Manager/Vesta.php @@ -343,7 +343,7 @@ class Server_Manager_Vesta extends Server_Manager 'returncode' => $vst_returncode, 'cmd' => $vst_command, 'arg1' => $a->getUsername(), - 'arg2' => $this->create_tmp_file($new), + 'arg2' => $new, ]; // Make request and change password $result = $this->_makeRequest($postvars); diff --git a/src/library/Server/Manager/Whm.php b/src/library/Server/Manager/Whm.php index ef106830f..b6678614d 100644 --- a/src/library/Server/Manager/Whm.php +++ b/src/library/Server/Manager/Whm.php @@ -632,12 +632,7 @@ class xmlapi { if ( (defined('XMLAPI_DEBUG')) && (XMLAPI_DEBUG == '1') ) { $this->debug = true; } - - // Check if raw xml output must be enabled - if ( (defined('XMLAPI_RAW_XML')) && (XMLAPI_RAW_XML == '1') ) { - $this->raw_xml = true; - } - + /** * Authentication * This can either be passed at this point or by using the set_hash or set_password functions @@ -1907,7 +1902,7 @@ class xmlapi { * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/EditPackage XML API Call documentation */ public function editpkg($pkg) { - if (!$isset($pkg['name'])) { + if (!isset($pkg['name'])) { error_log("editpkg requires that name is defined in the array passed to it"); return false; } diff --git a/src/modules/Cron/Service.php b/src/modules/Cron/Service.php index 7e5199ba0..cb40e173d 100644 --- a/src/modules/Cron/Service.php +++ b/src/modules/Cron/Service.php @@ -103,8 +103,8 @@ class Service { try { $api->{$method}($params); - } catch (Exception $e) { - throw new Exception($e); + } catch (\Exception $e) { + throw new \Exception($e); } finally { if ('cli' == php_sapi_name()) { echo "\e[32mSuccessfully ran " . $method . '(' . $params . ')' . ".\e[0m\n"; diff --git a/src/modules/Currency/Service.php b/src/modules/Currency/Service.php index ce0eca61f..99acbc6b5 100644 --- a/src/modules/Currency/Service.php +++ b/src/modules/Currency/Service.php @@ -364,7 +364,6 @@ class Service implements InjectionAwareInterface * * @since 4.22.0 * - * @return string */ public function updateKey($key) { @@ -372,7 +371,7 @@ class Service implements InjectionAwareInterface $values = [':key' => $key]; $db = $this->di['db']; - $currency = $db->exec($sql, $values); + $db->exec($sql, $values); } /** @@ -380,7 +379,7 @@ class Service implements InjectionAwareInterface * * @since 4.22.0 * - * @return string + * @return bool */ public function isCronEnabled() { @@ -403,7 +402,6 @@ class Service implements InjectionAwareInterface * * @var int * - * @return string */ public function setCron($data) { @@ -418,7 +416,7 @@ class Service implements InjectionAwareInterface $values = [':key' => $key]; $db = $this->di['db']; - $currency = $db->exec($sql, $values); + $db->exec($sql, $values); } public function toApiArray(\Model_Currency $model) diff --git a/src/modules/Extension/Service.php b/src/modules/Extension/Service.php index a634599f1..3b77d2e67 100644 --- a/src/modules/Extension/Service.php +++ b/src/modules/Extension/Service.php @@ -515,8 +515,8 @@ class Service implements InjectionAwareInterface } $info = $mod->getManifest(); - if (isset($info['minimum_boxbilling_version']) && Box_Version::compareVersion($info['minimum_boxbilling_version']) > 0) { - throw new \Box_Exception('Module can not be installed. It requires at least :min version of FOSSBilling. You are using :v', [':min' => $info['minimum_boxbilling_version'], ':v' => Box_Version::VERSION]); + if (isset($info['minimum_boxbilling_version']) && \Box_Version::compareVersion($info['minimum_boxbilling_version']) > 0) { + throw new \Box_Exception('Module can not be installed. It requires at least :min version of FOSSBilling. You are using :v', [':min' => $info['minimum_boxbilling_version'], ':v' => \Box_Version::VERSION]); } // Allow install module even if no installer exists diff --git a/src/modules/Massmailer/Service.php b/src/modules/Massmailer/Service.php index 1e50369a6..70738413e 100644 --- a/src/modules/Massmailer/Service.php +++ b/src/modules/Massmailer/Service.php @@ -160,7 +160,7 @@ class Service implements \Box\InjectionAwareInterface 'client_id' => $client_id, ]; - $extensionService = $di['mod_service']('extension'); + $extensionService = $this->di['mod_service']('extension'); if ($extensionService->isExtensionActive('mod', 'demo')) { throw new \Box_Exception('Disabled for security reasons (Demo mode enabled)'); } diff --git a/src/modules/Theme/Controller/Admin.php b/src/modules/Theme/Controller/Admin.php index 2c8ce2ce9..acc73bb7f 100644 --- a/src/modules/Theme/Controller/Admin.php +++ b/src/modules/Theme/Controller/Admin.php @@ -47,7 +47,6 @@ class Admin implements \Box\InjectionAwareInterface * * @param string $code - client area theme code * - * @return array */ public function save_theme_settings(\Box_App $app, $theme) {