Skip to content

Commit

Permalink
Merge pull request #2 from SAM-IT/fix-improve-static-types
Browse files Browse the repository at this point in the history
fix: improve phpstan hints
  • Loading branch information
SamMousa authored Jul 16, 2024
2 parents ebb4684 + 5617828 commit 51d6b9d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Continous integration
on:
pull_request:
types: [opened, reopened]
push:
branches:
- '**'
Expand All @@ -21,6 +22,8 @@ jobs:
run: vendor/bin/ecs
- name: Static analysis (Psalm)
run: vendor/bin/psalm
- name: Build test help files
run: vendor/bin/codecept build
- name: Static analysis (PHPStan)
run: vendor/bin/phpstan
- name: Run tests
Expand Down
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
5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ parameters:
paths:
- src
- tests
excludePaths:
- tests/_support/_generated
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#Method .*::getModelInstance\(\) should return #'
- message: "#.*#"
paths:
- tests/_support/_generated
reportUnmatchedIgnoredErrors: false
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;
}
}
Empty file.

0 comments on commit 51d6b9d

Please sign in to comment.