Skip to content

Commit 2b59e49

Browse files
committed
Merge remote-tracking branch 'upstream/0.6.x' into qa/mago-sql-typed-constants
2 parents 9eba43b + 8b08e6e commit 2b59e49

9 files changed

Lines changed: 83 additions & 46 deletions

File tree

‎analyzer-baseline.toml‎

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,6 @@ code = "imprecise-type"
156156
message = "Type `array` in return type of `getConnectionParameters` is imprecise, equivalent to `array<array-key, mixed>`."
157157
count = 1
158158

159-
[[issues]]
160-
file = "src/Adapter/Driver/AbstractConnection.php"
161-
code = "incompatible-return-type"
162-
message = 'Return type `null|resource` of `PhpDb\Adapter\Driver\AbstractConnection::getresource()` is incompatible with parent return type `resource` of `PhpDb\Adapter\Driver\ConnectionInterface::getresource()`'
163-
count = 1
164-
165-
[[issues]]
166-
file = "src/Adapter/Driver/AbstractConnection.php"
167-
code = "incompatible-return-type"
168-
message = 'Return type `null|resource` of `PhpDb\Adapter\Driver\Pdo\AbstractPdoConnection::getresource()` is incompatible with parent return type `resource` of `PhpDb\Adapter\Driver\ConnectionInterface::getresource()`'
169-
count = 1
170-
171159
[[issues]]
172160
file = "src/Adapter/Driver/AbstractConnection.php"
173161
code = "missing-api-or-internal"
@@ -363,19 +351,19 @@ count = 1
363351
[[issues]]
364352
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
365353
code = "non-existent-method"
366-
message = "Method `getlastgeneratedvalue` does not exist on type `PDO`."
354+
message = "Method `getLastGeneratedValue` does not exist on type `PDO`."
367355
count = 1
368356

369357
[[issues]]
370358
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
371359
code = "non-existent-method"
372-
message = "Method `getresource` does not exist on type `PDO`."
360+
message = "Method `getResource` does not exist on type `PDO`."
373361
count = 1
374362

375363
[[issues]]
376364
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
377365
code = "non-existent-method"
378-
message = "Method `isconnected` does not exist on type `PDO`."
366+
message = "Method `isConnected` does not exist on type `PDO`."
379367
count = 1
380368

381369
[[issues]]
@@ -426,12 +414,6 @@ code = "imprecise-type"
426414
message = "Type `array` in parameter `$connectionParameters` is imprecise, equivalent to `array<array-key, mixed>`."
427415
count = 1
428416

429-
[[issues]]
430-
file = "src/Adapter/Driver/Pdo/AbstractPdoConnection.php"
431-
code = "incompatible-property-type"
432-
message = 'Property `PhpDb\Adapter\Driver\Pdo\AbstractPdoConnection::$resource` has an incompatible type declaration from docblock.'
433-
count = 1
434-
435417
[[issues]]
436418
file = "src/Adapter/Driver/Pdo/AbstractPdoConnection.php"
437419
code = "missing-api-or-internal"
@@ -2610,12 +2592,6 @@ code = "nullable-return-statement"
26102592
message = '''Function `PhpDb\Sql\Join::current` is declared to return `array{'columns': array<array-key, PhpDb\Sql\ExpressionInterface|string>, 'name': PhpDb\Sql\TableIdentifier|non-empty-array<string, PhpDb\Sql\Expression|PhpDb\Sql\Select|PhpDb\Sql\TableIdentifier|string>|string, 'on': PhpDb\Sql\Predicate\PredicateInterface|string, 'type': string}` but possibly returns a nullable value (inferred as `array{'columns': array<array-key, PhpDb\Sql\ExpressionInterface|string>, 'name': PhpDb\Sql\TableIdentifier|non-empty-array<string, PhpDb\Sql\Expression|PhpDb\Sql\Select|PhpDb\Sql\TableIdentifier|string>|string, 'on': PhpDb\Sql\Predicate\PredicateInterface|string, 'type': string}|null`).'''
26112593
count = 1
26122594

2613-
[[issues]]
2614-
file = "src/Sql/Join.php"
2615-
code = "possibly-invalid-argument"
2616-
message = 'Possible argument type mismatch for argument #1 of `PhpDb\Sql\Exception\InvalidArgumentException::forInvalidJoinName`: expected `string`, but possibly received `PhpDb\Sql\Expression|PhpDb\Sql\Select|PhpDb\Sql\TableIdentifier|string`.'
2617-
count = 1
2618-
26192595
[[issues]]
26202596
file = "src/Sql/Join.php"
26212597
code = "possibly-undefined-int-array-index"
@@ -2667,25 +2643,25 @@ count = 1
26672643
[[issues]]
26682644
file = "src/Sql/Platform/AbstractPlatform.php"
26692645
code = "non-existent-method"
2670-
message = 'Method `getsqlstring` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
2646+
message = 'Method `getSqlString` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
26712647
count = 1
26722648

