Skip to content

Commit 6026869

Browse files
committed
Only in bleeding edge
1 parent 4293f99 commit 6026869

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

conf/config.level4.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ rules:
88
- PHPStan\Rules\DeadCode\UnusedPrivateMethodRule
99
- PHPStan\Rules\Exceptions\OverwrittenExitPointByFinallyRule
1010
- PHPStan\Rules\Functions\CallToFunctionStatementWithoutSideEffectsRule
11-
- PHPStan\Rules\Methods\CallToConstructorStatementWithoutSideEffectsRule
1211
- PHPStan\Rules\Methods\CallToMethodStatementWithoutSideEffectsRule
1312
- PHPStan\Rules\Methods\CallToStaticMethodStatementWithoutSideEffectsRule
1413
- PHPStan\Rules\Methods\NullsafeMethodCallRule
@@ -217,6 +216,13 @@ services:
217216
tags:
218217
- phpstan.rules.rule
219218

219+
-
220+
class: PHPStan\Rules\Methods\CallToConstructorStatementWithoutSideEffectsRule
221+
arguments:
222+
reportNoConstructor: %featureToggles.pure%
223+
tags:
224+
- phpstan.rules.rule
225+
220226
-
221227
class: PHPStan\Rules\TooWideTypehints\TooWideMethodReturnTypehintRule
222228
arguments:

src/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRule.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
class CallToConstructorStatementWithoutSideEffectsRule implements Rule
1717
{
1818

19-
public function __construct(private ReflectionProvider $reflectionProvider)
19+
public function __construct(
20+
private ReflectionProvider $reflectionProvider,
21+
private bool $reportNoConstructor,
22+
)
2023
{
2124
}
2225

@@ -43,12 +46,16 @@ public function processNode(Node $node, Scope $scope): array
4346

4447
$classReflection = $this->reflectionProvider->getClass($className);
4548
if (!$classReflection->hasConstructor()) {
46-
return [
47-
RuleErrorBuilder::message(sprintf(
48-
'Call to new %s() on a separate line has no effect.',
49-
$classReflection->getDisplayName(),
50-
))->identifier('new.resultUnused')->build(),
51-
];
49+
if ($this->reportNoConstructor) {
50+
return [
51+
RuleErrorBuilder::message(sprintf(
52+
'Call to new %s() on a separate line has no effect.',
53+
$classReflection->getDisplayName(),
54+
))->identifier('new.resultUnused')->build(),
55+
];
56+
}
57+
58+
return [];
5259
}
5360

5461
$constructor = $classReflection->getConstructor();

tests/PHPStan/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CallToConstructorStatementWithoutSideEffectsRuleTest extends RuleTestCase
1313

1414
protected function getRule(): Rule
1515
{
16-
return new CallToConstructorStatementWithoutSideEffectsRule($this->createReflectionProvider());
16+
return new CallToConstructorStatementWithoutSideEffectsRule($this->createReflectionProvider(), true);
1717
}
1818

1919
public function testRule(): void

0 commit comments

Comments
 (0)