Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/phpstan/baselines/deprecated-methods.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- '#Call to deprecated method getName\(\) of class MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseType#'
11 changes: 11 additions & 0 deletions ci/phpstan/baselines/lexer-constants.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
- '#Access to undefined constant Doctrine\\ORM\\Query\\Lexer::T_[A-Z_]+#'
- '#Access to constant [A-Z_]+ on an unknown class Doctrine\\ORM\\Query\\TokenType#'
- '#Fetching deprecated class constant T_IDENTIFIER of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_OPEN_PARENTHESIS of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_CLOSE_PARENTHESIS of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_COMMA of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_ORDER of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_AS of class Doctrine\\ORM\\Query\\Lexer#'
- '#Fetching deprecated class constant T_DISTINCT of class Doctrine\\ORM\\Query\\Lexer#'
3 changes: 3 additions & 0 deletions ci/phpstan/baselines/phpstan-identifiers.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- identifier: missingType.iterableValue
5 changes: 5 additions & 0 deletions ci/phpstan/baselines/type-mismatches.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
- '#Parameter \#1 \$phpArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToDatabaseValue\(\) expects array\|null, string given.#'
- '#Parameter \#1 \$postgresArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToPHPValue\(\) expects string\|null, int given.#'
- '#Property MartinGeorgiev\\Doctrine\\ORM\\Query\\AST\\Functions\\Cast::\$sourceType \(Doctrine\\ORM\\Query\\AST\\Node\) does not accept Doctrine\\ORM\\Query\\AST\\Node\|string#'
21 changes: 12 additions & 9 deletions ci/phpstan/config.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
includes:
- ../../vendor/ekino/phpstan-banned-code/extension.neon
- ../../vendor/phpstan/phpstan-deprecation-rules/rules.neon
- ../../vendor/phpstan/phpstan-doctrine/extension.neon
- ../../vendor/phpstan/phpstan-phpunit/extension.neon
- ./baselines/deprecated-methods.neon
- ./baselines/lexer-constants.neon
- ./baselines/phpstan-identifiers.neon
- ./baselines/type-mismatches.neon

parameters:
level: max
Expand All @@ -9,13 +15,10 @@ parameters:
- ../../src
- ../../tests

reportUnmatchedIgnoredErrors: false
tmpDir: ../../var/cache/phpstan

parallel:
maximumNumberOfProcesses: 4

ignoreErrors:
- identifier: missingType.iterableValue

- '#Parameter \#1 \$phpArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToDatabaseValue\(\) expects array\|null, string given.#'
- '#Parameter \#1 \$postgresArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToPHPValue\(\) expects string\|null, int given.#'
- '#Property MartinGeorgiev\\Doctrine\\ORM\\Query\\AST\\Functions\\Cast::\$sourceType \(Doctrine\\ORM\\Query\\AST\\Node\) does not accept Doctrine\\ORM\\Query\\AST\\Node\|string#'
- '#Access to undefined constant Doctrine\\ORM\\Query\\Lexer::T_[A-Z_]+#'
- '#Access to constant [A-Z_]+ on an unknown class Doctrine\\ORM\\Query\\TokenType#'
errorFormat: table
reportUnmatchedIgnoredErrors: false
38 changes: 27 additions & 11 deletions ci/phpunit/config.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" stopOnFailure="false" bootstrap="../../vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="PostgreSQL-for-Doctrine Test Suite">
<directory>../../tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../../src</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
stopOnFailure="false"
bootstrap="../../vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory="../../var/cache/phpunit/"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true">
<testsuites>
<testsuite name="PostgreSQL-for-Doctrine Test Suite">
<directory>../../tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="../../var/coverage/html"/>
<clover outputFile="../../var/coverage/clover.xml"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">../../src</directory>
</include>
</source>
</phpunit>
35 changes: 21 additions & 14 deletions ci/rector/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,36 @@
$basePath = __DIR__.'/../../';
$paths = [
$basePath.'ci',
$basePath.'fixtures',
$basePath.'src',
$basePath.'tests',
];
$rectorConfig->paths($paths);