26732649
[[issues]]
26742650
file = "src/Sql/Platform/AbstractPlatform.php"
26752651
code = "non-existent-method"
2676-
message = 'Method `getsqlstring` does not exist on type `PhpDb\Sql\PreparableSqlInterface`.'
2652+
message = 'Method `getSqlString` does not exist on type `PhpDb\Sql\PreparableSqlInterface`.'
26772653
count = 1
26782654

26792655
[[issues]]
26802656
file = "src/Sql/Platform/AbstractPlatform.php"
26812657
code = "non-existent-method"
2682-
message = 'Method `preparestatement` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
2658+
message = 'Method `prepareStatement` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
26832659
count = 1
26842660

26852661
[[issues]]
26862662
file = "src/Sql/Platform/AbstractPlatform.php"
26872663
code = "non-existent-method"
2688-
message = 'Method `preparestatement` does not exist on type `PhpDb\Sql\SqlInterface`.'
2664+
message = 'Method `prepareStatement` does not exist on type `PhpDb\Sql\SqlInterface`.'
26892665
count = 1
26902666

26912667
[[issues]]
@@ -2715,25 +2691,25 @@ count = 1
27152691
[[issues]]
27162692
file = "src/Sql/Platform/Platform.php"
27172693
code = "non-existent-method"
2718-
message = 'Method `getsqlstring` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
2694+
message = 'Method `getSqlString` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
27192695
count = 1
27202696

27212697
[[issues]]
27222698
file = "src/Sql/Platform/Platform.php"
27232699
code = "non-existent-method"
2724-
message = 'Method `getsqlstring` does not exist on type `PhpDb\Sql\PreparableSqlInterface`.'
2700+
message = 'Method `getSqlString` does not exist on type `PhpDb\Sql\PreparableSqlInterface`.'
27252701
count = 1
27262702

27272703
[[issues]]
27282704
file = "src/Sql/Platform/Platform.php"
27292705
code = "non-existent-method"
2730-
message = 'Method `preparestatement` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
2706+
message = 'Method `prepareStatement` does not exist on type `PhpDb\Sql\Platform\PlatformDecoratorInterface`.'
27312707
count = 1
27322708

27332709
[[issues]]
27342710
file = "src/Sql/Platform/Platform.php"
27352711
code = "non-existent-method"
2736-
message = 'Method `preparestatement` does not exist on type `PhpDb\Sql\SqlInterface`.'
2712+
message = 'Method `prepareStatement` does not exist on type `PhpDb\Sql\SqlInterface`.'
27372713
count = 1
27382714

27392715
[[issues]]

‎infection.json5.dist‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// implode() discards keys, so array_fill()'s start index cannot be observed.
2323
"PhpDb\\Sql\\Argument\\Identifiers::getSpecification",
2424
"PhpDb\\Sql\\Argument\\Values::getSpecification",
25+
"PhpDb\\Sql\\Ddl\\Constraint\\AbstractConstraint::getExpressionData",
2526
"PhpDb\\Sql\\Ddl\\Constraint\\ForeignKey::getExpressionData"
2627
]
2728
},
@@ -30,6 +31,7 @@
3031
// implode() discards keys, so array_fill()'s start index cannot be observed.
3132
"PhpDb\\Sql\\Argument\\Identifiers::getSpecification",
3233
"PhpDb\\Sql\\Argument\\Values::getSpecification",
34+
"PhpDb\\Sql\\Ddl\\Constraint\\AbstractConstraint::getExpressionData",
3335
"PhpDb\\Sql\\Ddl\\Constraint\\ForeignKey::getExpressionData"
3436
]
3537
},

‎src/Adapter/Driver/AbstractConnection.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ abstract class AbstractConnection implements ConnectionInterface, ProfilerAwareI
2121

2222
protected ?ProfilerInterface $profiler = null;
2323

24-
/**
25-
* Extending classes must be covariant
26-
*
27-
* @var mixed
28-
*/
24+
/** Extending classes must be covariant. */
2925
protected $resource;
3026

3127
#[Override]

‎src/Adapter/Driver/ConnectionInterface.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getLastGeneratedValue(?string $name = null): string|int|false|nu
3030
/**
3131
* Get resource
3232
*
33-
* @return resource
33+
* @return resource|object|null
3434
*/
3535
public function getResource();
3636

