Skip to content

Commit 6844090

Browse files
author
Florian Guimier
committed
Update
1 parent eada048 commit 6844090

36 files changed

Lines changed: 87 additions & 59 deletions

src/Validator/Constraints/EntityValidator.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
99
use Doctrine\ORM\EntityManagerInterface;
1010
use Doctrine\ORM\Mapping\ClassMetadataInfo;
11+
use Doctrine\ORM\Mapping\FieldMapping;
1112
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
1213
use Symfony\Component\PropertyAccess\PropertyAccess;
1314
use Symfony\Component\Validator\Constraint;
@@ -79,13 +80,12 @@ public function validate(mixed $entity, Constraint $constraint): void
7980
}
8081

8182
/**
82-
* @param FieldMapping $fieldMapping
8383
* @return Constraint[]
8484
*/
85-
public function getConstraintsForType(array $fieldMapping): array
85+
public function getConstraintsForType(FieldMapping $fieldMapping): array
8686
{
8787
foreach ($this->fieldConstraintsSetFactories as $fieldConstraintsSetProvider) {
88-
if ($fieldConstraintsSetProvider->supports($fieldMapping['type'])) {
88+
if ($fieldConstraintsSetProvider->supports($fieldMapping->type)) {
8989
return $fieldConstraintsSetProvider->getConstraints($fieldMapping);
9090
}
9191
}
@@ -105,9 +105,7 @@ public function getConstraints(string $class, string $field): array
105105
if (array_key_exists($field, $metadata->fieldMappings)) {
106106
$fieldMapping = $metadata->fieldMappings[$field];
107107

108-
// Nullable field
109-
Assert::keyExists($fieldMapping, 'nullable');
110-
if (true !== $fieldMapping['nullable']) {
108+
if (true !== $fieldMapping->nullable) {
111109
$constraints[] = [new NotNull()];
112110
}
113111

src/Validator/ConstraintsSetProvider/Field/AbsolutePercentValueProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use AssoConnect\AbsolutePercentValueBundle\Object\AbsolutePercentValue;
88
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\AbsolutePercentValueType;
9+
use Doctrine\ORM\Mapping\FieldMapping;
910
use Symfony\Component\Validator\Constraints\Type;
1011

1112
class AbsolutePercentValueProvider implements FieldConstraintsSetProviderInterface
@@ -15,7 +16,7 @@ public function supports(string $type): bool
1516
return AbsolutePercentValueType::NAME === $type;
1617
}
1718

18-
public function getConstraints(array $fieldMapping): array
19+
public function getConstraints(FieldMapping $fieldMapping): array
1920
{
2021
return [
2122
new Type(AbsolutePercentValue::class),

src/Validator/ConstraintsSetProvider/Field/AmountProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\AmountAsBigintType;
88
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\AmountType;
9+
use Doctrine\ORM\Mapping\FieldMapping;
910
use Money\Money as MoneyObject;
1011
use Symfony\Component\Validator\Constraints\Type;
1112

@@ -16,7 +17,7 @@ public function supports(string $type): bool
1617
return AmountType::NAME === $type || AmountAsBigintType::NAME === $type;
1718
}
1819

19-
public function getConstraints(array $fieldMapping): array
20+
public function getConstraints(FieldMapping $fieldMapping): array
2021
{
2122
return [
2223
new Type(MoneyObject::class),

src/Validator/ConstraintsSetProvider/Field/ArrayProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field;
66

77
use Doctrine\DBAL\Types\Types;
8+
use Doctrine\ORM\Mapping\FieldMapping;
89
use Symfony\Component\Validator\Constraints\Type;
910

1011
class ArrayProvider implements FieldConstraintsSetProviderInterface
@@ -14,7 +15,7 @@ public function supports(string $type): bool
1415
return Types::ARRAY === $type || 'simple_array' === $type;
1516
}
1617

17-
public function getConstraints(array $fieldMapping): array
18+
public function getConstraints(FieldMapping $fieldMapping): array
1819
{
1920
return [
2021
new Type('array'),

src/Validator/ConstraintsSetProvider/Field/BicProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field;
66

77
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\BicType;
8+
use Doctrine\ORM\Mapping\FieldMapping;
89
use Symfony\Component\Validator\Constraints\Bic;
910
use Symfony\Component\Validator\Constraints\Regex;
1011

@@ -15,7 +16,7 @@ public function supports(string $type): bool
1516
return BicType::NAME === $type;
1617
}
1718

18-
public function getConstraints(array $fieldMapping): array
19+
public function getConstraints(FieldMapping $fieldMapping): array
1920
{
2021
return [
2122
new Bic(),

src/Validator/ConstraintsSetProvider/Field/BooleanProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field;
66

77
use Doctrine\DBAL\Types\Types;
8+
use Doctrine\ORM\Mapping\FieldMapping;
89
use Symfony\Component\Validator\Constraints\Type;
910

1011
class BooleanProvider implements FieldConstraintsSetProviderInterface
@@ -14,7 +15,7 @@ public function supports(string $type): bool
1415
return Types::BOOLEAN === $type;
1516
}
1617

17-
public function getConstraints(array $fieldMapping): array
18+
public function getConstraints(FieldMapping $fieldMapping): array
1819
{
1920
return [
2021
new Type('bool'),

src/Validator/ConstraintsSetProvider/Field/CountryProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field;
66

77
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\CountryType;
8+
use Doctrine\ORM\Mapping\FieldMapping;
89
use Symfony\Component\Validator\Constraints\Country;
910

1011
class CountryProvider implements FieldConstraintsSetProviderInterface
@@ -14,7 +15,7 @@ public function supports(string $type): bool
1415
return CountryType::NAME === $type;
1516
}
1617

17-
public function getConstraints(array $fieldMapping): array
18+
public function getConstraints(FieldMapping $fieldMapping): array
1819
{
1920
return [
2021
new Country(),

src/Validator/ConstraintsSetProvider/Field/CurrencyProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field;
66

77
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\CurrencyType;
8+
use Doctrine\ORM\Mapping\FieldMapping;
89
use Money\Currency as CurrencyObject;
910
use Symfony\Component\Validator\Constraints\Currency as CurrencyConstraint;
1011
use Symfony\Component\Validator\Constraints\Type;
@@ -16,7 +17,7 @@ public function supports(string $type): bool
1617
return CurrencyType::NAME === $type;
1718
}
1819

19-
public function getConstraints(array $fieldMapping): array
20+
public function getConstraints(FieldMapping $fieldMapping): array
2021
{
2122
return [
2223
new CurrencyConstraint(),

src/Validator/ConstraintsSetProvider/Field/DateTimeImmutableProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use AssoConnect\DoctrineTypesBundle\Doctrine\DBAL\Types\DateTimeImmutableMicroSecondsType;
88
use DateTimeImmutable;
99
use Doctrine\DBAL\Types\Types;
10+
use Doctrine\ORM\Mapping\FieldMapping;
1011
use Symfony\Component\Validator\Constraints\Type;
1112

1213
class DateTimeImmutableProvider implements FieldConstraintsSetProviderInterface
@@ -25,7 +26,7 @@ public function supports(string $type): bool
2526
);
2627
}
2728

28-
public function getConstraints(array $fieldMapping): array
29+
public function getConstraints(FieldMapping $fieldMapping): array
2930
{
3031
return [
3132
new Type(DateTimeImmutable::class),

src/Validator/ConstraintsSetProvider/Field/DateTimeProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DateTime;
88
use Doctrine\DBAL\Types\Types;
9+
use Doctrine\ORM\Mapping\FieldMapping;
910
use Symfony\Component\Validator\Constraints\Type;
1011

1112
class DateTimeProvider implements FieldConstraintsSetProviderInterface
@@ -24,7 +25,7 @@ public function supports(string $type): bool
2425
);
2526
}
2627

27-
public function getConstraints(array $fieldMapping): array
28+
public function getConstraints(FieldMapping $fieldMapping): array
2829
{
2930
return [
3031
new Type(DateTime::class),

0 commit comments

Comments
 (0)