Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding Style - CSFixer #172

Merged
merged 2 commits into from
Jun 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/Doctrine/DBAL/Types/PhoneNumberType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
{
// DBAL < 4
if (method_exists(AbstractPlatform::class, 'getVarcharTypeDeclarationSQL')) {
// @phpstan-ignore-next-line
Copy link
Collaborator

@Nek- Nek- Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxhelias , it would be better to add the specific error in the phpstan file or specify the exact error! (it's a best practice) see https://phpstan.org/user-guide/ignoring-errors

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know about this new feature. We'll edit next time.
Thanks

return $platform->getVarcharTypeDeclarationSQL(['length' => $column['length'] ?? 35]);
}

Expand Down Expand Up @@ -78,7 +79,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?PhoneNum
}

// DBAL 4
// @phpstan-ignore-next-line
throw InvalidType::new($value, self::NAME, ['null', 'string']);
}
}
Expand Down
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
31 changes: 17 additions & 14 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 All @@ -129,7 +132,7 @@ public function validate(mixed $value, Constraint $constraint): void
}
}

private function getRegion(PhoneNumberConstraint $constraint): ?string
private function getRegion(PhoneNumberConstraint $constraint): string
{
$defaultRegion = null;
if (null !== $path = $constraint->regionPath) {
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();
}
}
7 changes: 5 additions & 2 deletions tests/Doctrine/DBAL/Types/PhoneNumberTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PhoneNumberTypeTest extends TestCase
* @var ObjectProphecy<AbstractPlatform>
*/
private ObjectProphecy $platform;
private Type $type;
private PhoneNumberType $type;
private PhoneNumberUtil $phoneNumberUtil;

public static function setUpBeforeClass(): void
Expand All @@ -53,7 +53,10 @@ protected function setUp(): void
$this->platform->getStringTypeDeclarationSQL()->willReturn('DUMMYVARCHAR()');
}

$this->type = Type::getType('phone_number');
/** @var PhoneNumberType $type */
$type = Type::getType('phone_number');

$this->type = $type;
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
}

Expand Down
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
Loading