‎src/Metadata/Source/AbstractSource.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,8 @@ public function getConstraintKeys(string $constraint, string $table, ?string $sc
300300
foreach ($this->data['constraint_keys'][$schema] ?? [] as $constraintKeyInfo) {
301301
if (
302302
! (
303-
304-
$constraintKeyInfo['table_name'] === $table
305-
&& $constraintKeyInfo['constraint_name'] === $constraint
306-
303+
$constraintKeyInfo['table_name'] === $table
304+
&& $constraintKeyInfo['constraint_name'] === $constraint
307305
)
308306
) {
309307
continue;

‎src/Sql/Join.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use function array_key_exists;
1313
use function array_shift;
1414
use function count;
15+
use function get_debug_type;
1516
use function is_array;
1617
use function is_string;
1718
use function key;
@@ -112,7 +113,11 @@ public function join(
112113
string $type = self::JOIN_INNER,
113114
): static {
114115
if (is_array($name) && (! is_string(key($name)) || count($name) !== 1)) {
115-
throw Exception\InvalidArgumentException::forInvalidJoinName(array_shift($name));
116+
$first = array_shift($name);
117+
118+
throw Exception\InvalidArgumentException::forInvalidJoinName(
119+
is_string($first) ? $first : get_debug_type($first),
120+
);
116121
}
117122

118123
if (! is_array($columns)) {

‎test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,21 @@ public function getExpressionData(): void
2828
$expressionData['values'],
2929
);
3030
}
31+
32+
#[Test]
33+
public function getExpressionDataListsEveryColumnInTheSpecification(): void
34+
{
35+
$pk = new PrimaryKey(['foo', 'bar']);
36+
37+
$expressionData = $pk->getExpressionData();
38+
39+
static::assertSame('PRIMARY KEY (%s, %s)', $expressionData['spec']);
40+
static::assertEquals(
41+
[
42+
Argument::identifier('foo'),
43+
Argument::identifier('bar'),
44+
],
45+
$expressionData['values'],
46+
);
47+
}
3148
}

‎test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,22 @@ public function getExpressionData(): void
2929
$expressionData['values'],
3030
);
3131
}
32+
33+
#[Test]
34+
public function getExpressionDataListsEveryColumnInTheSpecification(): void
35+
{
36+
$uk = new UniqueKey(['foo', 'bar'], 'my_uk');
37+
38+
$expressionData = $uk->getExpressionData();
39+
40+
static::assertSame('CONSTRAINT %s UNIQUE (%s, %s)', $expressionData['spec']);
41+
static::assertEquals(
42+
[
43+
Argument::identifier('my_uk'),
44+
Argument::identifier('foo'),
45+
Argument::identifier('bar'),
46+
],
47+
$expressionData['values'],
48+
);
49+
}
3250
}

‎test/unit/Sql/JoinTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpDb\Sql\Select;
1010
use PhpDbTest\DeprecatedAssertionsTrait;
1111
use PHPUnit\Framework\Attributes\CoversMethod;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1314
use PHPUnit\Framework\Attributes\RequiresPhp;
1415
use PHPUnit\Framework\Attributes\Test;
@@ -32,6 +33,16 @@ class JoinTest extends TestCase
3233
{
3334
use DeprecatedAssertionsTrait;
3435

36+
/** @return array<string, array{array<array-key, mixed>, string}> */
37+
public static function invalidJoinNameWithoutStringElementProvider(): array
38+
{
39+
return [
40+
'empty array' => [[], 'null'],
41+
'select without alias' => [[new Select('foo')], Select::class],
42+
'integer element' => [[5], 'int'],
43+
];
44+
}
45+
3546
#[Test]
3647
#[TestDox('unit test: Test count() returns correct count')]
3748
public function countsJoinedTables(): void
@@ -91,6 +102,20 @@ public function joinFullOuter(): void
91102
static::assertSame($join, $return);
92103
}
93104

105+
/**
106+
* @param array<array-key, mixed> $name
107+
*/
108+
#[Test]
109+
#[DataProvider('invalidJoinNameWithoutStringElementProvider')]
110+
public function joinThrowsInvalidArgumentWhenInvalidNameHasNoLeadingString(array $name, string $described): void
111+
{
112+
$join = new Join();
113+
114+
self::expectException(InvalidArgumentException::class);
115+
self::expectExceptionMessage("expects '{$described}' as a single element associative array");
116+
$join->join($name, 'on');
117+
}
118+
94119
#[Test]
95120
public function joinThrowsOnInvalidMultiElementArray(): void
96121
{

0 commit comments

Comments
 (0)