Skip to content

Commit

Permalink
Drop PHP7.4 & rework CI
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Nov 29, 2023
1 parent 89e2996 commit a1e9534
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
composer-options: "--working-dir=tools/php-cs-fixer"

- name: PHP-CS-Fixer
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist.php
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php
31 changes: 21 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ jobs:
strategy:
matrix:
include:
- php: '8.0'
# Lowest Deps
- php: 8.0
symfony-require: 5.4.*
- php: '8.0'
symfony-require: 6.3.*
- php: '8.2'
composer-flags: '--prefer-stable --prefer-lowest'
# LTS with latest stable PHP
- php: 8.2
symfony-require: 6.4.*
composer-flags: '--prefer-stable'
# Active release
- php: 8.3
symfony-require: 7.0.*
composer-flags: '--prefer-stable --ignore-platform-req=php+'
# Development release
- php: nightly
symfony-require: 7.1.*@dev
composer-flags: '--ignore-platform-req=php+'
stability: dev
- php: '8.1'
can-fail: true
fail-fast: false

steps:
Expand All @@ -30,7 +40,8 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
php-version: ${{ matrix.php }}
extensions: intl-74.1
coverage: none

- name: Configure Composer minimum stability
Expand All @@ -39,8 +50,8 @@ jobs:

- name: Install dependencies
env:
SYMFONY_REQUIRE: "${{ matrix.symfony-require }}"
run: composer update --prefer-dist
SYMFONY_REQUIRE: ${{ matrix.symfony-require }}
run: composer update ${{ matrix.composer-flags }} --no-interaction --no-progress --optimize-autoloader

- name: "Run PHPUnit"
run: "vendor/bin/phpunit"
- name: Run PHPUnit
run: vendor/bin/phpunit
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/.phpunit.result.cache
/composer.lock
/composer.phar
/phpunit.xml
/tools/*/composer.lock
/tools/*/vendor
/vendor/
File renamed without changes.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed

- Remove support of Symfony 4.x, 5.3 & < 6.3
- Add support for Symfony 7
- Remove support of PHP 7.4

## [3.9.3] - 2023-11-29

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sort-packages": true
},
"require": {
"php": ">=7.4",
"php": ">=8.0",
"giggsey/libphonenumber-for-php": "^8.0",
"symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0",
"symfony/intl": "^5.4 || ^6.3 || ^7.0",
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true">

<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<env name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=67&amp;max[self]=3" />
</php>

<testsuites>
<testsuite name="MisdPhoneNumberBundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
20 changes: 0 additions & 20 deletions phpunit.xml.dist

This file was deleted.

4 changes: 1 addition & 3 deletions src/Doctrine/DBAL/Types/PhoneNumberType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
throw new ConversionException('Expected \libphonenumber\PhoneNumber, got '.\gettype($value));
}

$util = PhoneNumberUtil::getInstance();

return $util->format($value, PhoneNumberFormat::E164);
return PhoneNumberUtil::getInstance()->format($value, PhoneNumberFormat::E164);
}

public function convertToPHPValue($value, AbstractPlatform $platform): ?PhoneNumber
Expand Down
16 changes: 9 additions & 7 deletions src/Form/DataTransformer/PhoneNumberToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ public function __construct(array $countryChoices)
$this->countryChoices = $countryChoices;
}

