type fixes

This commit is contained in:
Yuri Kuznetsov
2022-02-21 13:27:00 +02:00
parent 32abc4b554
commit 0598e82196
2 changed files with 255 additions and 37 deletions
@@ -56,7 +56,10 @@ use LogicException;
*/ */
abstract class BaseQueryComposer implements QueryComposer abstract class BaseQueryComposer implements QueryComposer
{ {
// @todo Remove. /**
* @var string[]
* @todo Remove.
*/
protected const PARAM_LIST = [ protected const PARAM_LIST = [
'select', 'select',
'whereClause', 'whereClause',
@@ -87,12 +90,18 @@ abstract class BaseQueryComposer implements QueryComposer
'forShare', 'forShare',
]; ];
/**
* @var string[]
*/
protected const SQL_OPERATORS = [ protected const SQL_OPERATORS = [
'OR', 'OR',
'AND', 'AND',
]; ];
protected $comparisonOperators = [ /**
* @var array<string,string>
*/
protected array $comparisonOperators = [
'!=s' => 'NOT IN', '!=s' => 'NOT IN',
'=s' => 'IN', '=s' => 'IN',
'!=' => '<>', '!=' => '<>',
@@ -105,7 +114,10 @@ abstract class BaseQueryComposer implements QueryComposer
'=' => '=', '=' => '=',
]; ];
protected $comparisonFunctionOperatorMap = [ /**
* @var array<string,string>
*/
protected array $comparisonFunctionOperatorMap = [
'LIKE' => 'LIKE', 'LIKE' => 'LIKE',
'NOT_LIKE' => 'NOT LIKE', 'NOT_LIKE' => 'NOT LIKE',
'EQUAL' => '=', 'EQUAL' => '=',
@@ -120,7 +132,10 @@ abstract class BaseQueryComposer implements QueryComposer
'NOT_IN' => 'NOT IN', 'NOT_IN' => 'NOT IN',
]; ];
protected $mathFunctionOperatorMap = [ /**
* @var array<string,string>
*/
protected array $mathFunctionOperatorMap = [
'ADD' => '+', 'ADD' => '+',
'SUB' => '-', 'SUB' => '-',
'MUL' => '*', 'MUL' => '*',
@@ -128,7 +143,10 @@ abstract class BaseQueryComposer implements QueryComposer
'MOD' => '%', 'MOD' => '%',
]; ];
protected $matchFunctionMap = [ /**
* @var array<string,string>
*/
protected array $matchFunctionMap = [
'MATCH_BOOLEAN' => 'IN BOOLEAN MODE', 'MATCH_BOOLEAN' => 'IN BOOLEAN MODE',
'MATCH_NATURAL_LANGUAGE' => 'IN NATURAL LANGUAGE MODE', 'MATCH_NATURAL_LANGUAGE' => 'IN NATURAL LANGUAGE MODE',
'MATCH_QUERY_EXPANSION' => 'WITH QUERY EXPANSION', 'MATCH_QUERY_EXPANSION' => 'WITH QUERY EXPANSION',
@@ -142,34 +160,31 @@ abstract class BaseQueryComposer implements QueryComposer
protected const INSERT_METHOD = 'INSERT'; protected const INSERT_METHOD = 'INSERT';
protected $identifierQuoteCharacter = '`'; protected string $identifierQuoteCharacter = '`';
protected EntityFactory $entityFactory;
protected PDO $pdo;
protected Metadata $metadata;
protected ?FunctionConverterFactory $functionConverterFactory;
protected Helper $helper;
/** /**
* @var EntityFactory * @var array<string,string>
*/ */
protected $entityFactory; protected array $attributeDbMapCache = [];
/** /**
* @var PDO * @var array<string,array<string,string>>
*/ */
protected $pdo;
/**
* @var Metadata
*/
protected $metadata;
/**
* @var FunctionConverterFactory|null
*/
protected $functionConverterFactory;
protected $helper;
protected $attributeDbMapCache = [];
protected $aliasesCache = []; protected $aliasesCache = [];
/**
* @var array<string,Entity>
*/
protected $seedCache = []; protected $seedCache = [];
public function __construct( public function __construct(
@@ -288,7 +303,8 @@ abstract class BaseQueryComposer implements QueryComposer
/** /**
* @deprecated * @deprecated
* @todo Remove in 6.5. * @todo Remove in v7.3.
* @param array<string,mixed>|null $params
*/ */
public function createSelectQuery(string $entityType, ?array $params = null): string public function createSelectQuery(string $entityType, ?array $params = null): string
{ {
@@ -299,7 +315,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $this->compose(SelectQuery::fromRaw($params)); return $this->compose(SelectQuery::fromRaw($params));
} }
protected function createDeleteQuery(array $params = null): string /**
* @param array<string,mixed>|null $params
*/
protected function createDeleteQuery(?array $params = null): string
{ {
$params = $this->normilizeParams(self::DELETE_METHOD, $params); $params = $this->normilizeParams(self::DELETE_METHOD, $params);
@@ -331,7 +350,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
protected function createUpdateQuery(array $params = null): string /**
* @param array<string,mixed>|null $params
*/
protected function createUpdateQuery(?array $params = null): string
{ {
$params = $this->normilizeParams(self::UPDATE_METHOD, $params); $params = $this->normilizeParams(self::UPDATE_METHOD, $params);
@@ -359,7 +381,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
protected function createInsertQuery(array $params): string /**
* @param array<string,mixed>|null $params
*/
protected function createInsertQuery(?array $params): string
{ {
$params = $this->normilizeInsertParams($params); $params = $this->normilizeInsertParams($params);
@@ -382,7 +407,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $this->composeInsertQuery($this->toDb($entityType), $columnsPart, $valuesPart, $updatePart); return $this->composeInsertQuery($this->toDb($entityType), $columnsPart, $valuesPart, $updatePart);
} }
protected function getInsertValuesPart(string $entityType, array $params) /**
* @param array<string,mixed> $params
*/
protected function getInsertValuesPart(string $entityType, array $params): string
{ {
$isMass = $params['isMass']; $isMass = $params['isMass'];
$isBySelect = $params['isBySelect']; $isBySelect = $params['isBySelect'];
@@ -398,15 +426,20 @@ abstract class BaseQueryComposer implements QueryComposer
if ($isMass) { if ($isMass) {
$list = []; $list = [];
foreach ($values as $item) { foreach ($values as $item) {
$list[] = '(' . $this->getInsertValuesItemPart($columns, $item) . ')'; $list[] = '(' . $this->getInsertValuesItemPart($columns, $item) . ')';
} }
return 'VALUES ' . implode(', ', $list); return 'VALUES ' . implode(', ', $list);
} }
return 'VALUES (' . $this->getInsertValuesItemPart($columns, $values) . ')'; return 'VALUES (' . $this->getInsertValuesItemPart($columns, $values) . ')';
} }
/**
* @param array<string,mixed> $params
*/
protected function createUnionQuery(array $params): string protected function createUnionQuery(array $params): string
{ {
$selectQueryList = $params['queries'] ?? []; $selectQueryList = $params['queries'] ?? [];
@@ -449,7 +482,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
protected function getUnionOrderPart(array $orderBy) /**
* @param array<string|mixed[]> $orderBy
*/
protected function getUnionOrderPart(array $orderBy): string
{ {
$orderByParts = []; $orderByParts = [];
@@ -474,6 +510,10 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(', ', $orderByParts); return implode(', ', $orderByParts);
} }
/**
* @param array<string,mixed> $params
* @return array<string,mixed>
*/
protected function normilizeInsertParams(array $params): array protected function normilizeInsertParams(array $params): array
{ {
$columns = $params['columns'] ?? null; $columns = $params['columns'] ?? null;
@@ -535,6 +575,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $params; return $params;
} }
/**
* @param array<string,mixed>|null $params
* @return array<string,mixed>
*/
protected function normilizeParams(string $method, ?array $params): array protected function normilizeParams(string $method, ?array $params): array
{ {
$params = $params ?? []; $params = $params ?? [];
@@ -572,7 +616,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $params; return $params;
} }
protected function createSelectQueryInternal(array $params = null): string /**
* @param array<string,mixed>|null $params
*/
protected function createSelectQueryInternal(?array $params = null): string
{ {
$params = $this->normilizeParams(self::SELECT_METHOD, $params); $params = $this->normilizeParams(self::SELECT_METHOD, $params);
@@ -737,6 +784,9 @@ abstract class BaseQueryComposer implements QueryComposer
"FROM ({$sql}) AS " . $this->quoteIdentifier('countAlias'); "FROM ({$sql}) AS " . $this->quoteIdentifier('countAlias');
} }
/**
* @param array<string,mixed> $params
*/
protected function createSelectQueryNoFrom(array $params): string protected function createSelectQueryNoFrom(array $params): string
{ {
$selectPart = $this->getSelectPart(null, $params); $selectPart = $this->getSelectPart(null, $params);
@@ -749,6 +799,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
/**
* @param array<string,mixed> $params
* @return string[]|null
*/
protected function getIndexKeyList(string $entityType, array $params): ?array protected function getIndexKeyList(string $entityType, array $params): ?array
{ {
$indexKeyList = []; $indexKeyList = [];
@@ -773,6 +827,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $indexKeyList; return $indexKeyList;
} }
/**
* @param array<string,mixed> $params
*/
protected function getJoinsPart(Entity $entity, array $params, bool $includeBelongsTo = false): string protected function getJoinsPart(Entity $entity, array $params, bool $includeBelongsTo = false): string
{ {
$joinsPart = ''; $joinsPart = '';
@@ -835,6 +892,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $joinsPart; return $joinsPart;
} }
/**
* @param array<string,mixed> $params
*/
protected function getGroupByPart(Entity $entity, array $params): ?string protected function getGroupByPart(Entity $entity, array $params): ?string
{ {
if (empty($params['groupBy'])) { if (empty($params['groupBy'])) {
@@ -850,6 +910,9 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(', ', $list); return implode(', ', $list);
} }
/**
* @param array<string,mixed> $params
*/
protected function getAdditionalSelect(Entity $entity, array $params): ?string protected function getAdditionalSelect(Entity $entity, array $params): ?string
{ {
if (!empty($params['strictSelect'])) { if (!empty($params['strictSelect'])) {
@@ -891,6 +954,7 @@ abstract class BaseQueryComposer implements QueryComposer
/** /**
* @param string[] $argumentPartList * @param string[] $argumentPartList
* @param array<string,mixed> $params
*/ */
protected function getFunctionPart( protected function getFunctionPart(
string $function, string $function,
@@ -1094,6 +1158,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $function . '(' . $part . ')'; return $function . '(' . $part . ')';
} }
/**
* @param string[] $argumentPartList
*/
private function getFunctionPartFromFactory(string $function, array $argumentPartList): string private function getFunctionPartFromFactory(string $function, array $argumentPartList): string
{ {
assert($this->functionConverterFactory !== null); assert($this->functionConverterFactory !== null);
@@ -1103,7 +1170,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $obj->convert(...$argumentPartList); return $obj->convert(...$argumentPartList);
} }
protected function getFunctionPartTZ(?array $argumentPartList = null) /**
* @param string[]|null $argumentPartList
*/
protected function getFunctionPartTZ(?array $argumentPartList = null): string
{ {
if (!$argumentPartList || count($argumentPartList) < 2) { if (!$argumentPartList || count($argumentPartList) < 2) {
throw new RuntimeException("ORM Query: Not enough arguments for function TZ."); throw new RuntimeException("ORM Query: Not enough arguments for function TZ.");
@@ -1135,6 +1205,9 @@ abstract class BaseQueryComposer implements QueryComposer
return "CONVERT_TZ(". $argumentPartList[0]. ", '+00:00', " . $this->quote($offsetString) . ")"; return "CONVERT_TZ(". $argumentPartList[0]. ", '+00:00', " . $this->quote($offsetString) . ")";
} }
/**
* @param array<string,mixed> $params
*/
protected function convertMatchExpression(Entity $entity, string $expression, array $params): string protected function convertMatchExpression(Entity $entity, string $expression, array $params): string
{ {
$delimiterPosition = strpos($expression, ':'); $delimiterPosition = strpos($expression, ':');
@@ -1194,12 +1267,16 @@ abstract class BaseQueryComposer implements QueryComposer
return $result; return $result;
} }
/**
* @param array<string,mixed> $params
*/
protected function convertComplexExpression( protected function convertComplexExpression(
?Entity $entity, ?Entity $entity,
string $attribute, string $attribute,
bool $distinct, bool $distinct,
array &$params array &$params
): string { ): string {
$function = null; $function = null;
if (!$entity) { if (!$entity) {
@@ -1262,15 +1339,23 @@ abstract class BaseQueryComposer implements QueryComposer
return $part; return $part;
} }
/**
* @return string[]
* @deprecated
*/
public static function getAllAttributesFromComplexExpression(string $expression): array public static function getAllAttributesFromComplexExpression(string $expression): array
{ {
return Util::getAllAttributesFromComplexExpression($expression); return Util::getAllAttributesFromComplexExpression($expression);
} }
/**
* @param array<string,mixed> $params
*/
protected function getFunctionArgumentPart( protected function getFunctionArgumentPart(
Entity $entity, Entity $entity,
string $attribute, string $attribute,
bool $distinct, array &$params bool $distinct,
array &$params
): string { ): string {
$argument = $attribute; $argument = $attribute;
@@ -1348,6 +1433,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $part; return $part;
} }
/**
* @param array<string,mixed>|null $params
*/
protected function getFromAlias(?array $params = null, ?string $entityType = null): string protected function getFromAlias(?array $params = null, ?string $entityType = null): string
{ {
$params = $params ?? []; $params = $params ?? [];
@@ -1371,6 +1459,9 @@ abstract class BaseQueryComposer implements QueryComposer
throw new RuntimeException(); throw new RuntimeException();
} }
/**
* @param array<string,mixed>|null $params
*/
protected function getAttributeOrderSql( protected function getAttributeOrderSql(
Entity $entity, Entity $entity,
string $attribute, string $attribute,
@@ -1447,6 +1538,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $part; return $part;
} }
/**
* @param array<string,mixed>|null $params
*/
protected function getAttributeSql( protected function getAttributeSql(
Entity $entity, Entity $entity,
string $attribute, string $attribute,
@@ -1501,6 +1595,10 @@ abstract class BaseQueryComposer implements QueryComposer
); );
} }
/**
* @param array<string,mixed> $defs
* @param array<string,mixed> $params
*/
protected function applyAttributeCustomParams( protected function applyAttributeCustomParams(
array $defs, array $defs,
array &$params, array &$params,
@@ -1601,6 +1699,10 @@ abstract class BaseQueryComposer implements QueryComposer
} }
} }
/**
* @param array<string,mixed> $params
* @return string[]
*/
protected function getOrderByAttributeList(array $params): array protected function getOrderByAttributeList(array $params): array
{ {
$value = $params['orderBy'] ?? null; $value = $params['orderBy'] ?? null;
@@ -1645,6 +1747,12 @@ abstract class BaseQueryComposer implements QueryComposer
return $list; return $list;
} }
/**
*
* @param string[]|array<string[]> $itemList
* @param string[]|array<string[]> $newItemList
* @return string[]|array<string[]>
*/
protected function getNotIntersectingSelectItemList(array $itemList, array $newItemList): array protected function getNotIntersectingSelectItemList(array $itemList, array $newItemList): array
{ {
$list = []; $list = [];
@@ -1669,6 +1777,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $list; return $list;
} }
/**
* @param array<string,mixed> $params
*/
protected function getSelectPart(?Entity $entity, array &$params): string protected function getSelectPart(?Entity $entity, array &$params): string
{ {
$itemList = $params['select'] ?? []; $itemList = $params['select'] ?? [];
@@ -1750,7 +1861,9 @@ abstract class BaseQueryComposer implements QueryComposer
} }
/** /**
* @param array<string,mixed> $params
* @param string|string[] $attribute * @param string|string[] $attribute
* @return array{string,string}|null
*/ */
protected function getSelectPartItemPair(?Entity $entity, array &$params, $attribute): ?array protected function getSelectPartItemPair(?Entity $entity, array &$params, $attribute): ?array
{ {
@@ -1870,6 +1983,10 @@ abstract class BaseQueryComposer implements QueryComposer
return [$fieldPath, $attribute]; return [$fieldPath, $attribute];
} }
/**
* @param string[]|array<string[]> $itemList
* @return string[]|array<string[]>
*/
protected function getSelectDependeeAdditionalList(Entity $entity, array $itemList): array protected function getSelectDependeeAdditionalList(Entity $entity, array $itemList): array
{ {
$additionalList = []; $additionalList = [];
@@ -1896,6 +2013,9 @@ abstract class BaseQueryComposer implements QueryComposer
); );
} }
/**
* @param array<string,mixed>|null $params
*/
protected function getBelongsToJoinItemPart( protected function getBelongsToJoinItemPart(
Entity $entity, Entity $entity,
string $relationName, string $relationName,
@@ -1931,6 +2051,9 @@ abstract class BaseQueryComposer implements QueryComposer
"{$alias}." . $this->toDb($foreignKey); "{$alias}." . $this->toDb($foreignKey);
} }
/**
* @param array<string,mixed> $params
*/
protected function getSelectTailPart(array $params): ?string protected function getSelectTailPart(array $params): ?string
{ {
$forShare = $params['forShare'] ?? null; $forShare = $params['forShare'] ?? null;
@@ -1947,6 +2070,11 @@ abstract class BaseQueryComposer implements QueryComposer
return null; return null;
} }
/**
* @param string[]|array<string[]> $select
* @param string[] $skipList
* @param array<string,mixed> $params
*/
protected function getBelongsToJoinsPart(Entity $entity, ?array $select, array $skipList, array $params): string protected function getBelongsToJoinsPart(Entity $entity, ?array $select, array $skipList, array $params): string
{ {
$joinsArr = []; $joinsArr = [];
@@ -2034,6 +2162,9 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(' ', $joinsArr); return implode(' ', $joinsArr);
} }
/**
* @param array<string[]|string> $select
*/
protected static function isSelectAll(array $select): bool protected static function isSelectAll(array $select): bool
{ {
if (!count($select)) { if (!count($select)) {
@@ -2043,6 +2174,11 @@ abstract class BaseQueryComposer implements QueryComposer
return $select[0] === '*'; return $select[0] === '*';
} }
/**
* @param array<string,mixed>|null $params
* @param mixed $orderBy
* @param mixed $order
*/
protected function getOrderExpressionPart( protected function getOrderExpressionPart(
Entity $entity, Entity $entity,
$orderBy = null, $orderBy = null,
@@ -2132,11 +2268,19 @@ abstract class BaseQueryComposer implements QueryComposer
return "{$fieldPath} " . $order; return "{$fieldPath} " . $order;
} }
/**
* @param array<string,mixed>|null $params
* @param mixed $orderBy
* @param mixed $order
*/
protected function getOrderPart(Entity $entity, $orderBy = null, $order = null, &$params = null): ?string protected function getOrderPart(Entity $entity, $orderBy = null, $order = null, &$params = null): ?string
{ {
return $this->getOrderExpressionPart($entity, $orderBy, $order, $params); return $this->getOrderExpressionPart($entity, $orderBy, $order, $params);
} }
/**
* @param array<string,mixed> $params
*/
protected function getAttributePathForOrderBy(Entity $entity, string $orderBy, array $params): ?string protected function getAttributePathForOrderBy(Entity $entity, string $orderBy, array $params): ?string
{ {
if (Util::isComplexExpression($orderBy)) { if (Util::isComplexExpression($orderBy)) {
@@ -2151,6 +2295,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $this->getAttributePath($entity, $orderBy, $params); return $this->getAttributePath($entity, $orderBy, $params);
} }
/**
* @param array<string,mixed> $params
*/
protected function getAggregationSelectPart( protected function getAggregationSelectPart(
Entity $entity, Entity $entity,
string $aggregation, string $aggregation,
@@ -2187,6 +2334,7 @@ abstract class BaseQueryComposer implements QueryComposer
* Quote a value (if needed). * Quote a value (if needed).
* @deprecated * @deprecated
* @todo Make protected in 6.5. * @todo Make protected in 6.5.
* @param mixed $value
*/ */
public function quote($value): string public function quote($value): string
{ {
@@ -2222,6 +2370,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $this->attributeDbMapCache[$string]; return $this->attributeDbMapCache[$string];
} }
/**
* @param array<string> $matches
*/
protected function toDbMatchConversion(array $matches): string protected function toDbMatchConversion(array $matches): string
{ {
return '_' . strtolower($matches[1]); return '_' . strtolower($matches[1]);
@@ -2240,6 +2391,9 @@ abstract class BaseQueryComposer implements QueryComposer
return null; return null;
} }
/**
* @return array<string,string>
*/
protected function getTableAliases(Entity $entity): array protected function getTableAliases(Entity $entity): array
{ {
$aliases = []; $aliases = [];
@@ -2273,6 +2427,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $aliases; return $aliases;
} }
/**
* @param array<string,mixed> $params
*/
protected function getAttributePath(Entity $entity, string $attribute, array &$params): ?string protected function getAttributePath(Entity $entity, string $attribute, array &$params): ?string
{ {
if (!$entity->hasAttribute($attribute)) { if (!$entity->hasAttribute($attribute)) {
@@ -2341,6 +2498,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $alias . '.' . $this->toDb($this->sanitize($attribute)); return $alias . '.' . $this->toDb($this->sanitize($attribute));
} }
/**
* @param array<string,mixed> $params
* @param array<mixed,mixed> $whereClause
*/
protected function getWherePart( protected function getWherePart(
Entity $entity, Entity $entity,
?array $whereClause = null, ?array $whereClause = null,
@@ -2367,6 +2528,11 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(" " . $sqlOp . " ", $wherePartList); return implode(" " . $sqlOp . " ", $wherePartList);
} }
/**
* @param array<string,mixed> $params
* @param mixed $leftKey
* @param mixed $value
*/
protected function getWherePartItem( protected function getWherePartItem(
Entity $entity, Entity $entity,
$leftKey, $leftKey,
@@ -2663,6 +2829,12 @@ abstract class BaseQueryComposer implements QueryComposer
return $leftPart . " " . $operator . " " . $this->quote($value); return $leftPart . " " . $operator . " " . $this->quote($value);
} }
/**
*
* @param array<mixed,mixed> $whereClause
* @param mixed $value
* @return array<mixed,mixed>
*/
protected function applyValueToCustomWhereClause(array $whereClause, $value): array protected function applyValueToCustomWhereClause(array $whereClause, $value): array
{ {
$modified = []; $modified = [];
@@ -2685,7 +2857,8 @@ abstract class BaseQueryComposer implements QueryComposer
} }
/** /**
* @param array|string $j * @param array<string>|string $j
* @return string
*/ */
protected function obtainJoinAlias($j) protected function obtainJoinAlias($j)
{ {
@@ -2707,6 +2880,9 @@ abstract class BaseQueryComposer implements QueryComposer
return $joinAlias; return $joinAlias;
} }
/**
* @param mixed $value
*/
protected function stringifyValue($value): string protected function stringifyValue($value): string
{ {
if (is_array($value)) { if (is_array($value)) {
@@ -2756,6 +2932,11 @@ abstract class BaseQueryComposer implements QueryComposer
return preg_replace('/[^A-Za-z0-9_]+/', '', $string) ?? ''; return preg_replace('/[^A-Za-z0-9_]+/', '', $string) ?? '';
} }
/**
* @param array<string,mixed> $params
* @param array<mixed,mixed> $joinConditions
* @param array<string,mixed[]> $joins
*/
protected function getJoinsTypePart( protected function getJoinsTypePart(
Entity $entity, Entity $entity,
array $joins, array $joins,
@@ -2821,8 +3002,20 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(' ', $joinSqlList); return implode(' ', $joinSqlList);
} }
protected function buildJoinConditionStatement(Entity $entity, $alias, $left, $right, array $params) /**
{ * @param array<string,mixed> $params
* @param string $alias
* @param mixed $left
* @param mixed $right
*/
protected function buildJoinConditionStatement(
Entity $entity,
string $alias,
$left,
$right,
array $params
): string {
$sql = ''; $sql = '';
if (is_array($right) && (is_int($left) || in_array($left, ['AND', 'OR']))) { if (is_array($right) && (is_int($left) || in_array($left, ['AND', 'OR']))) {
@@ -2833,6 +3026,7 @@ abstract class BaseQueryComposer implements QueryComposer
} }
$sqlList = []; $sqlList = [];
foreach ($right as $k => $v) { foreach ($right as $k => $v) {
$sqlList[] = $this->buildJoinConditionStatement($entity, $alias, $k, $v, $params); $sqlList[] = $this->buildJoinConditionStatement($entity, $alias, $k, $v, $params);
} }
@@ -2912,6 +3106,7 @@ abstract class BaseQueryComposer implements QueryComposer
} else if ($operator === '<>') { } else if ($operator === '<>') {
$sql .= " IS NOT NULL"; $sql .= " IS NOT NULL";
} }
return $sql; return $sql;
} }
@@ -2928,6 +3123,11 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
/**
* @param array<string,mixed> $params
* @param array<string,mixed> $joinParams
* @param array<mixed,mixed> $conditions
*/
protected function getJoinItemPart( protected function getJoinItemPart(
Entity $entity, Entity $entity,
string $name, string $name,
@@ -3151,6 +3351,9 @@ abstract class BaseQueryComposer implements QueryComposer
return ''; return '';
} }
/**
* @param string[]|null $indexKeyList
*/
protected function composeSelectQuery( protected function composeSelectQuery(
?string $from, ?string $from,
string $select, string $select,
@@ -3311,6 +3514,10 @@ abstract class BaseQueryComposer implements QueryComposer
return $sql; return $sql;
} }
/**
* @param array<string,mixed> $values
* @param array<string,mixed> $params
*/
protected function getSetPart(Entity $entity, array $values, array $params): string protected function getSetPart(Entity $entity, array $values, array $params): string
{ {
if (!count($values)) { if (!count($values)) {
@@ -3351,6 +3558,9 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(', ', $list); return implode(', ', $list);
} }
/**
* @param string[] $columnList
*/
protected function getInsertColumnsPart(array $columnList): string protected function getInsertColumnsPart(array $columnList): string
{ {
$list = []; $list = [];
@@ -3366,6 +3576,10 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(', ', $list); return implode(', ', $list);
} }
/**
* @param string[] $columnList
* @param array<string,mixed> $values
*/
protected function getInsertValuesItemPart(array $columnList, array $values): string protected function getInsertValuesItemPart(array $columnList, array $values): string
{ {
$list = []; $list = [];
@@ -3377,6 +3591,9 @@ abstract class BaseQueryComposer implements QueryComposer
return implode(', ', $list); return implode(', ', $list);
} }
/**
* @param array<string,mixed> $values
*/
protected function getInsertUpdatePart(array $values): string protected function getInsertUpdatePart(array $values): string
{ {
$list = []; $list = [];
+1
View File
@@ -1,6 +1,7 @@
parameters: parameters:
level: 5 level: 5
inferPrivatePropertyTypeFromConstructor: true inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
paths: paths:
- application - application
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false