$rectorConfig->cacheDirectory($basePath.'var/cache/rector/');

$rectorConfig->parallel();
$rectorConfig->phpstanConfig($basePath.'ci/phpstan/config.neon');

$rectorConfig->sets([
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::NAMING,
SetList::PHP_80,
SetList::PHP_81,
SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
SetList::CODING_STYLE,
DoctrineSetList::DOCTRINE_ORM_25,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
RenamePropertyToMatchTypeRector::class,
]);
$rectorConfig->importShortClasses(false);
$rectorConfig->importNames(false, false); // @todo Enable once Rector introduces better support for function imports.

$rectorConfig->import(SetList::CODE_QUALITY);
$rectorConfig->import(SetList::DEAD_CODE);
$rectorConfig->import(SetList::EARLY_RETURN);
$rectorConfig->import(SetList::NAMING);
$rectorConfig->import(SetList::PHP_80);
$rectorConfig->import(SetList::PHP_81);
$rectorConfig->import(SetList::TYPE_DECLARATION);

$rectorConfig->import(DoctrineSetList::DOCTRINE_ORM_25);
$rectorConfig->import(DoctrineSetList::DOCTRINE_CODE_QUALITY);

$rectorConfig->import(LevelSetList::UP_TO_PHP_81);
$rectorConfig->importShortClasses(false);
$rectorConfig->importNames(false, false);
};
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
"ekino/phpstan-banned-code": "^1.0",
"friendsofphp/php-cs-fixer": "^3.72.0",
"phpstan/phpstan": "^1.12.21",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-doctrine": "^1.5",
"phpstan/phpstan-phpunit": "^1.4.2",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^1.2.10",
"rector/rector": "^1.2",
"symfony/cache": "^6.4||^7.0"
},
"suggest": {
Expand Down
5 changes: 3 additions & 2 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsArrays extends Entity
{
#[ORM\Column(type: 'json')]
#[ORM\Column(type: Types::JSON)]
public array $array1;

#[ORM\Column(type: 'json')]
#[ORM\Column(type: Types::JSON)]
public array $array2;
}
13 changes: 7 additions & 6 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsDates extends Entity
{
#[ORM\Column(type: 'date_immutable')]
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
public \DateTimeImmutable $date1;

#[ORM\Column(type: 'date_immutable')]
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
public \DateTimeImmutable $date2;

#[ORM\Column(type: 'datetime_immutable')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
public \DateTimeImmutable $datetime1;

#[ORM\Column(type: 'datetime_immutable')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
public \DateTimeImmutable $datetime2;

#[ORM\Column(type: 'datetimetz_immutable')]
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
public \DateTimeImmutable $datetimetz1;

#[ORM\Column(type: 'datetimetz_immutable')]
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
public \DateTimeImmutable $datetimetz2;
}
7 changes: 4 additions & 3 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDecimals.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsDecimals extends Entity
{
#[ORM\Column(type: 'decimal')]
#[ORM\Column(type: Types::DECIMAL)]
public float $decimal1;

#[ORM\Column(type: 'decimal')]
#[ORM\Column(type: Types::DECIMAL)]
public float $decimal2;

#[ORM\Column(type: 'decimal')]
#[ORM\Column(type: Types::DECIMAL)]
public float $decimal3;
}
7 changes: 4 additions & 3 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsIntegers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsIntegers extends Entity
{
#[ORM\Column(type: 'integer')]
#[ORM\Column(type: Types::INTEGER)]
public int $integer1;

#[ORM\Column(type: 'integer')]
#[ORM\Column(type: Types::INTEGER)]
public int $integer2;

#[ORM\Column(type: 'integer')]
#[ORM\Column(type: Types::INTEGER)]
public int $integer3;
}
5 changes: 3 additions & 2 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsJsons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsJsons extends Entity
{
#[ORM\Column(type: 'json')]
#[ORM\Column(type: Types::JSON)]
public array $object1;

#[ORM\Column(type: 'json')]
#[ORM\Column(type: Types::JSON)]
public array $object2;
}
5 changes: 3 additions & 2 deletions fixtures/MartinGeorgiev/Doctrine/Entity/ContainsTexts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class ContainsTexts extends Entity
{
#[ORM\Column(type: 'text')]
#[ORM\Column(type: Types::TEXT)]
public string $text1;

#[ORM\Column(type: 'text')]
#[ORM\Column(type: Types::TEXT)]
public string $text2;
}
10 changes: 2 additions & 8 deletions fixtures/MartinGeorgiev/Doctrine/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@

namespace Fixtures\MartinGeorgiev\Doctrine\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

abstract class Entity
{
/**
* @ORM\Id
*
* @ORM\Column(type="string")
*
* @ORM\GeneratedValue
*/
#[ORM\Id()]
#[ORM\Column(type: 'string')]
#[ORM\Column(type: Types::STRING)]
#[ORM\GeneratedValue()]
public string $id;
}
8 changes: 5 additions & 3 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/BaseArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public function convertToDatabaseValue($phpArray, AbstractPlatform $platform): ?

foreach ($phpArray as &$item) {
if (!$this->isValidArrayItemForDatabase($item)) {
$exceptionMessage = 'One or more of the items given doesn\'t look valid.';
$exceptionMessage = "One or more of the items given doesn't look valid.";

throw new ConversionException($exceptionMessage);
}

$item = $this->transformArrayItemForPostgres($item);
}

Expand All @@ -51,7 +52,7 @@ public function convertToDatabaseValue($phpArray, AbstractPlatform $platform): ?
/**
* Tests if given PHP array item is from compatible type for PostgreSQL.
*/
protected function isValidArrayItemForDatabase(mixed $item): bool
public function isValidArrayItemForDatabase(mixed $item): bool
{
return true;
}
Expand All @@ -76,6 +77,7 @@ public function convertToPHPValue($postgresArray, AbstractPlatform $platform): ?
if ($postgresArray === null) {
return null;
}

if (!\is_string($postgresArray)) {
$exceptionMessage = 'Given PostgreSQL value content type is not PHP string. Instead it is "%s".';

Expand Down Expand Up @@ -105,7 +107,7 @@ protected function transformPostgresArrayToPHPArray(string $postgresArray): arra
*
* @return mixed
*/
protected function transformArrayItemForPHP(mixed $item)
public function transformArrayItemForPHP(mixed $item)
{
return $item;
}
Expand Down
2 changes: 2 additions & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public function isValidArrayItemForDatabase($item): bool
if (!\is_int($item) && !\is_string($item)) {
return false;
}

if (!(bool) \preg_match('/^-?\d+$/', (string) $item)) {
return false;
}

if ((string) $item < $this->getMinValue()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/JsonTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function transformToPostgresJson(mixed $phpValue): string
try {
$postgresValue = \json_encode($phpValue, JSON_THROW_ON_ERROR);
} catch (\JsonException) {
throw new ConversionException(\sprintf('Value %s can\'t be resolved to valid JSON', \var_export($phpValue, true)));
throw new ConversionException(\sprintf("Value %s can't be resolved to valid JSON", \var_export($phpValue, true)));
}

return $postgresValue;
Expand Down
1 change: 1 addition & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function transformPostgresArrayToPHPArray(string $postgresArray): arra
if ($postgresArray === '{}') {
return [];
}

$trimmedPostgresArray = \mb_substr($postgresArray, 2, -2);
$phpArray = \explode('},{', $trimmedPostgresArray);
foreach ($phpArray as &$item) {
Expand Down
1 change: 1 addition & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/TextArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function transformToPostgresTextArray(array $phpTextArray): string
if (!\is_array($phpTextArray)) {
throw new \InvalidArgumentException(\sprintf('Value %s is not an array', \var_export($phpTextArray, true)));
}

if ($phpTextArray === []) {
return '{}';
}
Expand Down
Loading