Skip to content

Commit ed99561

Browse files
committed
Import global constants
1 parent 23d8ef0 commit ed99561

File tree

6 files changed

+34
-57
lines changed

6 files changed

+34
-57
lines changed

phpcs.xml.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@
118118
<exclude-pattern>src/Query/QueryBuilder.php</exclude-pattern>
119119
</rule>
120120

121-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
122-
<properties>
123-
<property name="searchAnnotations" value="0"/>
124-
</properties>
125-
</rule>
126-
127121
<!-- see https://github.com/doctrine/dbal/issues/3377 -->
128122
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator">
129123
<exclude-pattern>src/Schema/Comparator.php</exclude-pattern>

psalm.xml.dist

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,6 @@
605605
<errorLevel type="suppress">
606606
<!-- We're testing with invalid input here. -->
607607
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
608-
609-
<!-- See https://github.com/vimeo/psalm/issues/9320 -->
610-
<file name="src/Portability/Converter.php"/>
611-
<file name="src/Portability/Driver.php"/>
612-
<file name="tests/Portability/ConnectionTest.php"/>
613-
<file name="tests/Portability/ConverterTest.php"/>
614608
</errorLevel>
615609
</InvalidArgument>
616610
<InvalidDocblock>
@@ -807,10 +801,6 @@
807801
and may not properly interpret the LanguageLevelTypeAware annotation from the stubs.
808802
-->
809803
<referencedClass name="OCILob"/>
810-
811-
<!-- See https://github.com/vimeo/psalm/issues/9320 -->
812-
<file name="src/Portability/Converter.php"/>
813-
<file name="tests/Portability/ConverterTest.php"/>
814804
</errorLevel>
815805
</UndefinedDocblockClass>
816806
<InvalidReturnStatement>
@@ -853,12 +843,5 @@
853843
<referencedFunction name="db2_autocommit"/>
854844
</errorLevel>
855845
</InvalidScalarArgument>
856-
<MismatchingDocblockParamType>
857-
<errorLevel type="suppress">
858-
<!-- See https://github.com/vimeo/psalm/issues/9320 -->
859-
<file name="src/Portability/Converter.php"/>
860-
<file name="tests/Portability/ConverterTest.php"/>
861-
</errorLevel>
862-
</MismatchingDocblockParamType>
863846
</issueHandlers>
864847
</psalm>

src/Portability/Converter.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
use function is_string;
1111
use function rtrim;
1212

13+
use const CASE_LOWER;
14+
use const CASE_UPPER;
15+
1316
final class Converter
1417
{
18+
public const CASE_LOWER = CASE_LOWER;
19+
public const CASE_UPPER = CASE_UPPER;
20+
1521
/** @var callable */
1622
private $convertNumeric;
1723

@@ -31,11 +37,12 @@ final class Converter
3137
private $convertFirstColumn;
3238

3339
/**
34-
* @param bool $convertEmptyStringToNull Whether each empty string should be converted
35-
* to NULL
36-
* @param bool $rightTrimString Whether each string should right-trimmed
37-
* @param \CASE_LOWER|\CASE_UPPER|null $case Convert the case of the column names
38-
* (one of {@see CASE_LOWER} and {@see CASE_UPPER})
40+
* @param bool $convertEmptyStringToNull Whether each empty string should
41+
* be converted to NULL
42+
* @param bool $rightTrimString Whether each string should right-trimmed
43+
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Convert the case of the column names
44+
* (one of {@see self::CASE_LOWER} and
45+
* {@see self::CASE_UPPER})
3946
*/
4047
public function __construct(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case)
4148
{
@@ -183,8 +190,8 @@ private function createConvertValue(bool $convertEmptyStringToNull, bool $rightT
183190
/**
184191
* Creates a function that will convert each array-row retrieved from the database
185192
*
186-
* @param callable|null $function The function that will convert each value
187-
* @param \CASE_LOWER|\CASE_UPPER|null $case Column name case
193+
* @param callable|null $function The function that will convert each value
194+
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Column name case
188195
*
189196
* @return callable|null The resulting function or NULL if no conversion is needed
190197
*/

src/Portability/Driver.php

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

1212
use function method_exists;
1313

14-
use const CASE_LOWER;
15-
use const CASE_UPPER;
16-
1714
final class Driver extends AbstractDriverMiddleware
1815
{
1916
private int $mode;
@@ -59,7 +56,7 @@ public function connect(
5956
$portability &= ~Connection::PORTABILITY_FIX_CASE;
6057
$nativeConnection->setAttribute(PDO::ATTR_CASE, self::convertToPdoCase($this->case));
6158
} else {
62-
$case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
59+
$case = $this->case === ColumnCase::LOWER ? Converter::CASE_LOWER : Converter::CASE_UPPER;
6360
}
6461
}
6562

tests/Portability/ConnectionTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use LogicException;
1010
use PHPUnit\Framework\TestCase;
1111

12-
use const CASE_LOWER;
13-
1412
class ConnectionTest extends TestCase
1513
{
1614
public function testGetServerVersion(): void
@@ -20,7 +18,7 @@ public function testGetServerVersion(): void
2018
->method('getServerVersion')
2119
->willReturn('1.2.3');
2220

23-
$connection = new Connection($driverConnection, new Converter(false, false, CASE_LOWER));
21+
$connection = new Connection($driverConnection, new Converter(false, false, Converter::CASE_LOWER));
2422

2523
self::assertSame('1.2.3', $connection->getServerVersion());
2624
}
@@ -29,7 +27,7 @@ public function testGetServerVersionFailsWithLegacyConnection(): void
2927
{
3028
$connection = new Connection(
3129
$this->createMock(DriverConnection::class),
32-
new Converter(false, false, CASE_LOWER),
30+
new Converter(false, false, Converter::CASE_LOWER),
3331
);
3432

3533
$this->expectException(LogicException::class);
@@ -45,7 +43,7 @@ public function testGetNativeConnection(): void
4543
$driverConnection->method('getNativeConnection')
4644
->willReturn($nativeConnection);
4745

48-
$connection = new Connection($driverConnection, new Converter(false, false, CASE_LOWER));
46+
$connection = new Connection($driverConnection, new Converter(false, false, Converter::CASE_LOWER));
4947

5048
self::assertSame($nativeConnection, $connection->getNativeConnection());
5149
}
@@ -54,7 +52,7 @@ public function testGetNativeConnectionFailsWithLegacyConnection(): void
5452
{
5553
$connection = new Connection(
5654
$this->createMock(DriverConnection::class),
57-
new Converter(false, false, CASE_LOWER),
55+
new Converter(false, false, Converter::CASE_LOWER),
5856
);
5957

6058
$this->expectException(LogicException::class);

tests/Portability/ConverterTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Doctrine\DBAL\Portability\Converter;
66
use PHPUnit\Framework\TestCase;
77

8-
use const CASE_LOWER;
9-
108
class ConverterTest extends TestCase
119
{
1210
/**
@@ -61,9 +59,9 @@ public static function convertNumericProvider(): iterable
6159
}
6260

6361
/**
64-
* @param array<string,mixed>|false $row
65-
* @param CASE_LOWER|CASE_UPPER|null $case
66-
* @param array<string,mixed>|false $expected
62+
* @param array<string,mixed>|false $row
63+
* @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case
64+
* @param array<string,mixed>|false $expected
6765
*
6866
* @dataProvider convertAssociativeProvider
6967
*/
@@ -137,7 +135,7 @@ public static function convertAssociativeProvider(): iterable
137135
$row,
138136
false,
139137
false,
140-
CASE_LOWER,
138+
Converter::CASE_LOWER,
141139
[
142140
'foo' => '',
143141
'bar' => 'X ',
@@ -148,7 +146,7 @@ public static function convertAssociativeProvider(): iterable
148146
$row,
149147
false,
150148
true,
151-
CASE_LOWER,
149+
Converter::CASE_LOWER,
152150
[
153151
'foo' => '',
154152
'bar' => 'X',
@@ -159,7 +157,7 @@ public static function convertAssociativeProvider(): iterable
159157
$row,
160158
true,
161159
false,
162-
CASE_LOWER,
160+
Converter::CASE_LOWER,
163161
[
164162
'foo' => null,
165163
'bar' => 'X ',
@@ -170,7 +168,7 @@ public static function convertAssociativeProvider(): iterable
170168
$row,
171169
true,
172170
true,
173-
CASE_LOWER,
171+
Converter::CASE_LOWER,
174172
[
175173
'foo' => null,
176174
'bar' => 'X',
@@ -277,9 +275,9 @@ public static function convertAllNumericProvider(): iterable
277275
}
278276

279277
/**
280-
* @param list<array<string,mixed>> $row
281-
* @param CASE_LOWER|CASE_UPPER|null $case
282-
* @param list<array<string,mixed>> $expected
278+
* @param list<array<string,mixed>> $row
279+
* @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case
280+
* @param list<array<string,mixed>> $expected
283281
*
284282
* @dataProvider convertAllAssociativeProvider
285283
*/
@@ -383,7 +381,7 @@ public static function convertAllAssociativeProvider(): iterable
383381
$data,
384382
false,
385383
false,
386-
CASE_LOWER,
384+
Converter::CASE_LOWER,
387385
[
388386
[
389387
'foo' => 'X ',
@@ -400,7 +398,7 @@ public static function convertAllAssociativeProvider(): iterable
400398
$data,
401399
false,
402400
true,
403-
CASE_LOWER,
401+
Converter::CASE_LOWER,
404402
[
405403
[
406404
'foo' => 'X',
@@ -417,7 +415,7 @@ public static function convertAllAssociativeProvider(): iterable
417415
$data,
418416
true,
419417
false,
420-
CASE_LOWER,
418+
Converter::CASE_LOWER,
421419
[
422420
[
423421
'foo' => 'X ',
@@ -434,7 +432,7 @@ public static function convertAllAssociativeProvider(): iterable
434432
$data,
435433
true,
436434
true,
437-
CASE_LOWER,
435+
Converter::CASE_LOWER,
438436
[
439437
[
440438
'foo' => 'X',
@@ -501,7 +499,7 @@ public static function convertFirstColumnProvider(): iterable
501499
];
502500
}
503501

504-
/** @param \CASE_LOWER|\CASE_UPPER|null $case */
502+
/** @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case */
505503
private function createConverter(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case): Converter
506504
{
507505
return new Converter($convertEmptyStringToNull, $rightTrimString, $case);

0 commit comments

Comments
 (0)