Skip to content

Commit 1b1d3de

Browse files
Add rector actions. (#154)
* Add rector action. * Update dependencies yiisoft/cache `2.0`. * Update dependencies yiisoft/aliases `2.0`. * Add tests php `8.2`. * Add tests pgsql 15. * Use union types.
1 parent 8dcf41e commit 1b1d3de

20 files changed

Lines changed: 98 additions & 194 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
php:
3939
- 8.0
4040
- 8.1
41+
- 8.2
4142

4243
pgsql:
4344
- 9
@@ -46,6 +47,7 @@ jobs:
4647
- 12
4748
- 13
4849
- 14
50+
- 15rc2
4951

5052
services:
5153
postgres:

.github/workflows/rector.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'psalm.xml'
11+
12+
push:
13+
paths-ignore:
14+
- 'docs/**'
15+
- 'README.md'
16+
- 'CHANGELOG.md'
17+
- '.gitignore'
18+
- '.gitattributes'
19+
- 'infection.json.dist'
20+
- 'psalm.xml'
21+
22+
name: rector
23+
24+
jobs:
25+
rector:
26+
uses: yiisoft/actions/.github/workflows/rector.yml@master
27+
with:
28+
os: >-
29+
['ubuntu-latest']
30+
php: >-
31+
['8.0']

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
"ext-json": "*",
2424
"ext-pdo": "*",
2525
"yiisoft/arrays": "^2.0",
26-
"yiisoft/db": "dev-master",
26+
"yiisoft/db": "^3.0@dev",
2727
"yiisoft/json": "^1.0",
2828
"yiisoft/strings": "^2.0"
2929
},
3030
"require-dev": {
3131
"phpunit/phpunit": "^9.5",
32+
"rector/rector": "^0.14",
3233
"roave/infection-static-analysis-plugin": "^1.16",
3334
"spatie/phpunit-watcher": "^1.23",
3435
"vimeo/psalm": "^4.18",
35-
"yiisoft/aliases": "^1.1|^2.0",
36-
"yiisoft/cache": "^1.0"
36+
"yiisoft/aliases": "^2.0",
37+
"yiisoft/cache": "^2.0"
3738
},
3839
"autoload": {
3940
"psr-4": {

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
]);
14+
15+
// register a single rule
16+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17+
18+
// define sets of rules
19+
$rectorConfig->sets([
20+
LevelSetList::UP_TO_PHP_80,
21+
]);
22+
};

