Fix #20634: Fix PHPDoc annotations in yii\db namespace. Add PHPStan/Psalm annotations for yii\db\SqlTokenizer::startsWithAnyLongest()

This commit is contained in:
Maksim Spirkov
2025-10-25 22:19:58 +03:00
committed by GitHub
parent 122e95216f
commit dd4c091e66
7 changed files with 11 additions and 5 deletions

View File

@@ -67,6 +67,7 @@ Yii Framework 2 Change Log
- Bug #20617: Fix `@return` annotation for `DataColumn::getDataCellValue()` (mspirkov)
- Bug #20628: Fix `@return` annotations for `lastInsertId` methods in `yii\db\mssql` namespace (mspirkov)
- Bug #20630: Fix `@var` annotations for `yii\web\CompositeUrlRule::$rules` and `yii\web\GroupUrlRule::$rules` (mspirkov)
- Bug #20634: Fix PHPDoc annotations in `yii\db` namespace. Add PHPStan/Psalm annotations for `yii\db\SqlTokenizer::startsWithAnyLongest()` (mspirkov)
- Bug #20636: Fix `@param` annotations for `$message` in logging methods (mspirkov)

View File

@@ -223,7 +223,7 @@ class DynamicModel extends Model
*/
public static function validateData(array $data, $rules = [])
{
/** @var self $model */
/** @var static $model */
$model = new static($data);
if (!empty($rules)) {
$validators = $model->getValidators();

View File

@@ -45,7 +45,7 @@ trait ActiveRelationTrait
*/
public $link;
/**
* @var array|object the query associated with the junction table. Please call [[via()]]
* @var array|object|null the query associated with the junction table. Please call [[via()]]
* to set this property instead of directly setting it.
* This property is only used in relational context.
* @see via()

View File

@@ -62,7 +62,7 @@ class ColumnSchema extends BaseObject
*/
public $scale;
/**
* @var bool whether this column is a primary key
* @var bool|null whether this column is a primary key
*/
public $isPrimaryKey;
/**

View File

@@ -319,6 +319,7 @@ class QueryBuilder extends \yii\base\BaseObject
}
if ($this->expressionBuilders[$className] === __CLASS__) {
/** @phpstan-var $this&ExpressionBuilderInterface */
return $this;
}

View File

@@ -176,12 +176,15 @@ abstract class SqlTokenizer extends Component
/**
* Returns whether the longest common prefix equals to the SQL code of the same length at the current offset.
* @param string[] $with strings to be tested.
* @param array $with strings to be tested.
* The method **will** modify this parameter to speed up lookups.
* @param bool $caseSensitive whether to perform a case sensitive comparison.
* @param int|null $length length of the matched string.
* @param string|null $content matched string.
* @return bool whether a match is found.
*
* @phpstan-param array<int, string>|array<int, array<string, mixed>> $with
* @psalm-param array<int, string>|array<int, array<string, mixed>> $with
*/
protected function startsWithAnyLongest(array &$with, $caseSensitive, &$length = null, &$content = null)
{
@@ -194,6 +197,7 @@ abstract class SqlTokenizer extends Component
return mb_strlen($string2, 'UTF-8') - mb_strlen($string1, 'UTF-8');
});
$map = [];
/** @var string $string */
foreach ($with as $string) {
$map[mb_strlen($string, 'UTF-8')][$caseSensitive ? $string : mb_strtoupper($string, 'UTF-8')] = true;
}

View File

@@ -132,7 +132,7 @@ class ArrayExpressionBuilder implements ExpressionBuilderInterface
*
* @param ArrayExpression $expression
* @param mixed $value
* @return JsonExpression
* @return mixed
*/
protected function typecastValue(ArrayExpression $expression, $value)
{