Open
Show file tree
Hide file tree
Changes from 2 commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ includes:
- phpstan-baseline.neon
- phpstan-baseline-deprecations.neon
- phpstan-baseline-dbal-3.neon
- phpstan-baseline-dbal-4.neon
- compatibility/orm-3-baseline.php
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
namespace PHPStan\Type\Doctrine\Query;

use BackedEnum;
use Doctrine\DBAL\Types\EnumType as DbalEnumType;
use Doctrine\DBAL\Types\StringType as DbalStringType;
use Doctrine\DBAL\Types\Type as DbalType;
use Doctrine\ORM\EntityManagerInterface;
Expand DownExpand Up@@ -1235,6 +1236,7 @@ public function walkSelectExpression($selectExpression): string
if (
$expr instanceof TypedExpression
&& !$expr->getReturnType() instanceof DbalStringType // StringType is no-op, so using TypedExpression with that does nothing
&& !$expr->getReturnType() instanceof DbalEnumType // EnumType is also no-op
) {
$dbalTypeName = DbalType::getTypeRegistry()->lookupName($expr->getReturnType());
$type = TypeCombinator::intersect( // e.g. count is typed as int, but we infer int<0, max>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\VerbosityLevel;
use QueryResult\Entities\Dbal4Entity;
use QueryResult\Entities\Embedded;
use QueryResult\Entities\JoinedChild;
use QueryResult\Entities\Many;
Expand DownExpand Up@@ -187,6 +188,15 @@ public static function setUpBeforeClass(): void
$em->persist($entityWithEnum);
}

if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=4.2')) {
assert(class_exists(Dbal4Entity::class));

$dbal4Entity = new Dbal4Entity();
$dbal4Entity->enum = 'a';
$dbal4Entity->smallfloat = 1.1;
$em->persist($dbal4Entity);
}

$em->flush();
}

Expand DownExpand Up@@ -1532,6 +1542,25 @@ private function yieldConditionalDataset(): iterable
];
}

if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=4.2')) {
yield 'enum and smallfloat' => [
$this->constantArray([
[
new ConstantStringType('enum'),
new StringType(),
],
[
new ConstantStringType('smallfloat'),
new FloatType(),
],
]),
'
SELECT e.enum, e.smallfloat
FROM QueryResult\Entities\Dbal4Entity e
',
];
}

$ormVersion = InstalledVersions::getVersion('doctrine/orm');
$hasOrm3 = $ormVersion !== null && strpos($ormVersion, '3.') === 0;

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);

namespace QueryResult\Entities;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;

/**
* @Entity
*/
class Dbal4Entity
{

/**
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
* @Id()
*
* @var int
*/
public $id;

/**
* @Column(type="enum", options={"values"={"a", "b", "c"}})
* @var string
*/
public $enum; // dbal 4.2+

/**
* @Column(type="smallfloat")
* @var float
*/
public $smallfloat; // dbal 4.1+
}
Loading