Skip to content

Commit

Permalink
Merge branch '3.1.x' into 3.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jul 15, 2021
2 parents b37d126 + 2549642 commit 812213b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"squizlabs/php_codesniffer": "3.6.0",
"symfony/cache": "^5.2|^6.0",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0|^6.0",
"vimeo/psalm": "4.6.4"
"vimeo/psalm": "4.8.1"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
Expand Down
9 changes: 2 additions & 7 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<!-- Show progress of the run and show sniff names -->
<arg value="ps"/>

<config name="php_version" value="70300"/>

<file>bin</file>
<file>src</file>
<file>tests</file>
Expand All @@ -37,13 +39,6 @@
<exclude-pattern>*/lib/Doctrine/DBAL/Driver/PDOStatementImplementations.php</exclude-pattern>
</rule>

<!-- Disable the rules that will require PHP 7.4 -->
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="false"/>
</properties>
</rule>

<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<exclude-pattern>*/src/Configuration.php</exclude-pattern>
<exclude-pattern>*/src/Connection.php</exclude-pattern>
Expand Down
14 changes: 14 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
See https://github.com/vimeo/psalm/issues/5325
-->
<file name="tests/Driver/OCI8/ExecutionModeTest.php"/>
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
<file name="src/Portability/Converter.php"/>
</errorLevel>
</DocblockTypeContradiction>
<FalsableReturnStatement>
Expand All @@ -162,6 +164,12 @@
<file name="src/Driver/OCI8/Connection.php"/>
</errorLevel>
</ImplementedReturnTypeMismatch>
<InvalidDocblock>
<errorLevel type="suppress">
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
<file name="src/Portability/Converter.php"/>
</errorLevel>
</InvalidDocblock>
<InvalidNullableReturnType>
<errorLevel type="suppress">
<!-- See https://github.com/doctrine/dbal/issues/4503 -->
Expand Down Expand Up @@ -301,6 +309,12 @@
<file name="src/Tools/Dumper.php"/>
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
<referencedClass name="Doctrine\DBAL\Portability\T"/>
</errorLevel>
</UndefinedDocblockClass>
<UnsafeInstantiation>
<errorLevel type="suppress">
<!-- See https://github.com/doctrine/dbal/issues/4510 -->
Expand Down
10 changes: 5 additions & 5 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1352,13 +1352,13 @@ public function getWriteLockSQL()
/**
* Returns the SQL snippet to drop an existing database.
*
* @param string $database The name of the database that should be dropped.
* @param string $name The name of the database that should be dropped.
*
* @return string
*/
public function getDropDatabaseSQL($database)
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $database;
return 'DROP DATABASE ' . $name;
}

/**
Expand Down Expand Up @@ -2929,13 +2929,13 @@ public function getSequenceNextValSQL($sequence)
/**
* Returns the SQL to create a new database.
*
* @param string $database The name of the database that should be created.
* @param string $name The name of the database that should be created.
*
* @return string
*
* @throws Exception If not supported on this platform.
*/
public function getCreateDatabaseSQL($database)
public function getCreateDatabaseSQL($name)
{
throw Exception::notSupported(__METHOD__);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,17 @@ public function getDropViewSQL($name)
/**
* {@inheritDoc}
*/
public function getCreateDatabaseSQL($database)
public function getCreateDatabaseSQL($name)
{
return 'CREATE DATABASE ' . $database;
return 'CREATE DATABASE ' . $name;
}

/**
* {@inheritDoc}
*/
public function getDropDatabaseSQL($database)
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $database;
return 'DROP DATABASE ' . $name;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ public function getForeignKeyReferentialActionSQL($action)
/**
* {@inheritDoc}
*/
public function getDropDatabaseSQL($database)
public function getDropDatabaseSQL($name)
{
return 'DROP USER ' . $database . ' CASCADE';
return 'DROP USER ' . $name . ' CASCADE';
}

/**
Expand Down
101 changes: 53 additions & 48 deletions src/Portability/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,17 @@ final class Converter
*/
public function __construct(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case)
{
$id =
/**
* @param T $value
*
* @return T
*
* @template T
*/
static function ($value) {
return $value;
};

$convertValue = $this->createConvertValue($convertEmptyStringToNull, $rightTrimString);
$convertNumeric = $this->createConvertRow($convertValue, null);
$convertAssociative = $this->createConvertRow($convertValue, $case);

$this->convertNumeric = $this->createConvert($convertNumeric, $id);
$this->convertAssociative = $this->createConvert($convertAssociative, $id);
$this->convertOne = $this->createConvert($convertValue, $id);
$this->convertNumeric = $this->createConvert($convertNumeric, [self::class, 'id']);
$this->convertAssociative = $this->createConvert($convertAssociative, [self::class, 'id']);
$this->convertOne = $this->createConvert($convertValue, [self::class, 'id']);

$this->convertAllNumeric = $this->createConvertAll($convertNumeric, $id);
$this->convertAllAssociative = $this->createConvertAll($convertAssociative, $id);
$this->convertFirstColumn = $this->createConvertAll($convertValue, $id);
$this->convertAllNumeric = $this->createConvertAll($convertNumeric, [self::class, 'id']);
$this->convertAllAssociative = $this->createConvertAll($convertAssociative, [self::class, 'id']);
$this->convertFirstColumn = $this->createConvertAll($convertValue, [self::class, 'id']);
}

/**
Expand Down Expand Up @@ -123,6 +111,51 @@ public function convertFirstColumn(array $data): array
return ($this->convertFirstColumn)($data);
}

/**
* @param T $value
*
* @return T
*
* @template T
*/
private static function id($value)
{
return $value;
}

/**
* @param T $value
*
* @return T|null
*
* @template T
*/
private static function convertEmptyStringToNull($value)
{
if ($value === '') {
return null;
}

return $value;
}

/**
* @param T $value
*
* @return T|string
* @psalm-return (T is string ? string : T)
*
* @template T
*/
private static function rightTrimString($value)
{
if (! is_string($value)) {
return $value;
}

return rtrim($value);
}

/**
* Creates a function that will convert each individual value retrieved from the database
*
Expand All @@ -136,39 +169,11 @@ private function createConvertValue(bool $convertEmptyStringToNull, bool $rightT
$functions = [];

if ($convertEmptyStringToNull) {
$functions[] =
/**
* @param T $value
*
* @return T|null
*
* @template T
*/
static function ($value) {
if ($value === '') {
return null;
}

return $value;
};
$functions[] = [self::class, 'convertEmptyStringToNull'];
}

if ($rightTrimString) {
$functions[] =
/**
* @param T $value
*
* @psalm-return (T is string ? string : T)
*
* @template T
*/
static function ($value) {
if (! is_string($value)) {
return $value;
}

return rtrim($value);
};
$functions[] = [self::class, 'rightTrimString'];
}

return $this->compose(...$functions);
Expand Down

0 comments on commit 812213b

Please sign in to comment.