public function transform($phoneNumber): array
public function transform($value): array
{
if (null === $phoneNumber) {
if (null === $value) {
return ['country' => '', 'number' => ''];
} elseif (false === $phoneNumber instanceof PhoneNumber) {
}

if (false === $value instanceof PhoneNumber) {
throw new TransformationFailedException('Expected a \libphonenumber\PhoneNumber.');
}

$util = PhoneNumberUtil::getInstance();

if (false === \in_array($util->getRegionCodeForNumber($phoneNumber), $this->countryChoices)) {
if (false === \in_array($util->getRegionCodeForNumber($value), $this->countryChoices)) {
throw new TransformationFailedException('Invalid country.');
}

return [
'country' => $util->getRegionCodeForNumber($phoneNumber),
'number' => $util->format($phoneNumber, PhoneNumberFormat::NATIONAL),
'country' => $util->getRegionCodeForNumber($value),
'number' => $util->format($value, PhoneNumberFormat::NATIONAL),
];
}

Expand All @@ -78,7 +80,7 @@ public function reverseTransform($value): ?PhoneNumber
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}

if (false === \in_array($util->getRegionCodeForNumber($phoneNumber), $this->countryChoices)) {
if (null !== $phoneNumber && false === \in_array($util->getRegionCodeForNumber($phoneNumber), $this->countryChoices)) {
throw new TransformationFailedException('Invalid country.');
}

Expand Down
20 changes: 10 additions & 10 deletions src/Form/DataTransformer/PhoneNumberToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,33 @@ public function __construct(
$this->format = $format;
}

public function transform($phoneNumber): string
public function transform($value): string
{
if (null === $phoneNumber) {
if (null === $value) {
return '';
} elseif (false === $phoneNumber instanceof PhoneNumber) {
}

if (false === $value instanceof PhoneNumber) {
throw new TransformationFailedException('Expected a \libphonenumber\PhoneNumber.');
}

$util = PhoneNumberUtil::getInstance();

if (PhoneNumberFormat::NATIONAL === $this->format) {
return $util->formatOutOfCountryCallingNumber($phoneNumber, $this->defaultRegion);
return $util->formatOutOfCountryCallingNumber($value, $this->defaultRegion);
}

return $util->format($phoneNumber, $this->format);
return $util->format($value, $this->format);
}

public function reverseTransform($string): ?PhoneNumber
public function reverseTransform($value): ?PhoneNumber
{
if (!$string && '0' !== $string) {
if (!$value && '0' !== $value) {
return null;
}

$util = PhoneNumberUtil::getInstance();

try {
return $util->parse($string, $this->defaultRegion);
return PhoneNumberUtil::getInstance()->parse($value, $this->defaultRegion);
} catch (NumberParseException $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/Normalizer/PhoneNumberNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function supportsNormalization($data, $format = null, array $context = []
/**
* @throws UnexpectedValueException
*/
public function denormalize($data, $class, $format = null, array $context = []): ?PhoneNumber
public function denormalize($data, $type, $format = null, array $context = []): ?PhoneNumber
{
if (null === $data) {
return null;
Expand Down
21 changes: 2 additions & 19 deletions src/Templating/Helper/PhoneNumberHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,7 @@ public function __construct(PhoneNumberUtil $phoneNumberUtil)
$this->phoneNumberUtil = $phoneNumberUtil;
}

/**
* Format a phone number.
*
* @param PhoneNumber|string $phoneNumber phone number
* @param int|string $format format, or format constant name
*
* @return string formatted phone number
*
* @throws InvalidArgumentException if an argument is invalid
*/
public function format($phoneNumber, $format = PhoneNumberFormat::INTERNATIONAL): string
public function format(PhoneNumber|string $phoneNumber, string|int $format = PhoneNumberFormat::INTERNATIONAL): string
{
$phoneNumber = $this->getPhoneNumber($phoneNumber);

Expand Down Expand Up @@ -102,14 +92,7 @@ public function isType($phoneNumber, $type = PhoneNumberType::UNKNOWN): bool
return $this->phoneNumberUtil->getNumberType($phoneNumber) === $type;
}

/**
* @param PhoneNumber|string $phoneNumber
*
* @return PhoneNumber|void
*
* @throws \libphonenumber\NumberParseException
*/
private function getPhoneNumber($phoneNumber)
private function getPhoneNumber(PhoneNumber|string $phoneNumber): PhoneNumber
{
if (\is_string($phoneNumber)) {
$phoneNumber = $this->phoneNumberUtil->parse($phoneNumber);
Expand Down
13 changes: 9 additions & 4 deletions src/Validator/Constraints/PhoneNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as PhoneNumberConstraint;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
Expand Down Expand Up @@ -59,6 +60,10 @@ public function __construct(PhoneNumberUtil $phoneUtil = null, string $defaultRe

public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof PhoneNumberConstraint) {
return;
}

if (null === $value || '' === $value) {
return;
}
Expand Down Expand Up @@ -137,7 +142,7 @@ public function validate($value, Constraint $constraint): void
}
}

private function getRegion(Constraint $constraint): ?string
private function getRegion(PhoneNumberConstraint $constraint): ?string
{
$defaultRegion = null;
if (null !== $path = $constraint->regionPath) {
Expand Down Expand Up @@ -176,10 +181,10 @@ private function getPropertyAccessor(): PropertyAccessorInterface
/**
* Add a violation.
*
* @param mixed $value the value that should be validated
* @param Constraint $constraint the constraint for the validation
* @param mixed $value the value that should be validated
* @param PhoneNumberConstraint $constraint the constraint for the validation
*/
private function addViolation($value, Constraint $constraint): void
private function addViolation($value, PhoneNumberConstraint $constraint): void
{
$this->context->buildViolation($constraint->getMessage())
->setParameter('{{ types }}', implode(', ', $constraint->getTypeNames()))
Expand Down
9 changes: 0 additions & 9 deletions tests/Templating/Helper/PhoneNumberHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ public function testFormatAcceptString()
$this->assertEquals('+371 22 222 222', $result);
}

public function testFormatAcceptNotAllowValue()
{
$phoneNumberUtil = PhoneNumberUtil::getInstance();
$helper = new PhoneNumberHelper($phoneNumberUtil);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The phone number supplied is not PhoneNumber or string.');
$helper->format(0037122222222);
}

public function formatOutOfCountryCallingNumberAcceptString()
{
$phoneNumberUtil = PhoneNumberUtil::getInstance();
Expand Down

0 comments on commit a1e9534

Please sign in to comment.