Skip to content

Commit

Permalink
Add rector actions. (#196)
Browse files Browse the repository at this point in the history
* Add rector actions.
* Fix type hint method.
* Fix type hint method.
* More fix changes rector.
* Fix create property dinamic php `8.2`.
* Remove scrutinizer.yml.
* Update README.md.
* Fix version support PGSQL README.md.
* Use union types.
  • Loading branch information
terabytesoftw authored Oct 13, 2022
1 parent e254933 commit 5b36c6d
Show file tree
Hide file tree
Showing 26 changed files with 171 additions and 231 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
name: PHP ${{ matrix.php }}

env:
extensions: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.10.0-beta2, oci8
extensions: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.10.1
key: cache-v1

runs-on: ubuntu-latest
Expand All @@ -39,6 +39,7 @@ jobs:
php:
- 8.0
- 8.1
- 8.2

services:
mysql:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:

php:
- 8.0
- 8.1

services:
mysql:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
35 changes: 0 additions & 35 deletions .scrutinizer.yml

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ It is used in [Yii Framework] but is supposed to be usable separately.
|[[db-mssql]](https://github.com/yiisoft/db-mssql)|**7.4 - 8.0**| **2017 - 2019**|[![Build status](https://github.com/yiisoft/db-mssql/workflows/build/badge.svg)](https://github.com/yiisoft/db-mssql/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-mssql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mssql/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-mssql/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-mssql/?branch=master)|
|[[db-mysql]](https://github.com/yiisoft/db-mysql)|**7.4 - 8.0**| **5.7 - 8.0**|[![Build status](https://github.com/yiisoft/db-mysql/workflows/build/badge.svg)](https://github.com/yiisoft/db-mysql/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-mysql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mysql/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-mysql/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-mysql/?branch=master)|
|[[db-oracle]](https://github.com/yiisoft/db-oracle)|**7.4 - 8.0**| **11c - 12c**|[![Build status](https://github.com/yiisoft/db-oracle/workflows/build/badge.svg)](https://github.com/yiisoft/db-oracle/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-oracle%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-oracle/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-oracle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-oracle/?branch=master)|
|[[db-pgsql]](https://github.com/yiisoft/db-pgsql)|**7.4 - 8.0**| **9.0 - 13.0**|[![Build status](https://github.com/yiisoft/db-pgsql/workflows/build/badge.svg)](https://github.com/yiisoft/db-pgsql/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-pgsql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-pgsql/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-pgsql/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-pgsql/?branch=master)|
|[[db-pgsql]](https://github.com/yiisoft/db-pgsql)|**7.4 - 8.0**| **9.0 - 15.0**|[![Build status](https://github.com/yiisoft/db-pgsql/workflows/build/badge.svg)](https://github.com/yiisoft/db-pgsql/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-pgsql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-pgsql/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-pgsql/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-pgsql/?branch=master)|
|[[db-sqlite]](https://github.com/yiisoft/db-sqlite)|**7.4 - 8.0**| **3:latest**|[![Build status](https://github.com/yiisoft/db-sqlite/workflows/build/badge.svg)](https://github.com/yiisoft/db-sqlite/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-sqlite%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-sqlite/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-sqlite/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-sqlite/?branch=master)|
|[[db-redis]](https://github.com/yiisoft/db-redis)|**7.4 - 8.0**| **4.0 - 6.0**|[![Build status](https://github.com/yiisoft/db-redis/workflows/build/badge.svg)](https://github.com/yiisoft/db-redis/actions?query=workflow%3Abuild) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-redis%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-redis/master) [![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/db-redis/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/db-redis/?branch=master)|


## Installation

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
61 changes: 27 additions & 34 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use function array_merge;
use function array_values;
use function count;
use function get_class;
use function implode;
use function in_array;
use function is_array;
Expand Down Expand Up @@ -101,21 +100,17 @@ class ActiveQuery extends Query implements ActiveQueryInterface
use ActiveQueryTrait;
use ActiveRelationTrait;

protected string $arClass;
protected ConnectionInterface $db;
private ?string $sql = null;
private $on;
private string|null $sql = null;
private array|string|null $on = null;
private array $joinWith = [];
private ?ActiveRecordInterface $arInstance = null;
private ?ActiveRecordFactory $arFactory;
private ActiveRecordInterface|null $arInstance = null;
private QueryHelper|null $queryHelper = null;

public function __construct(string $modelClass, ConnectionInterface $db, ActiveRecordFactory $arFactory = null)
{
$this->arClass = $modelClass;
$this->arFactory = $arFactory;
$this->db = $db;

public function __construct(
protected string $arClass,
protected ConnectionInterface $db,
private ActiveRecordFactory|null $arFactory = null
) {
parent::__construct($db);
}

Expand Down Expand Up @@ -410,8 +405,6 @@ public function createCommand(): CommandInterface
* @param ExpressionInterface|string $selectExpression
*
* @throws Exception|InvalidConfigException|Throwable
*
* @return false|float|int|string|null
*/
protected function queryScalar(string|ExpressionInterface $selectExpression): false|float|int|string|null
{
Expand Down Expand Up @@ -484,7 +477,7 @@ protected function queryScalar(string|ExpressionInterface $selectExpression): fa
*
* @return $this the query object itself.
*/
public function joinWith($with, $eagerLoading = true, $joinType = 'LEFT JOIN'): self
public function joinWith(array|string $with, array|bool $eagerLoading = true, array|string $joinType = 'LEFT JOIN'): self
{
$relations = [];

Expand Down Expand Up @@ -594,7 +587,7 @@ private function buildJoinWith(): void
*
* {@see joinWith()}
*/
public function innerJoinWith($with, $eagerLoading = true): self
public function innerJoinWith(array|string $with, array|bool $eagerLoading = true): self
{
return $this->joinWith($with, $eagerLoading, 'INNER JOIN');
}
Expand All @@ -606,7 +599,7 @@ public function innerJoinWith($with, $eagerLoading = true): self
* @param array $with the relations to be joined.
* @param array|string $joinType the join type.
*/
private function joinWithRelations(ActiveRecordInterface $arClass, array $with, $joinType): void
private function joinWithRelations(ActiveRecordInterface $arClass, array $with, array|string $joinType): void
{
$relations = [];

Expand Down Expand Up @@ -665,7 +658,7 @@ private function joinWithRelations(ActiveRecordInterface $arClass, array $with,
*
* @return string the real join type.
*/
private function getJoinType($joinType, string $name): string
private function getJoinType(array|string $joinType, string $name): string
{
if (is_array($joinType) && isset($joinType[$name])) {
return $joinType[$name];
Expand Down Expand Up @@ -737,11 +730,11 @@ private function joinWithRelation(self $parent, self $child, string $joinType):
[$childTable, $childAlias] = $child->getTableNameAndAlias();

if (!empty($child->link)) {
if (strpos($parentAlias, '{{') === false) {
if (!str_contains($parentAlias, '{{')) {
$parentAlias = '{{' . $parentAlias . '}}';
}

if (strpos($childAlias, '{{') === false) {
if (!str_contains($childAlias, '{{')) {
$childAlias = '{{' . $childAlias . '}}';
}

Expand Down Expand Up @@ -821,7 +814,7 @@ private function joinWithRelation(self $parent, self $child, string $joinType):
*
* @return $this the query object itself
*/
public function onCondition($condition, array $params = []): self
public function onCondition(array|string $condition, array $params = []): self
{
$this->on = $condition;

Expand All @@ -844,7 +837,7 @@ public function onCondition($condition, array $params = []): self
* {@see onCondition()}
* {@see orOnCondition()}
*/
public function andOnCondition($condition, array $params = []): self
public function andOnCondition(array|string $condition, array $params = []): self
{
if ($this->on === null) {
$this->on = $condition;
Expand All @@ -871,7 +864,7 @@ public function andOnCondition($condition, array $params = []): self
* {@see onCondition()}
* {@see andOnCondition()}
*/
public function orOnCondition($condition, array $params = []): self
public function orOnCondition(array|string $condition, array $params = []): self
{
if ($this->on === null) {
$this->on = $condition;
Expand Down Expand Up @@ -909,7 +902,7 @@ public function orOnCondition($condition, array $params = []): self
*/
public function viaTable(string $tableName, array $link, callable $callable = null): self
{
$arClass = $this->primaryModel ? get_class($this->primaryModel) : $this->arClass;
$arClass = $this->primaryModel ? $this->primaryModel::class : $this->arClass;

$arClassInstance = new self($arClass, $this->db);

Expand Down Expand Up @@ -978,7 +971,7 @@ protected function getPrimaryTableName(): string
}

/**
* @return array|string the join condition to be used when this query is used in a relational context.
* @return array|string|null the join condition to be used when this query is used in a relational context.
*
* The condition will be used in the ON part when {@see ActiveQuery::joinWith()} is called. Otherwise, the condition
* will be used in the WHERE part of a query.
Expand All @@ -987,7 +980,7 @@ protected function getPrimaryTableName(): string
*
* {@see onCondition()}
*/
public function getOn()
public function getOn(): array|string|null
{
return $this->on;
}
Expand All @@ -1005,12 +998,12 @@ public function getJoinWith(): array
*
* This is set by {@see ActiveRecord::findBySql()}.
*/
public function getSql(): ?string
public function getSql(): string|null
{
return $this->sql;
}

public function getARClass(): ?string
public function getARClass(): string|null
{
return $this->arClass;
}
Expand All @@ -1022,7 +1015,7 @@ public function getARClass(): ?string
*
* @return ActiveRecordInterface|null ActiveRecord instance matching the condition, or `null` if nothing matches.
*/
public function findOne(mixed $condition): ?ActiveRecordInterface
public function findOne(mixed $condition): ActiveRecordInterface|null
{
return $this->findByCondition($condition)->one();
}
Expand Down Expand Up @@ -1050,7 +1043,7 @@ public function findAll(mixed $condition): array
*
* @return ActiveQueryInterface the newly created {@see QueryInterface} instance.
*/
protected function findByCondition($condition): ActiveQueryInterface
protected function findByCondition(mixed $condition): ActiveQueryInterface
{
$arInstance = $this->getARInstance();

Expand All @@ -1075,7 +1068,7 @@ protected function findByCondition($condition): ActiveQueryInterface
*/
$condition = [$pk => is_array($condition) ? array_values($condition) : $condition];
} else {
throw new InvalidConfigException('"' . get_class($arInstance) . '" must have a primary key.');
throw new InvalidConfigException('"' . $arInstance::class . '" must have a primary key.');
}
} elseif (is_array($condition)) {
$aliases = $arInstance->filterValidAliases($this);
Expand Down Expand Up @@ -1109,13 +1102,13 @@ public function findBySql(string $sql, array $params = []): QueryInterface
return $this->sql($sql)->params($params);
}

public function on($value): self
public function on(array|string|null $value): self
{
$this->on = $value;
return $this;
}

public function sql(?string $value): self
public function sql(string|null $value): self
{
$this->sql = $value;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/ActiveQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ActiveQueryInterface extends QueryInterface
*
* @return static the query object itself.
*/
public function asArray(?bool $value = true): self;
public function asArray(bool|null $value = true): self;

/**
* Executes query and returns a single row of result.
Expand Down Expand Up @@ -90,7 +90,7 @@ public function indexBy(string|Closure|null $column): QueryInterface;
*
* @return $this the query object itself
*/
public function with(...$with): self;
public function with(array|string ...$with): self;

/**
* Specifies the relation associated with the junction table for use in relational query.
Expand Down Expand Up @@ -193,7 +193,7 @@ public function findFor(string $name, ActiveRecordInterface $model): mixed;
*
* @return ActiveRecordInterface|null instance matching the condition, or `null` if nothing matches.
*/
public function findOne(mixed $condition): ?ActiveRecordInterface;
public function findOne(mixed $condition): ActiveRecordInterface|null;

/**
* Returns a list of active record that match the specified primary key value(s) or a set of column values.
Expand Down
Loading

0 comments on commit 5b36c6d

Please sign in to comment.