Skip to content

Commit

Permalink
Revert "Bleeding edge - ParamAttributesRule - promoted property attri…
Browse files Browse the repository at this point in the history
…bute needs to target both parameters and properties"

This reverts commit 25d1552.
  • Loading branch information
ondrejmirtes committed Jan 5, 2024
1 parent 6c92190 commit 02f66df
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 73 deletions.
1 change: 0 additions & 1 deletion conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ parameters:
missingMagicSerializationRule: true
nullContextForVoidReturningFunctions: true
unescapeStrings: true
promotedPropertyAttribute: true
alwaysCheckTooWideReturnTypeFinalMethods: true
duplicateStubs: true
logicalXor: true
Expand Down
8 changes: 1 addition & 7 deletions conf/config.level0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rules:
- PHPStan\Rules\Functions\FunctionAttributesRule
- PHPStan\Rules\Functions\InnerFunctionRule
- PHPStan\Rules\Functions\InvalidLexicalVariablesInClosureUseRule
- PHPStan\Rules\Functions\ParamAttributesRule
- PHPStan\Rules\Functions\PrintfParametersRule
- PHPStan\Rules\Functions\RedefinedParametersRule
- PHPStan\Rules\Functions\ReturnNullsafeByRefRule
Expand Down Expand Up @@ -152,13 +153,6 @@ services:
arguments:
checkFunctionNameCase: %checkFunctionNameCase%

-
class: PHPStan\Rules\Functions\ParamAttributesRule
tags:
- phpstan.rules.rule
arguments:
checkPromotedPropertyAttribute: %featureToggles.promotedPropertyAttribute%

-
class: PHPStan\Rules\Constants\OverridingConstantRule
arguments:
Expand Down
1 change: 0 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ parameters:
missingMagicSerializationRule: false
nullContextForVoidReturningFunctions: false
unescapeStrings: false
promotedPropertyAttribute: false
alwaysCheckTooWideReturnTypeFinalMethods: false
duplicateStubs: false
logicalXor: false
Expand Down
1 change: 0 additions & 1 deletion conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ parametersSchema:
missingMagicSerializationRule: bool()
nullContextForVoidReturningFunctions: bool()
unescapeStrings: bool()
promotedPropertyAttribute: bool()
alwaysCheckTooWideReturnTypeFinalMethods: bool()
duplicateStubs: bool()
logicalXor: bool()
Expand Down
33 changes: 10 additions & 23 deletions src/Rules/Functions/ParamAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class ParamAttributesRule implements Rule
{

public function __construct(private AttributesCheck $attributesCheck, private bool $checkPromotedPropertyAttribute)
public function __construct(private AttributesCheck $attributesCheck)
{
}

Expand All @@ -28,30 +28,17 @@ public function processNode(Node $node, Scope $scope): array
{
$targetName = 'parameter';
if ($node->flags !== 0) {
if ($this->checkPromotedPropertyAttribute) {
$propertyTargetErrors = $this->attributesCheck->check(
$scope,
$node->attrGroups,
Attribute::TARGET_PROPERTY,
'property',
);
$targetName = 'parameter or property';

if (count($propertyTargetErrors) > 0) {
return $propertyTargetErrors;
}
} else {
$targetName = 'parameter or property';
$propertyTargetErrors = $this->attributesCheck->check(
$scope,
$node->attrGroups,
Attribute::TARGET_PROPERTY,
$targetName,
);

$propertyTargetErrors = $this->attributesCheck->check(
$scope,
$node->attrGroups,
Attribute::TARGET_PROPERTY,
$targetName,
);

if (count($propertyTargetErrors) === 0) {
return $propertyTargetErrors;
}
if (count($propertyTargetErrors) === 0) {
return $propertyTargetErrors;
}
}

Expand Down
40 changes: 0 additions & 40 deletions tests/PHPStan/Rules/Functions/ParamAttributesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
class ParamAttributesRuleTest extends RuleTestCase
{

private bool $checkPromotedPropertyAttribute;

protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
Expand All @@ -42,13 +40,11 @@ protected function getRule(): Rule
new ClassCaseSensitivityCheck($reflectionProvider, false),
true,
),
$this->checkPromotedPropertyAttribute,
);
}

public function testRule(): void
{
$this->checkPromotedPropertyAttribute = false;
$this->analyse([__DIR__ . '/data/param-attributes.php'], [
[
'Attribute class ParamAttributes\Foo does not have the parameter target.',
Expand All @@ -65,44 +61,8 @@ public function testRule(): void
]);
}

public function testRuleCheckPromotedPropertyAttribute(): void
{
$this->checkPromotedPropertyAttribute = true;
$this->analyse([__DIR__ . '/data/param-attributes.php'], [
[
'Attribute class ParamAttributes\Foo does not have the parameter target.',
33,
],
[
'Attribute class ParamAttributes\Foo does not have the property target.',
72,
],
[
'Attribute class ParamAttributes\Bar does not have the property target.',
74,
],
[
'Attribute class ParamAttributes\Qux does not have the parameter target.',
76,
],
[
'Attribute class ParamAttributes\Qux does not have the parameter target.',
78,
],
[
'Attribute class ParamAttributes\Qux does not have the parameter target.',
80,
],
[
'Attribute class ParamAttributes\Qux does not have the parameter target.',
82,
],
]);
}

public function testSensitiveParameterAttribute(): void
{
$this->checkPromotedPropertyAttribute = false;
$this->analyse([__DIR__ . '/data/sensitive-parameter.php'], []);
}

Expand Down

0 comments on commit 02f66df

Please sign in to comment.