Skip to content
Open
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
5 changes: 2 additions & 3 deletions src/Rules/Doctrine/ORM/EntityColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use PHPStan\Type\TypehintHelper;
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use Throwable;
use function count;
Expand Down Expand Up @@ -173,8 +172,8 @@ public function processNode(Node $node, Scope $scope): array
}

if (count($enumTypes) > 0) {
$writableToPropertyType = new UnionType($enumTypes);
$writableToDatabaseType = new UnionType($enumTypes);
$writableToPropertyType = TypeCombinator::union(...$enumTypes);
$writableToDatabaseType = TypeCombinator::union(...$enumTypes);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,21 @@ public function testBug679(?string $objectManagerLoader): void
$this->analyse([__DIR__ . '/data/bug-679.php'], []);
}

/**
* @dataProvider dataObjectManagerLoader
*/
public function testBugSingleEnum(?string $objectManagerLoader): void
{
if (PHP_VERSION_ID < 80100) {
self::markTestSkipped('Test requires PHP 8.1');
}
if (!class_exists(\Doctrine\DBAL\Types\EnumType::class)) {
self::markTestSkipped('Test requires EnumType.');
}

$this->allowNullablePropertyForRequiredField = false;
$this->objectManagerLoader = $objectManagerLoader;
$this->analyse([__DIR__ . '/data/bug-single-enum.php'], []);
}

}
29 changes: 29 additions & 0 deletions tests/Rules/Doctrine/ORM/data/bug-single-enum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php // lint >= 8.1

namespace PHPStan\Rules\Doctrine\ORM\BugSingleEnum;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class MyBrokenEntity
{
public const LOGIN_METHOD_BASIC_AUTH = 'BasicAuth';

public const LOGIN_METHODS = [
self::LOGIN_METHOD_BASIC_AUTH,
];

/**
* @var int|null
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;

/**
* @var self::LOGIN_METHOD_*
*/
#[ORM\Column(name: 'login_method', type: 'enum', options: ['default' => self::LOGIN_METHOD_BASIC_AUTH, 'values' => self::LOGIN_METHODS])]
private string $loginMethod = self::LOGIN_METHOD_BASIC_AUTH;
}
Loading