type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-14 14:06:22 +02:00
parent bb2259232e
commit cd3a2bbc80
4 changed files with 31 additions and 9 deletions

View File

@@ -50,7 +50,7 @@ class Helper
* foreignType?: string,
* nearKey?: string,
* distantKey?: string,
* typeKey?: string
* typeKey?: string,
* }
*/
public function getRelationKeys(Entity $entity, string $relationName): array

View File

@@ -293,7 +293,7 @@ class SelectBuilder implements Builder
/**
* @param array<Expression|Selection|mixed[]> $itemList
* @return array<array{string,string}>
* @return array<array{0:string,1?:string}|string>
*/
private function normilizeSelectExpressionArray(array $itemList): array
{
@@ -315,6 +315,7 @@ class SelectBuilder implements Builder
}
if (!is_array($item) || !count($item) || !$item[0] instanceof Expression) {
/** @var array{0:string,1?:string} $item */
$resultList[] = $item;
continue;
@@ -326,6 +327,8 @@ class SelectBuilder implements Builder
$newItem[] = $item[1];
}
/** @var array{0:string,1?:string} $newItem */
$resultList[] = $newItem;
continue;

View File

@@ -327,7 +327,7 @@ trait SelectingBuilderTrait
/**
* @param array<Expression|mixed[]> $itemList
* @return array<array{string,string}>
* @return array<array{0:string,1?:string}|string>
*/
private function normilizeExpressionItemArray(array $itemList): array
{
@@ -341,6 +341,7 @@ trait SelectingBuilderTrait
}
if (!is_array($item) || !count($item) || !$item[0] instanceof Expression) {
/** @var array{0:string,1?:string} $item */
$resultList[] = $item;
continue;
@@ -352,6 +353,8 @@ trait SelectingBuilderTrait
$newItem[] = $item[1];
}
/** @var array{0:string,1?:string} $newItem */
$resultList[] = $newItem;
continue;
@@ -361,7 +364,7 @@ trait SelectingBuilderTrait
}
/**
* @param array<Order|mixed[]> $itemList
* @param array<Order|mixed[]|string> $itemList
* @param string|bool|null $direction
* @return array<array{string,string|bool}>
*/

View File

@@ -1632,6 +1632,7 @@ abstract class BaseQueryComposer implements QueryComposer
foreach ($j[2] as $k => $value) {
$value = str_replace('{alias}', $alias, $value);
/** @var string */
$left = $k;
$left = str_replace('{alias}', $alias, $left);
@@ -1670,6 +1671,7 @@ abstract class BaseQueryComposer implements QueryComposer
foreach ($j[2] as $k => $value) {
$value = str_replace('{alias}', $alias, $value);
/** @var string */
$left = $k;
$left = str_replace('{alias}', $alias, $left);
@@ -1898,6 +1900,8 @@ abstract class BaseQueryComposer implements QueryComposer
}
}
/** @var string $alias */
// @todo Make VALUE: usage deprecated.
if (is_string($expression) && stripos($expression, 'VALUE:') === 0) {
$part = $this->quote(
@@ -1943,6 +1947,7 @@ abstract class BaseQueryComposer implements QueryComposer
return null;
}
/** @var string */
$part = $this->getAttributePath($entity, $attribute0, $params);
return [$part, $alias];
@@ -1974,6 +1979,7 @@ abstract class BaseQueryComposer implements QueryComposer
return null;
}
/** @var string */
$fieldPath = $this->getAttributePath($entity, $attribute, $params);
if ($attributeType === Entity::TEXT && $maxTextColumnsLength !== null) {
@@ -2082,17 +2088,19 @@ abstract class BaseQueryComposer implements QueryComposer
$relationsToJoin = [];
if (is_array($select)) {
foreach ($select as $item) {
$field = $item;
if (is_array($item)) {
if (count($field) == 0) {
if (count($item) == 0) {
continue;
}
$field = $item[0];
}
/** @var string $field */
if (
$entity->getAttributeType($field) == 'foreign' &&
$this->getAttributeParam($entity, $field, 'relation')
@@ -3200,8 +3208,12 @@ abstract class BaseQueryComposer implements QueryComposer
case Entity::MANY_MANY:
$key = $keySet['key'];
$foreignKey = $keySet['foreignKey'];
$nearKey = $keySet['nearKey'];
$distantKey = $keySet['distantKey'];
$nearKey = $keySet['nearKey'] ?? null;
$distantKey = $keySet['distantKey'] ?? null;
if ($nearKey === null || $distantKey === null) {
throw new RuntimeException("Bad relation key.");
}
$relTable = $this->toDb(
$this->getRelationParam($entity, $relationName, 'relationName')
@@ -3316,7 +3328,11 @@ abstract class BaseQueryComposer implements QueryComposer
case Entity::HAS_CHILDREN:
$foreignKey = $keySet['foreignKey'];
$foreignType = $keySet['foreignType'];
$foreignType = $keySet['foreignType'] ?? null;
if ($foreignType === null) {
throw new RuntimeException("Bad relation key.");
}
$distantTable = $this->toDb($foreignEntityType);