Clean up missing or inconsistent types in remainder of parser classes

This commit is contained in:
Kijin Sung 2023-10-03 16:35:20 +09:00
parent 141ee7f7e1
commit c01ba1d3cf
4 changed files with 20 additions and 20 deletions

View file

@ -11,15 +11,15 @@ class DBQueryParser extends BaseParser
* Load a query XML file.
*
* @param string $filename
* @return object|false
* @return ?object
*/
public static function loadXML(string $filename)
public static function loadXML(string $filename): ?object
{
// Load the XML file.
$xml = simplexml_load_string(file_get_contents($filename));
if ($xml === false)
{
return false;
return null;
}
// Parse the query.

View file

@ -10,7 +10,7 @@ class DBTableParser extends BaseParser
/**
* Mapping for XE-compatible types.
*/
protected static $_xe_types = array(
protected const XE_COMPAT_TYPES = array(
'bignumber' => 'bigint',
'number' => 'bigint',
'bigtext' => 'longtext',
@ -20,7 +20,7 @@ class DBTableParser extends BaseParser
/**
* List of types for which the size attribute will be ignored.
*/
protected static $_nosize_types = array(
protected const NO_SIZE_TYPES = array(
'bigint' => true,
'int' => true,
'integer' => true,
@ -31,9 +31,9 @@ class DBTableParser extends BaseParser
*
* @param string $filename
* @param string $content
* @return object|false
* @return ?object
*/
public static function loadXML(string $filename = '', string $content = '')
public static function loadXML(string $filename = '', string $content = ''): object
{
// Load the XML content.
if ($content)
@ -47,7 +47,7 @@ class DBTableParser extends BaseParser
if ($xml === false)
{
return false;
return null;
}
// Initialize table definition.
@ -225,10 +225,10 @@ class DBTableParser extends BaseParser
public static function getTypeAndSize(string $type, string $size): array
{
// Map XE-compatible types to database native types.
if (isset(self::$_xe_types[$type]))
if (isset(self::XE_COMPAT_TYPES[$type]))
{
$xetype = $type;
$type = self::$_xe_types[$type];
$type = self::XE_COMPAT_TYPES[$type];
}
else
{
@ -243,7 +243,7 @@ class DBTableParser extends BaseParser
$size = $matches[2];
}
$size = implode(',', array_map('trim', explode(',', $size))) ?: null;
if (isset(self::$_nosize_types[$type]))
if (isset(self::NO_SIZE_TYPES[$type]))
{
$size = null;
}

View file

@ -99,7 +99,7 @@ class Query extends VariableBase
*
* @return array
*/
public function getQueryParams()
public function getQueryParams(): array
{
return $this->_params;
}
@ -596,7 +596,7 @@ class Query extends VariableBase
/**
* Generate a ORDER BY clause from navigation settings.
*
* @param object $navigation
* @param Navigation $navigation
* @return string
*/
protected function _arrangeOrderBy(Navigation $navigation): string
@ -643,7 +643,7 @@ class Query extends VariableBase
/**
* Generate a LIMIT/OFFSET clause from navigation settings.
*
* @param object $navigation
* @param Navigation $navigation
* @return string
*/
protected function _arrangeLimitOffset(Navigation $navigation): string
@ -688,7 +688,7 @@ class Query extends VariableBase
/**
* Generate each condition in a WHERE clause.
*
* @param object $condition
* @param VariableBase $condition
* @return string
*/
protected function _parseCondition(VariableBase $condition): string
@ -736,7 +736,7 @@ class Query extends VariableBase
* @param bool $allow_empty_string
* @return bool
*/
public static function isValidVariable($var, $allow_empty_string = true): bool
public static function isValidVariable($var, bool $allow_empty_string = true): bool
{
if ($var === null || ($var === '' && !$allow_empty_string))
{

View file

@ -284,7 +284,7 @@ class VariableBase
* @param array $args
* @return array
*/
public function getValue(array $args)
public function getValue(array $args): array
{
if ($this->var && Query::isValidVariable($args[$this->var] ?? null, $this instanceof ColumnWrite))
{
@ -324,7 +324,7 @@ class VariableBase
*
* @return array
*/
public function getDefaultValue()
public function getDefaultValue(): array
{
// Get the current column name.
$column = $this instanceof ColumnWrite ? $this->name : ($this->column ?? null);
@ -390,7 +390,7 @@ class VariableBase
* @param mixed $value
* @return void
*/
public function filterValue($value)
public function filterValue($value): void
{
// Don't apply a filter if there is no variable.
$column = $this instanceof ColumnWrite ? $this->name : $this->column;
@ -465,7 +465,7 @@ class VariableBase
* @param string $value
* @return array
*/
protected function _parseSearchKeywords($column, $value)
protected function _parseSearchKeywords(string $column, string $value): array
{
// Initialze the return values.
$where = '';