Skip to content
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
27 changes: 27 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
->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)
;
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/DependencyInjection/IdentityNumberValidatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
7 changes: 4 additions & 3 deletions src/Validator/Constraints/IdentityNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -43,7 +43,8 @@ public function validate(mixed $value, Constraint $constraint): void
$this->coordinationIdFactory->createId($value);

return;
} catch (\Exception $e) {}
} catch (\Exception $e) {
}
}

try {
Expand Down
10 changes: 6 additions & 4 deletions src/Validator/Constraints/OrganizationNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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) {
Expand All @@ -55,7 +56,8 @@ public function validate($value, Constraint $constraint): void
$this->coordinationIdFactory->createId($value);

return;
} catch (\Exception $e) {}
} catch (\Exception $e) {
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading