Skip to content

Commit

Permalink
fix: improve phpstan hints
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jul 16, 2024
1 parent ebb4684 commit 223b487
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
},
"require-dev": {
"yiisoft/yii2": "^2.0",
"codeception/codeception": "> 4",
"codeception/codeception": "> 5",
"codeception/module-yii2": "^1.1",
"codeception/module-asserts": "^1.2",
"vimeo/psalm": "^4.21",
"symplify/easy-coding-standard": "^11.1",
"phpstan/phpstan": "^1.8",
"codeception/module-asserts": "^3",
"vimeo/psalm": "^5",
"symplify/easy-coding-standard": "^12",
"phpstan/phpstan": "^1",
"captainhook/plugin-composer": "^5.3",
"ramsey/conventional-commits": "^1.3"

Expand Down
3 changes: 2 additions & 1 deletion src/VirtualFieldQueryBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function attach($owner): void
*/
public function withFields(string ...$fields): ActiveQuery
{
return $this->addField($this->owner, array_values($fields));
$this->addField($this->owner, array_values($fields));
return $this->owner;
}
}
14 changes: 7 additions & 7 deletions src/VirtualFieldQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ private function getModelInstance(string $class): ActiveRecord
}

/**
* @param ActiveQuery $query
* @param list<string> $fields
* @return ActiveQuery
* @throws exceptions\FieldNotFoundException
*/
private function addField(ActiveQuery $query, array $fields): ActiveQuery
private function addField(ActiveQuery $query, array $fields): void
{
/** @var class-string<ActiveRecord> $modelClass */
$modelClass = $query->modelClass;
$model = $this->getModelInstance($modelClass);

$columns = [];
if (empty($query->select)) {
if ($query->select === null || $query->select === []) {
$columns[] = '*';
}
foreach ($fields as $field) {
$columns[$field] = $model->getVirtualExpression($field);
}
$query->addSelect($columns);
return $query;
}

/**
* @return $this
*/
public function withFields(string ...$fields): ActiveQuery
{
return $this->addField($this, array_values($fields));
$this->addField($this, array_values($fields));
return $this;
}
}

0 comments on commit 223b487

Please sign in to comment.