Skip to content

Commit

Permalink
Coding Style - CSFixer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Jun 5, 2024
1 parent 67ee847 commit d51b50f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/Serializer/Normalizer/PhoneNumberNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function __construct(PhoneNumberUtil $phoneNumberUtil, string $region = P
*
* @throws InvalidArgumentException
*/
public function normalize(mixed $object, string $format = null, array $context = []): string
public function normalize(mixed $object, ?string $format = null, array $context = []): string
{
return $this->phoneNumberUtil->format($object, $this->format);
}

/**
* @param array<mixed> $context
*/
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof PhoneNumber;
}
Expand All @@ -66,7 +66,7 @@ public function supportsNormalization(mixed $data, string $format = null, array
*
* @throws UnexpectedValueException
*/
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): ?PhoneNumber
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): ?PhoneNumber
{
if (null === $data) {
return null;
Expand All @@ -82,7 +82,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
/**
* @param array<mixed> $context
*/
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
return PhoneNumber::class === $type && \is_string($data);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Validator/Constraints/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ class PhoneNumber extends Constraint
* @param array<mixed> $options
*/
#[HasNamedArguments]
public function __construct(int $format = null, string|array $type = null, string $defaultRegion = null, string $regionPath = null, string $message = null, array $groups = null, $payload = null, array $options = [])
{
public function __construct(
?int $format = null,
string|array|null $type = null,
?string $defaultRegion = null,
?string $regionPath = null,
?string $message = null,
?array $groups = null,
$payload = null,
array $options = []
) {
parent::__construct($options, $groups, $payload);

$this->message = $message ?? $this->message;
Expand Down
29 changes: 16 additions & 13 deletions src/Validator/Constraints/PhoneNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class PhoneNumberValidator extends ConstraintValidator
private ?PropertyAccessorInterface $propertyAccessor = null;
private int $format;

public function __construct(PhoneNumberUtil $phoneUtil = null, string $defaultRegion = PhoneNumberUtil::UNKNOWN_REGION, int $format = PhoneNumberFormat::INTERNATIONAL)
{
public function __construct(
?PhoneNumberUtil $phoneUtil = null,
string $defaultRegion = PhoneNumberUtil::UNKNOWN_REGION,
int $format = PhoneNumberFormat::INTERNATIONAL
) {
$this->phoneUtil = $phoneUtil ?? PhoneNumberUtil::getInstance();
$this->defaultRegion = $defaultRegion;
$this->format = $format;
Expand Down Expand Up @@ -83,36 +86,36 @@ public function validate(mixed $value, Constraint $constraint): void
$validTypes = [];
foreach ($constraint->getTypes() as $type) {
switch ($type) {
case PhoneNumber::FIXED_LINE:
case PhoneNumberConstraint::FIXED_LINE:
$validTypes[] = PhoneNumberType::FIXED_LINE;
$validTypes[] = PhoneNumberType::FIXED_LINE_OR_MOBILE;
break;
case PhoneNumber::MOBILE:
case PhoneNumberConstraint::MOBILE:
$validTypes[] = PhoneNumberType::MOBILE;
$validTypes[] = PhoneNumberType::FIXED_LINE_OR_MOBILE;
break;
case PhoneNumber::PAGER:
case PhoneNumberConstraint::PAGER:
$validTypes[] = PhoneNumberType::PAGER;
break;
case PhoneNumber::PERSONAL_NUMBER:
case PhoneNumberConstraint::PERSONAL_NUMBER:
$validTypes[] = PhoneNumberType::PERSONAL_NUMBER;
break;
case PhoneNumber::PREMIUM_RATE:
case PhoneNumberConstraint::PREMIUM_RATE:
$validTypes[] = PhoneNumberType::PREMIUM_RATE;
break;
case PhoneNumber::SHARED_COST:
case PhoneNumberConstraint::SHARED_COST:
$validTypes[] = PhoneNumberType::SHARED_COST;
break;
case PhoneNumber::TOLL_FREE:
case PhoneNumberConstraint::TOLL_FREE:
$validTypes[] = PhoneNumberType::TOLL_FREE;
break;
case PhoneNumber::UAN:
case PhoneNumberConstraint::UAN:
$validTypes[] = PhoneNumberType::UAN;
break;
case PhoneNumber::VOIP:
case PhoneNumberConstraint::VOIP:
$validTypes[] = PhoneNumberType::VOIP;
break;
case PhoneNumber::VOICEMAIL:
case PhoneNumberConstraint::VOICEMAIL:
$validTypes[] = PhoneNumberType::VOICEMAIL;
break;
}
Expand Down Expand Up @@ -176,7 +179,7 @@ private function addViolation($value, PhoneNumberConstraint $constraint): void
$this->context->buildViolation($constraint->getMessage())
->setParameter('{{ types }}', implode(', ', $constraint->getTypeNames()))
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(PhoneNumber::INVALID_PHONE_NUMBER_ERROR)
->setCode(PhoneNumberConstraint::INVALID_PHONE_NUMBER_ERROR)
->addViolation();
}
}
8 changes: 4 additions & 4 deletions tests/Validator/Constraints/PhoneNumberValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ protected function setUp(): void
public function testValidate(
string|LibPhoneNumber|null $value,
bool $violates,
array|string $type = null,
string $defaultRegion = null,
string $regionPath = null,
int $format = null
array|string|null $type = null,
?string $defaultRegion = null,
?string $regionPath = null,
?int $format = null
): void {
$constraint = new PhoneNumber($format, $type, $defaultRegion, $regionPath);

Expand Down

0 comments on commit d51b50f

Please sign in to comment.