Skip to content

Commit 98bf387

Browse files
committed
Introduce ReflectionProvider interface
1 parent 1c9cfef commit 98bf387

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

conf/config.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ services:
796796
broker:
797797
class: PHPStan\Broker\Broker
798798
factory: @brokerFactory::create
799+
autowired:
800+
- PHPStan\Broker\Broker
799801

800802
brokerFactory:
801803
class: PHPStan\Broker\BrokerFactory
@@ -814,6 +816,12 @@ services:
814816
class: PHPStan\Rules\Registry
815817
factory: @PHPStan\Rules\RegistryFactory::create
816818

819+
reflectionProvider:
820+
class: PHPStan\Reflection\ReflectionProvider
821+
factory: @broker
822+
autowired:
823+
- PHPStan\Reflection\ReflectionProvider
824+
817825
typeNodeResolverFactory:
818826
class: PHPStan\PhpDoc\TypeNodeResolverFactory
819827

src/Broker/Broker.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Reflection\FunctionVariant;
1515
use PHPStan\Reflection\Native\NativeFunctionReflection;
1616
use PHPStan\Reflection\Native\NativeParameterReflection;
17+
use PHPStan\Reflection\ReflectionProvider;
1718
use PHPStan\Reflection\SignatureMap\ParameterSignature;
1819
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
1920
use PHPStan\TrinaryLogic;
@@ -30,7 +31,7 @@
3031
use PHPStan\Type\UnionType;
3132
use ReflectionClass;
3233

33-
class Broker
34+
class Broker implements ReflectionProvider
3435
{
3536

3637
/** @var \PHPStan\Reflection\PropertiesClassReflectionExtension[] */
@@ -90,7 +91,7 @@ class Broker
9091
/** @var \PHPStan\Reflection\Php\PhpFunctionReflection[] */
9192
private $customFunctionReflections = [];
9293

93-
/** @var self|null */
94+
/** @var ReflectionProvider|null */
9495
private static $instance;
9596

9697
/** @var bool[] */
@@ -169,12 +170,12 @@ public function __construct(
169170
$this->universalObjectCratesClasses = $universalObjectCratesClasses;
170171
}
171172

172-
public static function registerInstance(Broker $broker): void
173+
public static function registerInstance(ReflectionProvider $reflectionProvider): void
173174
{
174-
self::$instance = $broker;
175+
self::$instance = $reflectionProvider;
175176
}
176177

177-
public static function getInstance(): self
178+
public static function getInstance(): ReflectionProvider
178179
{
179180
if (self::$instance === null) {
180181
throw new \PHPStan\ShouldNotHappenException();

src/Reflection/Php/UniversalObjectCratesClassReflectionExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Reflection\ClassReflection;
77
use PHPStan\Reflection\ParametersAcceptorSelector;
88
use PHPStan\Reflection\PropertyReflection;
9+
use PHPStan\Reflection\ReflectionProvider;
910
use PHPStan\Type\MixedType;
1011

1112
class UniversalObjectCratesClassReflectionExtension
@@ -41,19 +42,19 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
4142
}
4243

4344
/**
44-
* @param \PHPStan\Broker\Broker $broker
45+
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
4546
* @param string[] $classes
4647
* @param \PHPStan\Reflection\ClassReflection $classReflection
4748
* @return bool
4849
*/
4950
public static function isUniversalObjectCrate(
50-
Broker $broker,
51+
ReflectionProvider $reflectionProvider,
5152
array $classes,
5253
ClassReflection $classReflection
5354
): bool
5455
{
5556
foreach ($classes as $className) {
56-
if (!$broker->hasClass($className)) {
57+
if (!$reflectionProvider->hasClass($className)) {
5758
continue;
5859
}
5960

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Reflection;
4+
5+
use PHPStan\Analyser\Scope;
6+
7+
interface ReflectionProvider
8+
{
9+
10+
public function hasClass(string $className): bool;
11+
12+
public function getClass(string $className): ClassReflection;
13+
14+
public function getClassName(string $className): string;
15+
16+
public function hasFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): bool;
17+
18+
public function getFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): FunctionReflection;
19+
20+
// helper functions that do not have to do anything with reflection
21+
22+
/**
23+
* @return string[]
24+
*/
25+
public function getUniversalObjectCratesClasses(): array;
26+
27+
}

0 commit comments

Comments
 (0)