Skip to content

Commit 92a35f5

Browse files
committed
Make the bug-12585 extension fixture loadable on PHP 7.4
The extension is registered in the test's container, so PHP 7.4 has to parse it. Replace promoted properties, nullable union return types and the named argument with their PHP 7.4 equivalents. The data file needs PHP 8.0 (native mixed, union and promoted properties), so the test now requires PHP >= 8.0. Amp-Thread-ID: https://ampcode.com/threads/T-01a196a1-2352-73e4-b226-d1df672638a1
1 parent 6f5c6ba commit 92a35f5

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎tests/PHPStan/Rules/Methods/CallMethodsRuleParameterClosureTypeTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7+
use PHPUnit\Framework\Attributes\RequiresPhp;
78

89
/**
910
* @extends RuleTestCase<CallMethodsRule>
@@ -21,6 +22,7 @@ protected function getRule(): Rule
2122
return self::getContainer()->getByType(CallMethodsRule::class);
2223
}
2324

25+
#[RequiresPhp('>= 8.0.0')]
2426
public function testBug12585(): void
2527
{
2628
$this->analyse([__DIR__ . '/data/bug-12585.php'], [

‎tests/PHPStan/Rules/Methods/data/bug-12585-extension.php‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php // lint >= 8.0
1+
<?php
22

33
namespace Bug12585;
44

@@ -30,8 +30,12 @@ final class EloquentBuilderRelationParameterExtension implements MethodParameter
3030
/** @var list<string> */
3131
private array $methods = ['whereHas', 'withWhereHas'];
3232

33-
public function __construct(private ReflectionProvider $reflectionProvider)
33+
/** @var ReflectionProvider */
34+
private $reflectionProvider;
35+
36+
public function __construct(ReflectionProvider $reflectionProvider)
3437
{
38+
$this->reflectionProvider = $reflectionProvider;
3539
}
3640

3741
public function isMethodSupported(MethodReflection $methodReflection, ParameterReflection $parameter): bool
@@ -40,10 +44,10 @@ public function isMethodSupported(MethodReflection $methodReflection, ParameterR
4044
return false;
4145
}
4246

43-
return in_array($methodReflection->getName(), $this->methods, strict: true);
47+
return in_array($methodReflection->getName(), $this->methods, true);
4448
}
4549

46-
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, ParameterReflection $parameter, Scope $scope): Type|null
50+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, ParameterReflection $parameter, Scope $scope): ?Type
4751
{
4852
$method = $methodReflection->getName();
4953
$relations = $this->getRelationsFromMethodCall($methodCall, $scope);
@@ -180,7 +184,7 @@ private function determineBuilderName(string $modelClassName): string
180184
* @param array<int, string|TypeWithClassName>|string|TypeWithClassName $models
181185
* @return ($models is array<int, string|TypeWithClassName> ? Type : ObjectType)
182186
*/
183-
private function getBuilderTypeForModels(array|string|TypeWithClassName $models): Type
187+
private function getBuilderTypeForModels($models): Type
184188
{
185189
$models = is_array($models) ? $models : [$models];
186190
$models = array_unique($models, SORT_REGULAR);
@@ -215,8 +219,16 @@ private function getBuilderTypeForModels(array|string|TypeWithClassName $models)
215219

216220
final class ClosureQueryParameter implements ParameterReflection
217221
{
218-
public function __construct(private string $name, private Type $type)
222+
/** @var string */
223+
private $name;
224+
225+
/** @var Type */
226+
private $type;
227+
228+
public function __construct(string $name, Type $type)
219229
{
230+
$this->name = $name;
231+
$this->type = $type;
220232
}
221233

222234
public function getName(): string
@@ -244,7 +256,7 @@ public function isVariadic(): bool
244256
return false;
245257
}
246258

247-
public function getDefaultValue(): Type|null
259+
public function getDefaultValue(): ?Type
248260
{
249261
return null;
250262
}

0 commit comments

Comments
 (0)