diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..ad291a1 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,27 @@ +on: [ pull_request ] +name: Static analysis + +jobs: + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + coverage: none + tools: cs2pr + + - name: Download dependencies + uses: ramsey/composer-install@v2 + + - name: Display PHP-CS-Fixer version + run: sleep 1 && ./vendor/bin/php-cs-fixer --version + + - name: PHP-CS-Fixer + run: ./vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..7522b6b --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/tests') +; + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'mb_str_functions' => true, + 'phpdoc_to_comment' => false, + 'phpdoc_separation' => false, + 'trailing_comma_in_multiline' => ['elements' => ['array_destructuring', 'arrays', 'match']], + 'nullable_type_declaration_for_default_null_value' => false, + ]) + ->setFinder($finder) +; diff --git a/composer.json b/composer.json index 5c183e2..5fa3bb4 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "byrokrat/id": "^2.1" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.95.2", "phpunit/phpunit": "^12.5", "symfony/validator": "^8.0", "vimeo/psalm": "^6.16" diff --git a/src/DependencyInjection/IdentityNumberValidatorExtension.php b/src/DependencyInjection/IdentityNumberValidatorExtension.php index b7058a8..d5c42b6 100644 --- a/src/DependencyInjection/IdentityNumberValidatorExtension.php +++ b/src/DependencyInjection/IdentityNumberValidatorExtension.php @@ -2,16 +2,13 @@ namespace JGI\IdentityNumberValidatorBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader; class IdentityNumberValidatorExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/src/Validator/Constraints/IdentityNumberValidator.php b/src/Validator/Constraints/IdentityNumberValidator.php index e6a6f45..e39ed9c 100644 --- a/src/Validator/Constraints/IdentityNumberValidator.php +++ b/src/Validator/Constraints/IdentityNumberValidator.php @@ -3,7 +3,6 @@ namespace JGI\IdentityNumberValidatorBundle\Validator\Constraints; use byrokrat\id\CoordinationIdFactory; -use byrokrat\id\Exception; use byrokrat\id\PersonalIdFactory; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -32,8 +31,9 @@ public function validate(mixed $value, Constraint $constraint): void : $constraint->message; if ($constraint->strict) { - if (!preg_match("/^\d{12}$/", $value) ) { + if (!preg_match("/^\d{12}$/", $value)) { $this->context->addViolation($message); + return; } } @@ -43,7 +43,8 @@ public function validate(mixed $value, Constraint $constraint): void $this->coordinationIdFactory->createId($value); return; - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } try { diff --git a/src/Validator/Constraints/OrganizationNumberValidator.php b/src/Validator/Constraints/OrganizationNumberValidator.php index 8eca46f..2b85a06 100644 --- a/src/Validator/Constraints/OrganizationNumberValidator.php +++ b/src/Validator/Constraints/OrganizationNumberValidator.php @@ -4,7 +4,6 @@ use byrokrat\id\CoordinationIdFactory; use byrokrat\id\OrganizationIdFactory; -use byrokrat\id\Exception; use byrokrat\id\PersonalIdFactory; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -30,8 +29,9 @@ public function validate($value, Constraint $constraint): void } if ($constraint->strict) { - if (!preg_match("/^\d{10}$/", $value) ) { + if (!preg_match("/^\d{10}$/", $value)) { $this->context->addViolation($constraint->message); + return; } } @@ -44,7 +44,8 @@ public function validate($value, Constraint $constraint): void $this->personalIdFactory->createId($value); return; - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } if ($constraint->allowCoordinationNumber) { @@ -55,7 +56,8 @@ public function validate($value, Constraint $constraint): void $this->coordinationIdFactory->createId($value); return; - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } try { diff --git a/tests/Validator/Constraints/IdentityNumberValidatorTest.php b/tests/Validator/Constraints/IdentityNumberValidatorTest.php index 4c6e124..9de32af 100644 --- a/tests/Validator/Constraints/IdentityNumberValidatorTest.php +++ b/tests/Validator/Constraints/IdentityNumberValidatorTest.php @@ -3,13 +3,13 @@ namespace JGI\IdentityNumberValidatorBundle\Tests\Validator\Constraints; use byrokrat\id\CoordinationIdFactory; +use byrokrat\id\Exception; use byrokrat\id\PersonalIdFactory; use JGI\IdentityNumberValidatorBundle\Validator\Constraints\IdentityNumber; use JGI\IdentityNumberValidatorBundle\Validator\Constraints\IdentityNumberValidator; use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -use byrokrat\id\Exception; class IdentityNumberValidatorTest extends ConstraintValidatorTestCase { diff --git a/tests/Validator/Constraints/OrganizationNumberValidatorTest.php b/tests/Validator/Constraints/OrganizationNumberValidatorTest.php index 0366e03..947e3ab 100644 --- a/tests/Validator/Constraints/OrganizationNumberValidatorTest.php +++ b/tests/Validator/Constraints/OrganizationNumberValidatorTest.php @@ -2,13 +2,13 @@ namespace JGI\IdentityNumberValidatorBundle\Tests\Validator\Constraints; +use byrokrat\id\Exception; use byrokrat\id\OrganizationIdFactory; use JGI\IdentityNumberValidatorBundle\Validator\Constraints\OrganizationNumber; use JGI\IdentityNumberValidatorBundle\Validator\Constraints\OrganizationNumberValidator; use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -use byrokrat\id\Exception; class OrganizationNumberValidatorTest extends ConstraintValidatorTestCase {