src/ArrayParser.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ final class ArrayParser
2121
* Convert array from PostgresSQL to PHP
2222
*
2323
* @param string|null $value string to be converted
24-
*
25-
* @return array|null
2624
*/
27-
public function parse(?string $value): ?array
25+
public function parse(string|null $value): array|null
2826
{
2927
if ($value === null) {
3028
return null;
@@ -40,10 +38,7 @@ public function parse(?string $value): ?array
4038
/**
4139
* Pares PgSQL array encoded in string.
4240
*
43-
* @param string $value
4441
* @param int $i parse starting position.
45-
*
46-
* @return array
4742
*/
4843
private function parseArray(string $value, int &$i = 0): array
4944
{
@@ -79,12 +74,9 @@ private function parseArray(string $value, int &$i = 0): array
7974
/**
8075
* Parses PgSQL encoded string.
8176
*
82-
* @param string $value
8377
* @param int $i parse starting position.
84-
*
85-
* @return string|null
8678
*/
87-
private function parseString(string $value, int &$i): ?string
79+
private function parseString(string $value, int &$i): string|null
8880
{
8981
$isQuoted = $value[$i] === '"';
9082
$stringEndChars = $isQuoted ? ['"'] : [$this->delimiter, '}'];

src/Builder/ArrayExpressionBuilder.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Yiisoft\Db\Query\QueryInterface;
1919
use Yiisoft\Db\Schema\Schema as AbstractSchema;
2020

21-
use function get_class;
2221
use function implode;
2322
use function in_array;
2423
use function is_array;
@@ -69,12 +68,9 @@ public function build(ExpressionInterface $expression, array &$params = []): str
6968
/**
7069
* Builds placeholders array out of $expression values.
7170
*
72-
* @param ExpressionInterface $expression
7371
* @param array $params the binding parameters.
7472
*
7573
* @throws Exception|InvalidArgumentException|InvalidConfigException|NotSupportedException
76-
*
77-
* @return array
7874
*/
7975
protected function buildPlaceholders(ExpressionInterface $expression, array &$params): array
8076
{
@@ -120,21 +116,14 @@ protected function buildPlaceholders(ExpressionInterface $expression, array &$pa
120116
}
121117

122118
/**
123-
* @param ArrayExpression $expression
124119
* @param array|mixed|QueryInterface $value
125-
*
126-
* @return ArrayExpression
127120
*/
128121
private function unnestArrayExpression(ArrayExpression $expression, mixed $value): ArrayExpression
129122
{
130-
$expressionClass = get_class($expression);
131-
132-
return new $expressionClass($value, $expression->getType(), $expression->getDimension() - 1);
123+
return new ArrayExpression($value, $expression->getType(), $expression->getDimension() - 1);
133124
}
134125

135126
/**
136-
* @param ArrayExpression $expression
137-
*
138127
* @return string the typecast expression based on {@see type}.
139128
*/
140129
protected function getTypeHint(ArrayExpression $expression): string
@@ -156,7 +145,6 @@ protected function getTypeHint(ArrayExpression $expression): string
156145
* Build an array expression from a subquery SQL.
157146
*
158147
* @param string $sql the subquery SQL.
159-
* @param ArrayExpression $expression
160148
*
161149
* @return string the subquery array expression.
162150
*/
@@ -168,9 +156,6 @@ protected function buildSubqueryArray(string $sql, ArrayExpression $expression):
168156
/**
169157
* Casts $value to use in $expression.
170158
*
171-
* @param ArrayExpression $expression
172-
* @param array|bool|ExpressionInterface|int|string|null $value
173-
*
174159
* @return array|bool|ExpressionInterface|int|JsonExpression|string|null
175160
*/
176161
protected function typecastValue(

src/Builder/JsonExpressionBuilder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public function build(ExpressionInterface $expression, array &$params = []): str
5959
}
6060

6161
/**
62-
* @param JsonExpression $expression
63-
*
6462
* @return string the typecast expression based on {@see type}.
6563
*/
6664
protected function getTypecast(JsonExpression $expression): string

src/ColumnSchema.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class ColumnSchema extends AbstractColumnSchema
3131
/**
3232
* @var string|null name of associated sequence if column is auto-incremental.
3333
*/
34-
private ?string $sequenceName = null;
34+
private string|null $sequenceName = null;
3535

3636
/**
3737
* Converts the input value according to {@see type} and {@see dbType} for use in a db query.
@@ -83,7 +83,7 @@ public function phpTypecast(mixed $value): mixed
8383
}
8484

8585
if (is_array($value)) {
86-
array_walk_recursive($value, function (?string &$val) {
86+
array_walk_recursive($value, function (string|null &$val) {
8787
/** @var mixed */
8888
$val = $this->phpTypecastValue($val);
8989
});
@@ -100,11 +100,7 @@ public function phpTypecast(mixed $value): mixed
100100
/**
101101
* Casts $value after retrieving from the DBMS to PHP representation.
102102
*
103-
* @param mixed $value
104-
*
105103
* @throws JsonException
106-
*
107-
* @return mixed
108104
*/
109105
protected function phpTypecastValue(mixed $value): mixed
110106
{
@@ -131,8 +127,6 @@ protected function phpTypecastValue(mixed $value): mixed
131127

132128
/**
133129
* Creates instance of ArrayParser.
134-
*
135-
* @return ArrayParser
136130
*/
137131
protected function getArrayParser(): ArrayParser
138132
{
@@ -150,7 +144,7 @@ public function getDimension(): int
150144
/**
151145
* @return string|null name of associated sequence if column is auto-incremental.
152146
*/
153-
public function getSequenceName(): ?string
147+
public function getSequenceName(): string|null
154148
{
155149
return $this->sequenceName;
156150
}
@@ -166,7 +160,7 @@ public function dimension(int $dimension): void
166160
/**
167161
* Set name of associated sequence if column is auto-incremental.
168162
*/
169-
public function sequenceName(?string $sequenceName): void
163+
public function sequenceName(string|null $sequenceName): void
170164
{
171165
$this->sequenceName = $sequenceName;
172166
}

src/CommandPDO.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function schema(): SchemaInterface
3939
return $this->db->getSchema();
4040
}
4141

42-
protected function internalExecute(?string $rawSql): void
42+
protected function internalExecute(string|null $rawSql): void
4343
{
4444
$attempt = 0;
4545

@@ -51,7 +51,7 @@ protected function internalExecute(?string $rawSql): void
5151
&& $this->db->getTransaction() === null
5252
) {
5353
$this->db->transaction(
54-
fn (?string $rawSql) => $this->internalExecute($rawSql),
54+
fn (string|null $rawSql) => $this->internalExecute($rawSql),
5555
$this->isolationLevel
5656
);
5757
} else {

src/ConnectionPDO.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
final class ConnectionPDO extends AbstractConnectionPDO
2424
{
25-
public function createCommand(?string $sql = null, array $params = []): CommandPDOInterface
25+
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface
2626
{
2727
$command = new CommandPDO($this, $this->queryCache);
2828

@@ -46,7 +46,7 @@ public function createTransaction(): TransactionInterface
4646
return new TransactionPDO($this);
4747
}
4848

49-
public function getLastInsertID(?string $sequenceName = null): string
49+
public function getLastInsertID(string $sequenceName = null): string
5050
{
5151
if ($sequenceName === null) {
5252
throw new InvalidArgumentException('PgSQL not support lastInsertId without sequence name');

0 commit comments

Comments
 (0)