Skip to content

Update phpstan to v2 #42

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

Merged
merged 1 commit into from
Dec 30, 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
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"lock": false
},
"require": {
"php": ">=8.1",
Expand All @@ -25,10 +26,10 @@
"squizlabs/php_codesniffer": "^3.6",
"phpmd/phpmd": "^2.14",
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpstan/extension-installer": "^1.3"
},
"autoload": {
Expand All @@ -42,6 +43,8 @@
}
},
"scripts": {
"baseline": ["@baseline:phpstan"],
"baseline:phpstan": "phpstan --generate-baseline",
"check": ["@check:phpstan", "@check:phpmd", "@check:phpcs"],
"check:phpstan": "phpstan analyse",
"check:phpmd": "phpmd src,tests text phpmd.xml.dist --suffixes php",
Expand Down
7 changes: 4 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$configs \\(array\\<string\\>\\) of method DigitalRevolution\\\\SymfonyRequestValidation\\\\DependencyInjection\\\\RequestValidationExtension\\:\\:load\\(\\) should be contravariant with parameter \\$configs \\(array\\) of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\ExtensionInterface\\:\\:load\\(\\)$#"
count: 2
path: src/DependencyInjection/RequestValidationExtension.php
message: '#^Method DigitalRevolution\\SymfonyRequestValidation\\AbstractValidatedRequest\:\:validateCustomRules\(\) has Symfony\\Component\\HttpFoundation\\Exception\\BadRequestException in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/AbstractValidatedRequest.php
10 changes: 7 additions & 3 deletions src/Constraint/RequestConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

class RequestConstraint extends Constraint
{
public const WRONG_VALUE_TYPE = '08937cc5-9ea6-460c-9917-d3f6ba912998';
public const MISSING_QUERY_CONSTRAINT = 'b62ab5ca-ee6f-4baf-bdef-ffbe14f674d6';
/** @var string */
public const MISSING_QUERY_CONSTRAINT = 'b62ab5ca-ee6f-4baf-bdef-ffbe14f674d6';
/** @var string */
public const MISSING_REQUEST_CONSTRAINT = 'c3990dad-3638-449b-9dd3-4dd42e90c52f';
public const INVALID_BODY_CONTENT = '3b41f393-5f46-471e-8a2e-c4035d5fb3cb';
/** @var string */
public const INVALID_BODY_CONTENT = '3b41f393-5f46-471e-8a2e-c4035d5fb3cb';
/** @var string */
public const WRONG_VALUE_TYPE = '08937cc5-9ea6-460c-9917-d3f6ba912998';

/** @var array<string, string> */
protected const ERROR_NAMES = [
Expand Down
11 changes: 5 additions & 6 deletions src/Constraint/RequestConstraintFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ public function __construct(ConstraintFactory $factory = null)
*/
public function createConstraint(ValidationRules $validationRules): RequestConstraint
{
$options = [];
foreach ($validationRules->getDefinitions() as $key => $definitions) {
$options[$key] = $this->factory->fromRuleDefinitions($definitions, $validationRules->getAllowExtraFields());
}

/**
* @var array{
* query?: Constraint|Constraint[],
* request?: Constraint|Constraint[],
* attributes?: Constraint|Constraint[],
* allowExtraFields: bool
* } $options
*/
$options = [];
foreach ($validationRules->getDefinitions() as $key => $definitions) {
$options[$key] = $this->factory->fromRuleDefinitions($definitions, $validationRules->getAllowExtraFields());
}

// Set extra constraint options
$options['allowExtraFields'] = $validationRules->getAllowExtraFields();

Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/RequestValidationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public function __construct(?FileLocatorInterface $fileLocator = null)
/**
* @inheritDoc
*
* @param string[] $configs
*
* @throws Exception
*/
public function load(array $configs, ContainerBuilder $container): void
Expand Down
Loading