Skip to content

Commit

Permalink
Import global constants
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Feb 16, 2023
1 parent 23d8ef0 commit 85ffe81
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 57 deletions.
6 changes: 0 additions & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@
<exclude-pattern>src/Query/QueryBuilder.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="searchAnnotations" value="0"/>
</properties>
</rule>

<!-- see https://github.com/doctrine/dbal/issues/3377 -->
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator">
<exclude-pattern>src/Schema/Comparator.php</exclude-pattern>
Expand Down
17 changes: 0 additions & 17 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,6 @@
<errorLevel type="suppress">
<!-- We're testing with invalid input here. -->
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>

<!-- See https://github.com/vimeo/psalm/issues/9320 -->
<file name="src/Portability/Converter.php"/>
<file name="src/Portability/Driver.php"/>
<file name="tests/Portability/ConnectionTest.php"/>
<file name="tests/Portability/ConverterTest.php"/>
</errorLevel>
</InvalidArgument>
<InvalidDocblock>
Expand Down Expand Up @@ -807,10 +801,6 @@
and may not properly interpret the LanguageLevelTypeAware annotation from the stubs.
-->
<referencedClass name="OCILob"/>

<!-- See https://github.com/vimeo/psalm/issues/9320 -->
<file name="src/Portability/Converter.php"/>
<file name="tests/Portability/ConverterTest.php"/>
</errorLevel>
</UndefinedDocblockClass>
<InvalidReturnStatement>
Expand Down Expand Up @@ -853,12 +843,5 @@
<referencedFunction name="db2_autocommit"/>
</errorLevel>
</InvalidScalarArgument>
<MismatchingDocblockParamType>
<errorLevel type="suppress">
<!-- See https://github.com/vimeo/psalm/issues/9320 -->
<file name="src/Portability/Converter.php"/>
<file name="tests/Portability/ConverterTest.php"/>
</errorLevel>
</MismatchingDocblockParamType>
</issueHandlers>
</psalm>
21 changes: 14 additions & 7 deletions src/Portability/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
use function is_string;
use function rtrim;

use const CASE_LOWER;
use const CASE_UPPER;

final class Converter
{
public const CASE_LOWER = CASE_LOWER;
public const CASE_UPPER = CASE_UPPER;

/** @var callable */
private $convertNumeric;

Expand All @@ -31,11 +37,12 @@ final class Converter
private $convertFirstColumn;

/**
* @param bool $convertEmptyStringToNull Whether each empty string should be converted
* to NULL
* @param bool $rightTrimString Whether each string should right-trimmed
* @param \CASE_LOWER|\CASE_UPPER|null $case Convert the case of the column names
* (one of {@see CASE_LOWER} and {@see CASE_UPPER})
* @param bool $convertEmptyStringToNull Whether each empty string should
* be converted to NULL
* @param bool $rightTrimString Whether each string should right-trimmed
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Convert the case of the column names
* (one of {@see self::CASE_LOWER} and
* {@see self::CASE_UPPER})
*/
public function __construct(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case)
{
Expand Down Expand Up @@ -183,8 +190,8 @@ private function createConvertValue(bool $convertEmptyStringToNull, bool $rightT
/**
* Creates a function that will convert each array-row retrieved from the database
*
* @param callable|null $function The function that will convert each value
* @param \CASE_LOWER|\CASE_UPPER|null $case Column name case
* @param callable|null $function The function that will convert each value
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Column name case
*
* @return callable|null The resulting function or NULL if no conversion is needed
*/
Expand Down
5 changes: 1 addition & 4 deletions src/Portability/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

use function method_exists;

use const CASE_LOWER;
use const CASE_UPPER;

final class Driver extends AbstractDriverMiddleware
{
private int $mode;
Expand Down Expand Up @@ -59,7 +56,7 @@ public function connect(
$portability &= ~Connection::PORTABILITY_FIX_CASE;
$nativeConnection->setAttribute(PDO::ATTR_CASE, self::convertToPdoCase($this->case));
} else {
$case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
$case = $this->case === ColumnCase::LOWER ? Converter::CASE_LOWER : Converter::CASE_UPPER;
}
}

Expand Down
10 changes: 4 additions & 6 deletions tests/Portability/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use LogicException;
use PHPUnit\Framework\TestCase;

use const CASE_LOWER;

class ConnectionTest extends TestCase
{
public function testGetServerVersion(): void
Expand All @@ -20,7 +18,7 @@ public function testGetServerVersion(): void
->method('getServerVersion')
->willReturn('1.2.3');

$connection = new Connection($driverConnection, new Converter(false, false, CASE_LOWER));
$connection = new Connection($driverConnection, new Converter(false, false, Converter::CASE_LOWER));

self::assertSame('1.2.3', $connection->getServerVersion());
}
Expand All @@ -29,7 +27,7 @@ public function testGetServerVersionFailsWithLegacyConnection(): void
{
$connection = new Connection(
$this->createMock(DriverConnection::class),
new Converter(false, false, CASE_LOWER),
new Converter(false, false, Converter::CASE_LOWER),
);

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

$connection = new Connection($driverConnection, new Converter(false, false, CASE_LOWER));
$connection = new Connection($driverConnection, new Converter(false, false, Converter::CASE_LOWER));

self::assertSame($nativeConnection, $connection->getNativeConnection());
}
Expand All @@ -54,7 +52,7 @@ public function testGetNativeConnectionFailsWithLegacyConnection(): void
{
$connection = new Connection(
$this->createMock(DriverConnection::class),
new Converter(false, false, CASE_LOWER),
new Converter(false, false, Converter::CASE_LOWER),
);

$this->expectException(LogicException::class);
Expand Down
32 changes: 15 additions & 17 deletions tests/Portability/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Doctrine\DBAL\Portability\Converter;
use PHPUnit\Framework\TestCase;

use const CASE_LOWER;

class ConverterTest extends TestCase
{
/**
Expand Down Expand Up @@ -61,9 +59,9 @@ public static function convertNumericProvider(): iterable
}

/**
* @param array<string,mixed>|false $row
* @param CASE_LOWER|CASE_UPPER|null $case
* @param array<string,mixed>|false $expected
* @param array<string,mixed>|false $row
* @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case
* @param array<string,mixed>|false $expected
*
* @dataProvider convertAssociativeProvider
*/
Expand Down Expand Up @@ -137,7 +135,7 @@ public static function convertAssociativeProvider(): iterable
$row,
false,
false,
CASE_LOWER,
Converter::CASE_LOWER,
[
'foo' => '',
'bar' => 'X ',
Expand All @@ -148,7 +146,7 @@ public static function convertAssociativeProvider(): iterable
$row,
false,
true,
CASE_LOWER,
Converter::CASE_LOWER,
[
'foo' => '',
'bar' => 'X',
Expand All @@ -159,7 +157,7 @@ public static function convertAssociativeProvider(): iterable
$row,
true,
false,
CASE_LOWER,
Converter::CASE_LOWER,
[
'foo' => null,
'bar' => 'X ',
Expand All @@ -170,7 +168,7 @@ public static function convertAssociativeProvider(): iterable
$row,
true,
true,
CASE_LOWER,
Converter::CASE_LOWER,
[
'foo' => null,
'bar' => 'X',
Expand Down Expand Up @@ -277,9 +275,9 @@ public static function convertAllNumericProvider(): iterable
}

/**
* @param list<array<string,mixed>> $row
* @param CASE_LOWER|CASE_UPPER|null $case
* @param list<array<string,mixed>> $expected
* @param list<array<string,mixed>> $row
* @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case
* @param list<array<string,mixed>> $expected
*
* @dataProvider convertAllAssociativeProvider
*/
Expand Down Expand Up @@ -383,7 +381,7 @@ public static function convertAllAssociativeProvider(): iterable
$data,
false,
false,
CASE_LOWER,
Converter::CASE_LOWER,
[
[
'foo' => 'X ',
Expand All @@ -400,7 +398,7 @@ public static function convertAllAssociativeProvider(): iterable
$data,
false,
true,
CASE_LOWER,
Converter::CASE_LOWER,
[
[
'foo' => 'X',
Expand All @@ -417,7 +415,7 @@ public static function convertAllAssociativeProvider(): iterable
$data,
true,
false,
CASE_LOWER,
Converter::CASE_LOWER,
[
[
'foo' => 'X ',
Expand All @@ -434,7 +432,7 @@ public static function convertAllAssociativeProvider(): iterable
$data,
true,
true,
CASE_LOWER,
Converter::CASE_LOWER,
[
[
'foo' => 'X',
Expand Down Expand Up @@ -501,7 +499,7 @@ public static function convertFirstColumnProvider(): iterable
];
}

/** @param \CASE_LOWER|\CASE_UPPER|null $case */
/** @param Converter::CASE_LOWER|Converter::CASE_UPPER|null $case */
private function createConverter(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case): Converter
{
return new Converter($convertEmptyStringToNull, $rightTrimString, $case);
Expand Down

0 comments on commit 85ffe81

Please sign in to comment.