Add type hints and use class constants where applicable in Rhymix Framework

This commit is contained in:
Kijin Sung 2023-10-03 02:33:24 +09:00
parent 78f7942e40
commit b6e8d41be8
11 changed files with 138 additions and 128 deletions

View file

@ -14,12 +14,12 @@ class Calendar
* @param bool $long_format (optional, default is true)
* @return string
*/
public static function getMonthName($month_number, $long_format = true)
public static function getMonthName(int $month_number, bool $long_format = true): string
{
$month_number = intval($month_number, 10);
if (!is_between($month_number, 1, 12))
{
return false;
throw new Exception('Invalid month number: ' . $month_number);
}
return date($long_format ? 'F' : 'M', mktime(0, 0, 0, $month_number, 1));
@ -35,12 +35,11 @@ class Calendar
* @param int $year (optional)
* @return int
*/
public static function getMonthStartDayOfWeek($month_number, $year = null)
public static function getMonthStartDayOfWeek(int $month_number, ?int $year = null): int
{
$month_number = intval($month_number, 10);
if (!is_between($month_number, 1, 12))
{
return false;
throw new Exception('Invalid month number: ' . $month_number);
}
return (int)date('w', mktime(0, 0, 0, $month_number, 1, $year ?: date('Y')));
@ -56,12 +55,11 @@ class Calendar
* @param int $year (optional)
* @return int
*/
public static function getMonthDays($month_number, $year = null)
public static function getMonthDays(int $month_number, ?int $year = null): int
{
$month_number = intval($month_number, 10);
if (!is_between($month_number, 1, 12))
{
return false;
throw new Exception('Invalid month number: ' . $month_number);
}
return (int)date('t', mktime(0, 0, 0, $month_number, 1, $year ?: date('Y')));
@ -81,20 +79,19 @@ class Calendar
* @param int $start_dow (optional)
* @return array
*/
public static function getMonthCalendar($month_number, $year = null, $start_dow = 0)
public static function getMonthCalendar(int $month_number, ?int $year = null, int $start_dow = 0): array
{
$month_number = intval($month_number, 10);
if (!is_between($month_number, 1, 12))
{
return false;
throw new Exception('Invalid month number: ' . $month_number);
}
if (!is_between($start_dow, 0, 6))
{
return false;
throw new Exception('Invalid first day of week: ' . $start_dow);
}
if (!$year || !is_between($year, 1000, 9999))
{
$year = date('Y');
$year = (int)date('Y');
}
$start = self::getMonthStartDayOfWeek($month_number, $year);

View file

@ -15,23 +15,23 @@ class Config
/**
* Location of configuration files.
*/
public static $config_filename = 'files/config/config.php';
public static $old_db_config_filename = 'files/config/db.config.php';
public static $old_ftp_config_filename = 'files/config/ftp.config.php';
public static $old_lang_config_filename = 'files/config/lang_selected.info';
public static $default_config_filename = 'common/defaults/config.php';
public const CONFIG_FILENAME = 'files/config/config.php';
public const OLD_DB_CONFIG_PATH = 'files/config/db.config.php';
public const OLD_FTP_CONFIG_PATH = 'files/config/ftp.config.php';
public const OLD_LANG_CONFIG_PATH = 'files/config/lang_selected.info';
public const DEFAULT_CONFIG_PATH = 'common/defaults/config.php';
/**
* Load system configuration.
*
* @return void
* @return array
*/
public static function init()
public static function init(): array
{
if (file_exists(\RX_BASEDIR . self::$config_filename))
if (file_exists(\RX_BASEDIR . self::CONFIG_FILENAME))
{
ob_start();
self::$_config = (include \RX_BASEDIR . self::$config_filename);
self::$_config = (include \RX_BASEDIR . self::CONFIG_FILENAME);
ob_end_clean();
}
else
@ -47,7 +47,7 @@ class Config
$GLOBALS['RX_NAMESPACES'] = self::$_config['namespaces'];
}
return self::$_config;
return self::$_config ?: [];
}
/**
@ -55,9 +55,9 @@ class Config
*
* @return array
*/
public static function getAll()
public static function getAll(): array
{
return self::$_config;
return self::$_config ?: [];
}
/**
@ -65,9 +65,9 @@ class Config
*
* @return array
*/
public static function getDefaults()
public static function getDefaults(): array
{
return (include \RX_BASEDIR . self::$default_config_filename);
return (include \RX_BASEDIR . self::DEFAULT_CONFIG_PATH);
}
/**
@ -76,7 +76,7 @@ class Config
* @param string $key
* @return mixed
*/
public static function get($key)
public static function get(string $key)
{
if (!count(self::$_config))
{
@ -102,7 +102,7 @@ class Config
* @param mixed $value
* @return void
*/
public static function set($key, $value)
public static function set(string $key, $value): void
{
if (!count(self::$_config))
{
@ -123,7 +123,7 @@ class Config
* @param array $config
* @return void
*/
public static function setAll($config)
public static function setAll(array $config): void
{
self::$_config = $config;
}
@ -134,7 +134,7 @@ class Config
* @param array $config (optional)
* @return bool
*/
public static function save($config = null)
public static function save(?array $config = null): bool
{
if ($config)
{
@ -142,10 +142,10 @@ class Config
}
// Backup the main config file.
$config_filename = \RX_BASEDIR . self::$config_filename;
$config_filename = \RX_BASEDIR . self::CONFIG_FILENAME;
if (Storage::exists($config_filename))
{
$backup_filename = \RX_BASEDIR . self::$config_filename . '.backup.' . time() . '.php';
$backup_filename = \RX_BASEDIR . self::CONFIG_FILENAME . '.backup.' . time() . '.php';
$result = Storage::copy($config_filename, $backup_filename);
clearstatcache(true, $backup_filename);
if (!$result || filesize($config_filename) !== filesize($backup_filename))
@ -169,8 +169,8 @@ class Config
// Save XE-compatible config files.
$warning = '// THIS FILE IS NOT USED IN RHYMIX.' . "\n" . '// TO MODIFY SYSTEM CONFIGURATION, EDIT config.php INSTEAD.';
$buff = '<?php' . "\n" . $warning . "\n";
Storage::write(\RX_BASEDIR . self::$old_db_config_filename, $buff);
Storage::write(\RX_BASEDIR . self::$old_ftp_config_filename, $buff);
Storage::write(\RX_BASEDIR . self::OLD_DB_CONFIG_PATH, $buff);
Storage::write(\RX_BASEDIR . self::OLD_FTP_CONFIG_PATH, $buff);
return true;
}
@ -180,7 +180,7 @@ class Config
* @param mixed $value
* @return string
*/
public static function serialize($value)
public static function serialize($value): string
{
if (is_object($value))
{

View file

@ -12,6 +12,11 @@ class DateTime
*/
protected static $_timezones = array();
/**
* Define the relative format constant.
*/
public const FORMAT_RELATIVE = 'relative';
/**
* Format a Unix timestamp using the internal timezone.
*
@ -19,9 +24,9 @@ class DateTime
* @param int $timestamp Unix timestamp (optional, default is now)
* @return string
*/
public static function formatTimestamp($format, $timestamp = null)
public static function formatTimestamp(string $format, ?int $timestamp = null): string
{
if ($format === 'relative')
if ($format === self::FORMAT_RELATIVE)
{
return self::getRelativeTimestamp($timestamp ?: time());
}
@ -37,9 +42,9 @@ class DateTime
* @param int $timestamp Unix timestamp (optional, default is now)
* @return string
*/
public static function formatTimestampForCurrentUser($format, $timestamp = null)
public static function formatTimestampForCurrentUser(string $format, ?int $timestamp = null): string
{
if ($format === 'relative')
if ($format === self::FORMAT_RELATIVE)
{
return self::getRelativeTimestamp($timestamp ?: time());
}
@ -60,7 +65,7 @@ class DateTime
*
* @return string
*/
public static function getTimezoneForCurrentUser()
public static function getTimezoneForCurrentUser(): string
{
if (isset($_SESSION['RHYMIX']['timezone']) && $_SESSION['RHYMIX']['timezone'])
{
@ -68,11 +73,11 @@ class DateTime
}
elseif ($default = \Context::get('_default_timezone'))
{
return $default;
return (string)$default;
}
elseif ($default = Config::get('locale.default_timezone'))
{
return $default;
return (string)$default;
}
else
{
@ -85,7 +90,7 @@ class DateTime
*
* @return array
*/
public static function getTimezoneList()
public static function getTimezoneList(): array
{
$result = array();
$tzlist = \DateTimeZone::listIdentifiers();
@ -111,7 +116,7 @@ class DateTime
* @param int $timestamp Unix timestamp (optional, default is now)
* @return int
*/
public static function getTimezoneOffset($timezone, $timestamp = null)
public static function getTimezoneOffset(string $timezone, ?int $timestamp = null): int
{
if (!isset(self::$_timezones[$timezone]))
{
@ -130,9 +135,9 @@ class DateTime
* @param int $timestamp Unix timestamp (optional, default is now)
* @return int
*/
public static function getTimezoneOffsetFromInternal($timezone, $timestamp = null)
public static function getTimezoneOffsetFromInternal(string $timezone, ?int $timestamp = null): int
{
return self::getTimezoneOffset($timezone, $timestamp) - Config::get('locale.internal_timezone');
return self::getTimezoneOffset($timezone, $timestamp ?: time()) - Config::get('locale.internal_timezone');
}
/**
@ -141,7 +146,7 @@ class DateTime
* @param string $timezone
* @return int
*/
public static function getTimezoneOffsetByLegacyFormat($timezone)
public static function getTimezoneOffsetByLegacyFormat(string $timezone): int
{
$multiplier = ($timezone[0] === '-') ? -60 : 60;
$timezone = preg_replace('/[^0-9]/', '', $timezone);
@ -159,9 +164,9 @@ class DateTime
* so this should never be a problem in practice.
*
* @param int $offset
* @return bool
* @return string
*/
public static function getTimezoneNameByOffset($offset)
public static function getTimezoneNameByOffset(int $offset): string
{
switch ($offset)
{
@ -185,9 +190,9 @@ class DateTime
* @param int $timestamp
* @return string
*/
public static function getRelativeTimestamp($timestamp)
public static function getRelativeTimestamp(?int $timestamp = null): string
{
$diff = \RX_TIME - $timestamp;
$diff = \RX_TIME - intval($timestamp ?: time());
$langs = lang('common.time_gap');
if ($diff < 3)

View file

@ -26,7 +26,7 @@ class Formatter
* @param int $options (optional)
* @return string
*/
public static function text2html($text, $options = 0)
public static function text2html(string $text, int $options = 0): string
{
// This option uses <p> instead of <br> to separate lines.
if ($options & self::TEXT_NEWLINE_AS_P)
@ -63,7 +63,7 @@ class Formatter
* @param string $html
* @return string
*/
public static function html2text($html)
public static function html2text(string $html): string
{
// Add line breaks after <br> and <p> tags.
$html = preg_replace('!<br[^>]*>\s*!i', "\n", $html);
@ -97,7 +97,7 @@ class Formatter
* @param int $options (optional)
* @return string
*/
public static function markdown2html($markdown, $options = 0)
public static function markdown2html(string $markdown, int $options = 0): string
{
if ($options & self::MD_ENABLE_EXTRA)
{
@ -126,7 +126,7 @@ class Formatter
* @param string $html
* @return string
*/
public static function html2markdown($html)
public static function html2markdown(string $html): string
{
$converter = new \League\HTMLToMarkdown\HtmlConverter();
$converter->getConfig()->setOption('bold_style', '**');
@ -140,7 +140,7 @@ class Formatter
* @param string $bbcode
* @return string
*/
public static function bbcode($bbcode)
public static function bbcode(string $bbcode): string
{
$parser = new \JBBCode\Parser;
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());
@ -162,7 +162,7 @@ class Formatter
* @param string $html
* @return string
*/
public static function applySmartQuotes($html)
public static function applySmartQuotes(string $html): string
{
return \Michelf\SmartyPants::defaultTransform($html, 'qbBdDiew');
}
@ -173,10 +173,10 @@ class Formatter
* @param string|array $source_filename
* @param string $target_filename
* @param array $variables (optional)
* @parsm bool $minify (optional)
* @param bool $minify (optional)
* @return bool
*/
public static function compileLESS($source_filename, $target_filename, $variables = array(), $minify = false)
public static function compileLESS($source_filename, string $target_filename, array $variables = [], bool $minify = false): bool
{
// Get the cleaned and concatenated content.
$imported_list = [];
@ -221,10 +221,10 @@ class Formatter
* @param string|array $source_filename
* @param string $target_filename
* @param array $variables (optional)
* @parsm bool $minify (optional)
* @param bool $minify (optional)
* @return bool
*/
public static function compileSCSS($source_filename, $target_filename, $variables = array(), $minify = false)
public static function compileSCSS($source_filename, string $target_filename, array $variables = [], bool $minify = false): bool
{
// Get the cleaned and concatenated content.
$imported_list = [];
@ -301,7 +301,7 @@ class Formatter
* @param string $target_filename
* @return bool
*/
public static function minifyCSS($source_filename, $target_filename)
public static function minifyCSS($source_filename, string $target_filename): bool
{
$minifier = new \MatthiasMullie\Minify\CSS();
$minifier->setMaxImportSize(5);
@ -329,7 +329,7 @@ class Formatter
* @param string $target_filename
* @return bool
*/
public static function minifyJS($source_filename, $target_filename)
public static function minifyJS($source_filename, string $target_filename): bool
{
$minifier = new \MatthiasMullie\Minify\JS();
if (is_array($source_filename))
@ -357,7 +357,7 @@ class Formatter
* @param array &$imported_list
* @return string
*/
public static function concatCSS($source_filename, $target_filename, $add_comment = true, &$imported_list = [])
public static function concatCSS($source_filename, string $target_filename, bool $add_comment = true, array &$imported_list = []): string
{
$charsets = [];
$imported_urls = [];
@ -523,10 +523,9 @@ class Formatter
* JS concatenation subroutine.
*
* @param string|array $source_filename
* @param string $target_filename
* @return string
*/
public static function concatJS($source_filename, $target_filename)
public static function concatJS($source_filename): string
{
$result = '';

View file

@ -13,7 +13,7 @@ class Image
* @param string $filename
* @return bool
*/
public static function isImage($filename)
public static function isImage(string $filename): bool
{
return array_shift(explode('/', MIME::getContentType($filename))) === 'image';
}
@ -24,7 +24,7 @@ class Image
* @param string $filename
* @return bool
*/
public static function isAnimatedGIF($filename)
public static function isAnimatedGIF(string $filename): bool
{
if (MIME::getContentType($filename) !== 'image/gif')
{
@ -51,17 +51,17 @@ class Image
* Get image information
*
* @param string $filename
* @return array|false
* @return ?array
*/
public static function getImageInfo($filename)
public static function getImageInfo(string $filename): ?array
{
if (!self::isImage($filename))
{
return false;
return null;
}
if (!$image_info = @getimagesize($filename))
{
return false;
return null;
}
$img_type = [
IMAGETYPE_GIF => 'gif',

View file

@ -13,7 +13,7 @@ class Korea
* @param string $num
* @return string
*/
public static function formatPhoneNumber($num)
public static function formatPhoneNumber(string $num): string
{
// Remove all non-numbers.
$num = preg_replace('/[^0-9]/', '', $num);
@ -69,7 +69,7 @@ class Korea
* @param string $num
* @return bool
*/
public static function isValidPhoneNumber($num)
public static function isValidPhoneNumber(string $num): bool
{
$num = str_replace('-', '', self::formatPhoneNumber($num));
if (preg_match('/^1[0-9]{7}$/', $num))
@ -97,7 +97,7 @@ class Korea
* @param string $num
* @return bool
*/
public static function isValidMobilePhoneNumber($num)
public static function isValidMobilePhoneNumber(string $num): bool
{
$num = str_replace('-', '', self::formatPhoneNumber($num));
$len = strlen($num);
@ -114,7 +114,7 @@ class Korea
* @param string $code
* @return bool
*/
public static function isValidJuminNumber($code)
public static function isValidJuminNumber(string $code): bool
{
// Return false if the format is obviously wrong.
if (!preg_match('/^[0-9]{6}-?[0-9]{7}$/', $code))
@ -164,7 +164,7 @@ class Korea
* @param string $code
* @return bool
*/
public static function isValidCorporationNumber($code)
public static function isValidCorporationNumber(string $code): bool
{
// Return false if the format is obviously wrong.
if (!preg_match('/^[0-9]{6}-?[0-9]{7}$/', $code))
@ -200,7 +200,7 @@ class Korea
* @param string $code
* @return bool
*/
public static function isValidBusinessNumber($code)
public static function isValidBusinessNumber(string $code): bool
{
// Return false if the format is obviously wrong.
if (!preg_match('/^[0-9]{3}-?[0-9]{2}-?[0-9]{5}$/', $code))
@ -232,7 +232,7 @@ class Korea
* @param string $ip
* @return bool
*/
public static function isKoreanIP($ip)
public static function isKoreanIP(string $ip): bool
{
// Extract the IPv4 address from an "IPv4-mapped IPv6" address.
if (preg_match('/::ffff:(?:0+:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $ip, $matches)) $ip = $matches[1];
@ -293,7 +293,7 @@ class Korea
* @param bool $clear_cache (optional)
* @return bool
*/
public static function isKoreanEmailAddress($email_address, $clear_cache = false)
public static function isKoreanEmailAddress(string $email_address, bool $clear_cache = false): bool
{
// Clear the cache if requested.
if ($clear_cache)
@ -369,7 +369,7 @@ class Korea
* @param int $type
* @return array
*/
protected static function _getDNSRecords($domain, $type)
protected static function _getDNSRecords(string $domain, int $type): array
{
$records = dns_get_record($domain, $type);
if (!$records)
@ -414,6 +414,7 @@ class Korea
'hanmail.net',
'hanmail2.net',
'daum.net',
'kakao.com',
'paran.com',
'tistory.com',
'naver.com',

View file

@ -24,9 +24,9 @@ class Lang
* This method returns the cached instance of a language.
*
* @param string $language
* @return object
* @return self
*/
public static function getInstance($language)
public static function getInstance(string $language): self
{
if ($language === 'jp')
{
@ -44,7 +44,7 @@ class Lang
*
* @param string $language
*/
protected function __construct($language)
protected function __construct(string $language)
{
$this->_language = preg_replace('/[^a-z0-9_-]/i', '', $language);
$this->_loaded_plugins['_custom_'] = new \stdClass();
@ -55,7 +55,7 @@ class Lang
*
* @return string
*/
public function langType()
public function langType(): string
{
return $this->_language;
}
@ -66,7 +66,7 @@ class Lang
* @param string $name
* @return bool
*/
public function loadPlugin($name)
public function loadPlugin(string $name): bool
{
if (isset($this->_loaded_plugins[$name]))
{
@ -89,6 +89,12 @@ class Lang
{
$this->loadDirectory(\RX_BASEDIR . "addons/$name/lang", $name);
}
else
{
return false;
}
return true;
}
/**
@ -98,7 +104,7 @@ class Lang
* @param string $plugin_name
* @return bool
*/
public function loadDirectory($dir, $plugin_name = null)
public function loadDirectory(string $dir, string $plugin_name = ''): bool
{
// Do not load the same directory twice.
$dir = rtrim($dir, '/');
@ -161,7 +167,7 @@ class Lang
*
* @return array
*/
public static function getSupportedList()
public static function getSupportedList(): array
{
static $list = null;
if ($list === null)
@ -175,9 +181,9 @@ class Lang
* Generic getter.
*
* @param string $key
* @return string
* @return string|\ArrayObject
*/
public function get($key)
public function get(string $key)
{
$args = func_get_args();
array_shift($args);
@ -200,10 +206,10 @@ class Lang
* Generic setter.
*
* @param string $key
* @param string $value
* @param mixed $value
* @return void
*/
public function set($key, $value)
public function set(string $key, $value): void
{
$this->__set($key, $value);
}
@ -212,9 +218,9 @@ class Lang
* Fallback method for getting the default translation.
*
* @param string $key
* @return string
* @return string|\ArrayObject
*/
public function getFromDefaultLang($key)
public function getFromDefaultLang(string $key)
{
if ($this->_language === 'en')
{
@ -230,9 +236,9 @@ class Lang
* Magic method for translations without arguments.
*
* @param string $key
* @return string
* @return string|\ArrayObject
*/
public function __get($key)
public function __get(string $key)
{
// Load a dot-separated key (prefixed by plugin name).
if (preg_match('/^[a-z0-9_.-]+$/i', $key) && ($keys = explode('.', $key)) && count($keys) >= 2)
@ -293,10 +299,10 @@ class Lang
* Magic method for setting a new custom translation.
*
* @param string $key
* @param string $value
* @param mixed $value
* @return void
*/
public function __set($key, $value)
public function __set(string $key, $value): void
{
// Set a dot-separated key (prefixed by plugin name).
if (preg_match('/^[a-z0-9_.-]+$/i', $key) && ($keys = explode('.', $key)) && count($keys) >= 2)
@ -309,7 +315,7 @@ class Lang
}
if (!isset($this->_loaded_plugins[$plugin_name]))
{
return false;
return;
}
// Set the given key.
@ -330,7 +336,7 @@ class Lang
}
else
{
return false;
return;
}
}
elseif (is_array($lang) && isset($lang[$subkey]))
@ -346,7 +352,7 @@ class Lang
}
else
{
return false;
return;
}
}
else
@ -374,7 +380,7 @@ class Lang
* @param string $key
* @return bool
*/
public function __isset($key)
public function __isset(string $key): bool
{
foreach ($this->_loaded_plugins as $plugin_name => $translations)
{
@ -392,7 +398,7 @@ class Lang
* @param string $key
* @return void
*/
public function __unset($key)
public function __unset(string $key): void
{
$this->set($key, null);
}
@ -402,9 +408,9 @@ class Lang
*
* @param string $key
* @param mixed $args
* @return string|null
* @return mixed
*/
public function __call($key, $args = array())
public function __call(string $key, $args = array())
{
return $this->get($key, $args);
}

View file

@ -29,7 +29,7 @@ class i18n
* @param int $sort_by
* @return array
*/
public static function listCountries($sort_by = self::SORT_NAME_ENGLISH)
public static function listCountries(int $sort_by = self::SORT_NAME_ENGLISH): array
{
if (isset(self::$_countries[$sort_by]))
{
@ -92,10 +92,10 @@ class i18n
*
* This function returns null if a matching country is not found.
*
* @param $code Country code
* @return string|null
* @param string $code Country code
* @return ?string
*/
public static function getCallingCodeByCountryCode($code)
public static function getCallingCodeByCountryCode(string $code): ?string
{
$countries = self::listCountries();
if (strlen($code) === 3)
@ -122,10 +122,11 @@ class i18n
* This function may return the wrong country if two or more countries share a calling code.
* This function returns null if a matching country is not found.
*
* @param $code Calling code
* @return string|null
* @param string $code Calling code
* @param int $type (2 or 3)
* @return ?string
*/
public static function getCountryCodeByCallingCode($code, $type = 3)
public static function getCountryCodeByCallingCode(string $code, $type = 3): ?string
{
$countries = self::listCountries();
$code = preg_replace('/[^0-9]/', '', $code);
@ -133,12 +134,13 @@ class i18n
{
if (preg_replace('/[^0-9]/', '', $country->calling_code) === $code)
{
return $type == 3 ? $country->iso_3166_1_alpha3 : $country->iso_3166_1_alpha2;
return strval($type == 3 ? $country->iso_3166_1_alpha3 : $country->iso_3166_1_alpha2);
}
}
return null;
}
/**
* Format a phone number with country code.
*
@ -147,7 +149,7 @@ class i18n
* @param bool $pretty (optional)
* @return string
*/
public static function formatPhoneNumber($phone_number, $phone_country, $pretty = true)
public static function formatPhoneNumber(string $phone_number, string $phone_country, bool $pretty = true): string
{
if (!is_numeric($phone_country))
{
@ -156,11 +158,11 @@ class i18n
if ($pretty)
{
if ($phone_country == 82)
if ($phone_country === '82')
{
$pretty_phone_number = Korea::formatPhoneNumber($phone_number);
}
elseif ($phone_country == 1)
elseif ($phone_country === '1')
{
$digits = preg_replace('/[^0-9]/', '', $phone_number);
$pretty_phone_number = substr($digits, 0, 3) . '-' . substr($digits, 3, 3) . '-' . substr($digits, 6);
@ -173,7 +175,7 @@ class i18n
}
else
{
if (!in_array(strval($phone_country), array('39', '378', '379')))
if (!in_array($phone_country, array('39', '378', '379')))
{
$phone_number = preg_replace('/^0/', '', $phone_number);
}

View file

@ -14,7 +14,7 @@ abstract class BaseParser
* @param bool $normalize
* @return array
*/
protected static function _getAttributes(\SimpleXMLElement $element, $normalize = true): array
protected static function _getAttributes(\SimpleXMLElement $element, bool $normalize = true): array
{
$result = array();
foreach ($element->attributes() as $key => $val)

View file

@ -17,13 +17,13 @@ class ConfigParser
*
* @return array
*/
public static function convert()
public static function convert(): array
{
// Load DB info file.
if (file_exists(\RX_BASEDIR . Config::$old_db_config_filename))
if (file_exists(\RX_BASEDIR . Config::OLD_DB_CONFIG_PATH))
{
ob_start();
include \RX_BASEDIR . Config::$old_db_config_filename;
include \RX_BASEDIR . Config::OLD_DB_CONFIG_PATH;
ob_end_clean();
}
else
@ -32,18 +32,18 @@ class ConfigParser
}
// Load FTP info file.
if (file_exists(\RX_BASEDIR . Config::$old_ftp_config_filename))
if (file_exists(\RX_BASEDIR . Config::OLD_FTP_CONFIG_PATH))
{
ob_start();
include \RX_BASEDIR . Config::$old_ftp_config_filename;
include \RX_BASEDIR . Config::OLD_FTP_CONFIG_PATH;
ob_end_clean();
}
// Load selected language file.
if (file_exists(\RX_BASEDIR . Config::$old_lang_config_filename))
if (file_exists(\RX_BASEDIR . Config::OLD_LANG_CONFIG_PATH))
{
$lang_selected = array();
$lang_selected_raw = file_get_contents(\RX_BASEDIR . Config::$old_lang_config_filename);
$lang_selected_raw = file_get_contents(\RX_BASEDIR . Config::OLD_LANG_CONFIG_PATH);
$lang_selected_raw = array_map('trim', explode("\n", $lang_selected_raw));
foreach ($lang_selected_raw as $lang_selected_item)
{
@ -64,7 +64,7 @@ class ConfigParser
}
// Load defaults for the new configuration.
$config = (include \RX_BASEDIR . Config::$default_config_filename);
$config = (include \RX_BASEDIR . Config::DEFAULT_CONFIG_PATH);
// Convert database configuration.
if (!isset($db_info->master_db))

View file

@ -30,7 +30,7 @@ function config(string $key, $value = null)
*
* @param string $code Lang variable name
* @param string $value `$code`s value
* @return mixed
* @return string|null|\ArrayObject
*/
function lang(string $code, $value = null)
{