Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
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']
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"require-dev": {
"ext-json": "*",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"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,
]);
};
33 changes: 7 additions & 26 deletions src/BaseTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
*/
abstract class BaseTokenizer
{
/**
* @var string SQL code.
*/
private string $sql;

/**
* @var int SQL code string length.
*/
Expand Down Expand Up @@ -78,9 +73,12 @@ abstract class BaseTokenizer
*/
private ?SqlToken $token = null;

public function __construct(string $sql)
{
$this->sql = $sql;
public function __construct(
/**
* @var string SQL code.
*/
private string $sql
) {
}

/**
Expand Down Expand Up @@ -213,9 +211,6 @@ abstract protected function isStringLiteral(int &$length, ?string &$content): bo
*/
abstract protected function isKeyword(string $string, ?string &$content): bool;

/**
* @param string $sql
*/
public function setSql(string $sql): void
{
$this->sql = $sql;
Expand Down Expand Up @@ -244,9 +239,7 @@ protected function startsWithAnyLongest(
}

if (!is_array(reset($with))) {
usort($with, static function (string $string1, string $string2) {
return mb_strlen($string2, 'UTF-8') - mb_strlen($string1, 'UTF-8');
});
usort($with, static fn (string $string1, string $string2) => mb_strlen($string2, 'UTF-8') - mb_strlen($string1, 'UTF-8'));

$map = [];

Expand Down Expand Up @@ -333,10 +326,6 @@ protected function indexAfter(string $string, ?int $offset = null): int

/**
* Determines whether there is a delimited string at the current offset and adds it to the token children.
*
* @param int $length
*
* @return bool
*/
private function tokenizeDelimitedString(int &$length): bool
{
Expand All @@ -360,10 +349,6 @@ private function tokenizeDelimitedString(int &$length): bool

/**
* Determines whether there is an operator at the current offset and adds it to the token children.
*
* @param int $length
*
* @return bool
*/
private function tokenizeOperator(int &$length): bool
{
Expand Down Expand Up @@ -457,8 +442,6 @@ private function addTokenFromBuffer(): void
/**
* Adds the specified length to the current offset.
*
* @param int $length
*
* @throws InvalidArgumentException
*/
private function advance(int $length): void
Expand All @@ -473,8 +456,6 @@ private function advance(int $length): void

/**
* Returns whether the SQL code is completely traversed.
*
* @return bool
*/
private function isEof(): bool
{
Expand Down
3 changes: 0 additions & 3 deletions src/Builder/InConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ protected function buildSubqueryInCondition(
/**
* Builds SQL for IN condition.
*
* @param string|null $operator
* @param array|Traversable $columns
* @param iterable|Iterator $values
* @param array $params
*
* @return string SQL.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Yiisoft\Db\Schema\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;

final class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
final class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder implements \Stringable
{
/**
* Builds the unsigned string for column. Defaults to unsupported.
Expand Down
9 changes: 0 additions & 9 deletions src/CommandPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,9 @@ protected function queryInternal(int $queryMode): mixed
* Splits the specified SQL codes into individual SQL statements and returns them or `false` if there's a single
* statement.
*
* @param string $sql
* @param array $params
*
* @throws InvalidArgumentException
*
* @return array|bool (array|string)[][]|bool
*
* @psalm-param array<string, string> $params
* @psalm-return false|list<array{0: string, 1: array}>
*/
Expand Down Expand Up @@ -217,11 +213,6 @@ private function splitStatements(string $sql, array $params): bool|array
/**
* Returns named bindings used in the specified statement token.
*
* @param SqlToken $statement
* @param array $params
*
* @return array
*
* @psalm-param array<string, string> $params
*/
private function extractUsedParams(SqlToken $statement, array $params): array
Expand Down
4 changes: 1 addition & 3 deletions src/ConnectionPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;

use function strncmp;

/**
* Database connection class prefilled for SQLite Server.
*/
Expand All @@ -29,7 +27,7 @@ public function __clone()
{
$this->transaction = null;

if (strncmp($this->driver->getDsn(), 'sqlite::memory:', 15) !== 0) {
if (!str_starts_with($this->driver->getDsn(), 'sqlite::memory:')) {
/** reset PDO connection, unless its sqlite in-memory, which can only have one connection */
$this->pdo = null;
}
Expand Down
2 changes: 0 additions & 2 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public function buildUnion(array $unions, array &$params = []): string
* Contains array of default expression builders. Extend this method and override it, if you want to change default
* expression builders for this query builder.
*
* @return array
*
* See {@see ExpressionBuilder} docs for details.
*
* @psalm-return array<string, class-string<ExpressionBuilderInterface>>
Expand Down
12 changes: 3 additions & 9 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface
* @param string $tableName table name.
*
* @throws Exception|InvalidConfigException|Throwable
*
* @return array
*/
private function loadTableColumnsInfo(string $tableName): array
{
Expand All @@ -520,8 +518,6 @@ private function loadTableColumnsInfo(string $tableName): array
*
* @throws Exception|InvalidConfigException|Throwable
*
* @return array|Constraint|null
*
* @psalm-return (Constraint|IndexConstraint)[]|Constraint|null
*/
private function loadTableConstraints(string $tableName, string $returnType): Constraint|array|null
Expand Down Expand Up @@ -648,7 +644,7 @@ private function getPragmaTableInfo(string $tableName): array
*/
protected function getCacheKey(string $name): array
{
return array_merge([__CLASS__], $this->db->getCacheKey(), [$this->getRawTableName($name)]);
return array_merge([self::class], $this->db->getCacheKey(), [$this->getRawTableName($name)]);
}

/**
Expand All @@ -660,7 +656,7 @@ protected function getCacheKey(string $name): array
*/
protected function getCacheTag(): string
{
return md5(serialize(array_merge([__CLASS__], $this->db->getCacheKey())));
return md5(serialize(array_merge([self::class], $this->db->getCacheKey())));
}

/**
Expand All @@ -674,9 +670,7 @@ protected function getCacheTag(): string
protected function normalizeRowKeyCase(array $row, bool $multiple): array
{
if ($multiple) {
return array_map(static function (array $row) {
return array_change_key_case($row, CASE_LOWER);
}, $row);
return array_map(static fn (array $row) => array_change_key_case($row, CASE_LOWER), $row);
}

return array_change_key_case($row, CASE_LOWER);
Expand Down
26 changes: 1 addition & 25 deletions src/SqlToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* read-only.
* @property string $sql SQL code. This property is read-only.
*/
final class SqlToken implements ArrayAccess
final class SqlToken implements ArrayAccess, \Stringable
{
public const TYPE_CODE = 0;
public const TYPE_STATEMENT = 1;
Expand Down Expand Up @@ -234,14 +234,6 @@ public function matches(

/**
* Tests the given token to match the specified pattern token.
*
* @param SqlToken $patternToken
* @param SqlToken $token
* @param int $offset
* @param int|null $firstMatchIndex
* @param int|null $lastMatchIndex
*
* @return bool
*/
private function tokensMatch(
self $patternToken,
Expand Down Expand Up @@ -308,10 +300,6 @@ private function tokensMatch(

/**
* Returns an absolute offset in the children array.
*
* @param int $offset
*
* @return int
*/
private function calculateOffset(int $offset): int
{
Expand Down Expand Up @@ -348,8 +336,6 @@ private function updateCollectionOffsets(): void
* - {@see TYPE_STRING_LITERAL}
*
* @param int $value token type. It has to be one of the following constants:
*
* @return self
*/
public function type(int $value): self
{
Expand All @@ -360,10 +346,6 @@ public function type(int $value): self

/**
* Set token content.
*
* @param string|null $value
*
* @return self
*/
public function content(?string $value): self
{
Expand All @@ -376,8 +358,6 @@ public function content(?string $value): self
* Set original SQL token start position.
*
* @param int $value original SQL token start position.
*
* @return self
*/
public function startOffset(int $value): self
{
Expand All @@ -390,8 +370,6 @@ public function startOffset(int $value): self
* Set original SQL token end position.
*
* @param int $value original SQL token end position.
*
* @return self
*/
public function endOffset(int $value): self
{
Expand All @@ -404,8 +382,6 @@ public function endOffset(int $value): self
* Set parent token.
*
* @param SqlToken $value parent token.
*
* @return self
*/
public function parent(self $value): self
{
Expand Down
7 changes: 1 addition & 6 deletions tests/ColumnSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ public function typesProvider(): array

/**
* @dataProvider typesProvider
*
* @param string $expected
* @param string $type
* @param int|null $length
* @param mixed $calls
*/
public function testCustomTypes(string $expected, string $type, ?int $length, $calls): void
public function testCustomTypes(string $expected, string $type, ?int $length, mixed $calls): void
{
$this->checkBuildString($expected, $type, $length, $calls);
}
Expand Down
9 changes: 1 addition & 8 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ public function testBatchInsertSQL(
*
* @dataProvider bindParamsNonWhereProviderTrait
*
* @param string $sql
*
* @throws Exception
* @throws InvalidArgumentException
* @throws InvalidConfigException
Expand Down Expand Up @@ -229,13 +227,11 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql
*
* @dataProvider invalidSelectColumnsProviderTrait
*
* @param mixed $invalidSelectColumns
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
*/
public function testInsertSelectFailed($invalidSelectColumns): void
public function testInsertSelectFailed(mixed $invalidSelectColumns): void
{
$db = $this->getConnection();
$query = new Query($db);
Expand All @@ -249,9 +245,6 @@ public function testInsertSelectFailed($invalidSelectColumns): void
/**
* @dataProvider upsertProviderTrait
*
* @param array $firstData
* @param array $secondData
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
Expand Down
Loading