From 869e690a0438ef03f045b826879ab34f53640ecc Mon Sep 17 00:00:00 2001 From: Brad Dutton Date: Thu, 1 Apr 2021 20:05:06 -0700 Subject: [PATCH] make some PHP CS recommended changes --- .phpcs.xml | 79 ++++++++++++++++++++++++++++++++ installer/installer.php | 4 +- modules/rest/helpers/rest.php | 2 +- system/core/Kohana.php | 29 ------------ system/core/Kohana_Exception.php | 2 +- system/libraries/ORM.php | 6 +-- system/libraries/Validation.php | 2 +- 7 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 .phpcs.xml diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 00000000..72f53f91 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,79 @@ + + + + + + *\.(inc|css|js)$ + + ./application + ./lib + ./system + ./modules + ./themes + ./installer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/installer/installer.php b/installer/installer.php index 7b6fb210..e4d2e936 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -138,7 +138,7 @@ class installer { $salt = ""; for ($i = 0; $i < 4; $i++) { $char = mt_rand(48, 109); - $char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0; + $char += ($char > 90) ? 13 : (($char > 57) ? 7 : 0); $salt .= chr($char); } $password = isset($config["g3_password"]) && strlen($config["g3_password"]) ? $config["g3_password"] : ''; @@ -229,8 +229,6 @@ class installer { if (!extension_loaded("mbstring")) { $errors[] = "PHP is missing the mbstring extension"; - } else if (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING) { - $errors[] = "The mbstring extension is overloading PHP's native string functions. Please disable it."; } if (!function_exists("json_encode")) { diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index c6be1e1d..e26b0f13 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -48,7 +48,7 @@ class rest_Core { header("Content-type: text/html; charset=UTF-8"); if ($data) { $html = preg_replace( - "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'\\1'", + "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#is", "'\\1'", var_export($data, 1)); } else { $html = t("Empty response"); diff --git a/system/core/Kohana.php b/system/core/Kohana.php index 96d969ed..272a9679 100644 --- a/system/core/Kohana.php +++ b/system/core/Kohana.php @@ -164,35 +164,6 @@ abstract class Kohana_Core { // Set and validate the timezone date_default_timezone_set(Kohana::config('locale.timezone')); - // register_globals is enabled - if (ini_get('register_globals')) - { - if (isset($_REQUEST['GLOBALS'])) - { - // Prevent GLOBALS override attacks - exit('Global variable overload attack.'); - } - - // Destroy the REQUEST global - $_REQUEST = array(); - - // These globals are standard and should not be removed - $preserve = array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION'); - - // This loop has the same effect as disabling register_globals - foreach (array_diff(array_keys($GLOBALS), $preserve) as $key) - { - global $$key; - $$key = NULL; - - // Unset the global variable - unset($GLOBALS[$key], $$key); - } - - // Warn the developer about register globals - Kohana_Log::add('debug', 'Disable register_globals! It is evil and deprecated: http://php.net/register_globals'); - } - // Enable Kohana routing Event::add('system.routing', array('Router', 'find_uri')); Event::add('system.routing', array('Router', 'setup')); diff --git a/system/core/Kohana_Exception.php b/system/core/Kohana_Exception.php index bc0efd18..4214b0e3 100644 --- a/system/core/Kohana_Exception.php +++ b/system/core/Kohana_Exception.php @@ -99,7 +99,7 @@ class Kohana_Exception_Core extends Exception { * @param object exception object * @return void */ - public static function handle(Exception $e) + public static function handle($e) { try { diff --git a/system/libraries/ORM.php b/system/libraries/ORM.php index 16e047bc..4e8f8486 100644 --- a/system/libraries/ORM.php +++ b/system/libraries/ORM.php @@ -107,7 +107,7 @@ class ORM_Core { } // Initialize database - $this->__initialize(); + $this->_initialize(); // Clear the object $this->clear(); @@ -133,7 +133,7 @@ class ORM_Core { * * @return void */ - public function __initialize() + public function _initialize() { if ( ! is_object($this->db)) { @@ -186,7 +186,7 @@ class ORM_Core { public function __wakeup() { // Initialize database - $this->__initialize(); + $this->_initialize(); if ($this->reload_on_wakeup === TRUE) { diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 9917fbbc..4dc76b67 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -812,4 +812,4 @@ class Validation_Core extends ArrayObject { return ! preg_match('![^'.implode('', $chars).']!u', $value); } -} // End Validation \ No newline at end of file +} // End Validation