Skip to content
Closed
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
14 changes: 14 additions & 0 deletions src/Rules/Doctrine/ORM/EntityColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@
$enumReflection->getDisplayName(),
$writableToDatabaseType->describe(VerbosityLevel::typeOnly()),
))->identifier('doctrine.enumType')->build();
} elseif ($backedEnumType->isString()->yes()) {
$databaseLength = $fieldMapping['length'] ?? 255;
$cases = $enumTypeString::cases();
$maxLength = max(array_map(fn ($case): int => strlen($case->value), $cases) ?: [0]);

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Parameter #1 $string of function strlen expects string, int|string given.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 126 in src/Rules/Doctrine/ORM/EntityColumnRule.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2)

Parameter #1 $string of function strlen expects string, int|string given.
if ($maxLength > $databaseLength) {
$errors[] = RuleErrorBuilder::message(sprintf(
'Property %s::$%s length mismatch: maximum value length %s for enum %s exceeds database column length %s.',
$className,
$propertyName,
$maxLength,
$enumReflection->getDisplayName(),
$databaseLength,
))->identifier('doctrine.enumStringLength')->build();
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ public function testEnumType(?string $objectManagerLoader): void
'Property PHPStan\Rules\Doctrine\ORMAttributes\Foo::$type7 type mapping mismatch: backing type int of enum PHPStan\Rules\Doctrine\ORMAttributes\BazEnum does not match value type string of the database type array<string>.',
63,
],
[
'Property PHPStan\Rules\Doctrine\ORMAttributes\Foo::$type8 length mismatch: maximum value length 3 for enum PHPStan\Rules\Doctrine\ORMAttributes\FooEnum exceeds database column length 1.',
66,
]
]);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Rules/Doctrine/ORM/data-attributes/enum-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ class Foo
*/
#[ORM\Column(type: "simple_array", enumType: BazEnum::class)]
public array $type7;

#[ORM\Column(type: "string", length: 1, enumType: FooEnum::class)]
public FooEnum $type8;

#[ORM\Column(type: "string", length: 3, enumType: FooEnum::class)]
public FooEnum $type9;
}
Loading