Skip to content

Commit cfe1c95

Browse files
authored
Add PHP 8.3 typed constants and #[Override] attributes (#335)
1 parent 3675f35 commit cfe1c95

133 files changed

Lines changed: 373 additions & 133 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Ouzo/Core/Config/ConfigValueSelector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
class ConfigValueSelector
1313
{
14-
private const CONFIG_START = '${';
15-
private const CONFIG_END = '}';
16-
private const VALUE_SEPARATOR = ':';
14+
private const string CONFIG_START = '${';
15+
private const string CONFIG_END = '}';
16+
private const string VALUE_SEPARATOR = ':';
1717

1818
public static function selectConfigValue(string $selector): mixed
1919
{

src/Ouzo/Core/Config/Inject/ValueAttributeInjector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
class ValueAttributeInjector implements AttributeInjector
1919
{
20+
#[Override]
2021
public function injectForProperties(object $instance, array $reflectionProperties, InstanceFactory $instanceFactory): void
2122
{
2223
foreach ($reflectionProperties as $reflectionProperty) {
@@ -30,6 +31,7 @@ public function injectForProperties(object $instance, array $reflectionPropertie
3031
}
3132
}
3233

34+
#[Override]
3335
public function injectForConstructorParameter(ReflectionMethod $constructor, InstanceFactory $instanceFactory): array
3436
{
3537
$constructorParameters = [];

src/Ouzo/Core/Db/Dialect/MySqlDialect.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class MySqlDialect extends Dialect
1515
{
16+
#[Override]
1617
public function table(): string
1718
{
1819
$alias = $this->query->aliasTable;
@@ -24,57 +25,68 @@ public function table(): string
2425
return $table;
2526
}
2627

28+
#[Override]
2729
public function getConnectionErrorCodes(): array
2830
{
2931
return [2003, 2006];
3032
}
3133

34+
#[Override]
3235
public function getErrorCode(array $errorInfo): mixed
3336
{
3437
return Arrays::getValue($errorInfo, 1);
3538
}
3639

40+
#[Override]
3741
public function using(): string
3842
{
3943
return $this->usingClause($this->query->usingClauses, ' INNER JOIN ', $this->query->table, $this->query->aliasTable);
4044
}
4145

46+
#[Override]
4247
public function batchInsert(string $table, string $primaryKey, array $columns, int $batchSize, ?OnConflict $onConflict): string
4348
{
4449
throw new InvalidArgumentException("Batch insert not supported in mysql");
4550
}
4651

52+
#[Override]
4753
protected function insertEmptyRow(): string
4854
{
4955
return "INSERT INTO {$this->query->table} VALUES ()";
5056
}
5157

58+
#[Override]
5259
public function regexpMatcher(): string
5360
{
5461
return 'REGEXP';
5562
}
5663

64+
#[Override]
5765
protected function quote(string $word): string
5866
{
5967
return "`{$word}`";
6068
}
6169

70+
#[Override]
6271
public function onConflictUpdate(): string
6372
{
6473
$attributes = DialectUtil::buildAttributesPartForUpdate($this->query->updateAttributes);
6574
return " ON DUPLICATE KEY UPDATE {$attributes}";
6675
}
6776

77+
#[Override]
6878
public function onConflictDoNothing(): string
6979
{
7080
throw new InvalidArgumentException("On conflict do nothing is not supported in mysql");
7181
}
7282

83+
#[Override]
7384
protected function getDistinctOnQuery(): string
7485
{
7586
throw new InvalidArgumentException("DISTINCT ON is not supported in mysql");
7687
}
7788

89+
#[Override]
7890
protected function wrapQueryWithDistinctCount(string $sql): string
7991
{
8092
throw new InvalidArgumentException("DISTINCT for COUNT is not supported in mysql");

src/Ouzo/Core/Db/Dialect/PostgresDialect.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313

1414
class PostgresDialect extends Dialect
1515
{
16+
#[Override]
1617
public function getConnectionErrorCodes(): array
1718
{
1819
return ['57000', '57014', '57P01', '57P02', '57P03'];
1920
}
2021

22+
#[Override]
2123
public function getErrorCode(array $errorInfo): mixed
2224
{
2325
return Arrays::getValue($errorInfo, 0);
2426
}
2527

28+
#[Override]
2629
public function batchInsert(string $table, string $primaryKey, $columns, $batchSize, ?OnConflict $onConflict): string
2730
{
2831
$valueClause = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')';
@@ -49,21 +52,25 @@ public function batchInsert(string $table, string $primaryKey, $columns, $batchS
4952
return $sql;
5053
}
5154

55+
#[Override]
5256
protected function insertEmptyRow(): string
5357
{
5458
return "INSERT INTO {$this->query->table} DEFAULT VALUES";
5559
}
5660

61+
#[Override]
5762
public function regexpMatcher(): string
5863
{
5964
return '~';
6065
}
6166

67+
#[Override]
6268
protected function quote(string $word): string
6369
{
6470
return "\"{$word}\"";
6571
}
6672

73+
#[Override]
6774
public function onConflictUpdate(): string
6875
{
6976
$attributes = DialectUtil::buildAttributesPartForUpdate($this->query->updateAttributes);
@@ -72,16 +79,19 @@ public function onConflictUpdate(): string
7279
return " ON CONFLICT ({$joinedColumns}) DO UPDATE SET {$attributes}";
7380
}
7481

82+
#[Override]
7583
public function onConflictDoNothing(): string
7684
{
7785
return " ON CONFLICT DO NOTHING";
7886
}
7987

88+
#[Override]
8089
protected function getDistinctOnQuery(): string
8190
{
8291
return 'DISTINCT ON (' . Joiner::on(', ')->join($this->query->distinctOnColumns) . ') ';
8392
}
8493

94+
#[Override]
8595
protected function wrapQueryWithDistinctCount(string $sql): string
8696
{
8797
return "SELECT count(*) FROM ({$sql}) AS count_data";

src/Ouzo/Core/Db/Dialect/Sqlite3Dialect.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515

1616
class Sqlite3Dialect extends Dialect
1717
{
18+
#[Override]
1819
public function getConnectionErrorCodes(): array
1920
{
2021
return [10, 11, 14];
2122
}
2223

24+
#[Override]
2325
public function getErrorCode(array $errorInfo): mixed
2426
{
2527
return Arrays::getValue($errorInfo, 1);
2628
}
2729

30+
#[Override]
2831
public function update(): string
2932
{
3033
if ($this->query->aliasTable) {
@@ -33,6 +36,7 @@ public function update(): string
3336
return parent::update();
3437
}
3538

39+
#[Override]
3640
public function join(): string
3741
{
3842
$any = Arrays::any($this->query->joinClauses, function (JoinClause $joinClause) {
@@ -44,6 +48,7 @@ public function join(): string
4448
return parent::join();
4549
}
4650

51+
#[Override]
4752
public function lockForUpdate(): string
4853
{
4954
if ($this->query->lockForUpdate) {
@@ -52,6 +57,7 @@ public function lockForUpdate(): string
5257
return '';
5358
}
5459

60+
#[Override]
5561
public function using(): string
5662
{
5763
if ($this->query->usingClauses) {
@@ -60,47 +66,56 @@ public function using(): string
6066
return '';
6167
}
6268

69+
#[Override]
6370
public function batchInsert(string $table, string $primaryKey, $columns, $batchSize, ?OnConflict $onConflict): string
6471
{
6572
throw new InvalidArgumentException("Batch insert not supported in sqlite3");
6673
}
6774

75+
#[Override]
6876
protected function insertEmptyRow(): string
6977
{
7078
return "INSERT INTO {$this->query->table} DEFAULT VALUES";
7179
}
7280

81+
#[Override]
7382
public function regexpMatcher(): string
7483
{
7584
//needs package sqlite3-pcre to work correctly
7685
return 'REGEXP';
7786
}
7887

88+
#[Override]
7989
protected function quote(string $word): string
8090
{
8191
return "\"{$word}\"";
8292
}
8393

94+
#[Override]
8495
public function getIteratorOptions(): array
8596
{
8697
return [];
8798
}
8899

100+
#[Override]
89101
public function onConflictUpdate(): string
90102
{
91103
throw new BadMethodCallException('UPSERT is not supported in sqlite3');
92104
}
93105

106+
#[Override]
94107
public function onConflictDoNothing(): string
95108
{
96109
throw new BadMethodCallException('On conflict do nothing is not supported in sqlite3');
97110
}
98111

112+
#[Override]
99113
protected function getDistinctOnQuery(): string
100114
{
101115
throw new InvalidArgumentException("DISTINCT ON is not supported in sqlite3");
102116
}
103117

118+
#[Override]
104119
protected function wrapQueryWithDistinctCount(string $sql): string
105120
{
106121
throw new InvalidArgumentException("DISTINCT for COUNT is not supported in sqlite3");

src/Ouzo/Core/Db/EmulatedPDOPreparedStatementExecutor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class EmulatedPDOPreparedStatementExecutor extends PDOExecutor
1313
{
14+
#[Override]
1415
public function createPDOStatement(PDO $dbHandle, string $sql, array $boundValues, string $queryString, array $options = []): PDOStatement
1516
{
1617
$sql = PreparedStatementEmulator::substitute($sql, $boundValues);

src/Ouzo/Core/Db/ModelQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class ModelQueryBuilder
2121
{
22-
const MODEL_QUERY_MARKER_COMMENT = 'orm:model';
22+
const string MODEL_QUERY_MARKER_COMMENT = 'orm:model';
2323

2424
private Db $db;
2525
/** @var ModelJoin[] */

src/Ouzo/Core/Db/OnConflict.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
class OnConflict
99
{
10-
const DO_NOTHING = 'DO_NOTHING';
11-
const UPDATE = 'UPDATE';
10+
const string DO_NOTHING = 'DO_NOTHING';
11+
const string UPDATE = 'UPDATE';
1212
private ?string $onConflictAction;
1313
private array $onConflictColumns;
1414
private array $onConflictUpdateValues;

src/Ouzo/Core/Db/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
class Options
99
{
10-
const EMULATE_PREPARES = 'EMULATE_PREPARES';
10+
const string EMULATE_PREPARES = 'EMULATE_PREPARES';
1111
}

src/Ouzo/Core/Db/PDOPreparedStatementExecutor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class PDOPreparedStatementExecutor extends PDOExecutor
1414
{
15+
#[Override]
1516
public function createPDOStatement(PDO $dbHandle, string $sql, array $boundValues, string $queryString, array $options = []): PDOStatement
1617
{
1718
try {

0 commit comments

Comments
 (0)