Skip to content

Commit

Permalink
[BCB] Removed some unused internal helper methods from Broker
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 14, 2021
1 parent 65efd93 commit d578151
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 216 deletions.
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ services:
class: PHPStan\Type\Php\TypeSpecifyingFunctionsDynamicReturnTypeExtension
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
universalObjectCratesClasses: %universalObjectCratesClasses%
tags:
- phpstan.broker.dynamicFunctionReturnTypeExtension

Expand Down
66 changes: 0 additions & 66 deletions src/Broker/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,32 @@
namespace PHPStan\Broker;

use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\GlobalConstantReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\OperatorTypeSpecifyingExtension;
use PHPStan\Type\Type;

/** @api */
class Broker implements ReflectionProvider
{

private ReflectionProvider $reflectionProvider;

private DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider;

private \PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider $operatorTypeSpecifyingExtensionRegistryProvider;

/** @var string[] */
private array $universalObjectCratesClasses;

private static ?Broker $instance = null;

/**
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
* @param \PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider
* @param \PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider $operatorTypeSpecifyingExtensionRegistryProvider
* @param string[] $universalObjectCratesClasses
*/
public function __construct(
ReflectionProvider $reflectionProvider,
DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider,
OperatorTypeSpecifyingExtensionRegistryProvider $operatorTypeSpecifyingExtensionRegistryProvider,
array $universalObjectCratesClasses
)
{
$this->reflectionProvider = $reflectionProvider;
$this->dynamicReturnTypeExtensionRegistryProvider = $dynamicReturnTypeExtensionRegistryProvider;
$this->operatorTypeSpecifyingExtensionRegistryProvider = $operatorTypeSpecifyingExtensionRegistryProvider;
$this->universalObjectCratesClasses = $universalObjectCratesClasses;
}

Expand Down Expand Up @@ -122,56 +108,4 @@ public function getUniversalObjectCratesClasses(): array
return $this->universalObjectCratesClasses;
}

/**
* @param string $className
* @return \PHPStan\Type\DynamicMethodReturnTypeExtension[]
*/
public function getDynamicMethodReturnTypeExtensionsForClass(string $className): array
{
return $this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicMethodReturnTypeExtensionsForClass($className);
}

/**
* @param string $className
* @return \PHPStan\Type\DynamicStaticMethodReturnTypeExtension[]
*/
public function getDynamicStaticMethodReturnTypeExtensionsForClass(string $className): array
{
return $this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicStaticMethodReturnTypeExtensionsForClass($className);
}

/**
* @return OperatorTypeSpecifyingExtension[]
*/
public function getOperatorTypeSpecifyingExtensions(string $operator, Type $leftType, Type $rightType): array
{
return $this->operatorTypeSpecifyingExtensionRegistryProvider->getRegistry()->getOperatorTypeSpecifyingExtensions($operator, $leftType, $rightType);
}

/**
* @return \PHPStan\Type\DynamicFunctionReturnTypeExtension[]
*/
public function getDynamicFunctionReturnTypeExtensions(): array
{
return $this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicFunctionReturnTypeExtensions();
}

/**
* @internal
* @return DynamicReturnTypeExtensionRegistryProvider
*/
public function getDynamicReturnTypeExtensionRegistryProvider(): DynamicReturnTypeExtensionRegistryProvider
{
return $this->dynamicReturnTypeExtensionRegistryProvider;
}

/**
* @internal
* @return \PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider
*/
public function getOperatorTypeSpecifyingExtensionRegistryProvider(): OperatorTypeSpecifyingExtensionRegistryProvider
{
return $this->operatorTypeSpecifyingExtensionRegistryProvider;
}

}
4 changes: 0 additions & 4 deletions src/Broker/BrokerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace PHPStan\Broker;

use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\Reflection\ReflectionProvider;

class BrokerFactory
Expand All @@ -28,8 +26,6 @@ public function create(): Broker
{
return new Broker(
$this->container->getByType(ReflectionProvider::class),
$this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class),
$this->container->getByType(OperatorTypeSpecifyingExtensionRegistryProvider::class),
$this->container->getParameter('universalObjectCratesClasses')
);
}
Expand Down

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions src/Testing/PHPStanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
use PHPStan\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
use PHPStan\Broker\AnonymousClassNameHelper;
use PHPStan\Broker\Broker;
use PHPStan\Broker\BrokerFactory;
use PHPStan\Cache\Cache;
use PHPStan\Cache\MemoryCacheStorage;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\ContainerFactory;
use PHPStan\DependencyInjection\Reflection\DirectClassReflectionExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DirectDynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DirectOperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\File\FileHelper;
Expand Down Expand Up @@ -164,22 +161,10 @@ public function createReflectionProvider(): ReflectionProvider
);
$setterReflectionProviderProvider->setReflectionProvider($reflectionProvider);

$dynamicReturnTypeExtensionRegistryProvider = new DirectDynamicReturnTypeExtensionRegistryProvider(
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG),
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_STATIC_METHOD_RETURN_TYPE_EXTENSION_TAG),
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_FUNCTION_RETURN_TYPE_EXTENSION_TAG)
);
$operatorTypeSpecifyingExtensionRegistryProvider = new DirectOperatorTypeSpecifyingExtensionRegistryProvider([]);

$broker = new Broker(
$reflectionProvider,
$dynamicReturnTypeExtensionRegistryProvider,
$operatorTypeSpecifyingExtensionRegistryProvider,
self::getContainer()->getParameter('universalObjectCratesClasses')
);
$dynamicReturnTypeExtensionRegistryProvider->setBroker($broker);
$dynamicReturnTypeExtensionRegistryProvider->setReflectionProvider($reflectionProvider);
$operatorTypeSpecifyingExtensionRegistryProvider->setBroker($broker);
$this->getClassReflectionExtensionRegistryProvider()->setBroker($broker);

return $reflectionProvider;
Expand Down
13 changes: 11 additions & 2 deletions src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ class TypeSpecifyingFunctionsDynamicReturnTypeExtension implements DynamicFuncti

private ?\PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper $helper = null;

public function __construct(ReflectionProvider $reflectionProvider, bool $treatPhpDocTypesAsCertain)
/** @var string[] */
private array $universalObjectCratesClasses;

/**
* @param ReflectionProvider $reflectionProvider
* @param bool $treatPhpDocTypesAsCertain
* @param string[] $universalObjectCratesClasses
*/
public function __construct(ReflectionProvider $reflectionProvider, bool $treatPhpDocTypesAsCertain, array $universalObjectCratesClasses)
{
$this->reflectionProvider = $reflectionProvider;
$this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain;
$this->universalObjectCratesClasses = $universalObjectCratesClasses;
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
Expand Down Expand Up @@ -84,7 +93,7 @@ public function getTypeFromFunctionCall(
private function getHelper(): ImpossibleCheckTypeHelper
{
if ($this->helper === null) {
$this->helper = new ImpossibleCheckTypeHelper($this->reflectionProvider, $this->typeSpecifier, $this->reflectionProvider->getUniversalObjectCratesClasses(), $this->treatPhpDocTypesAsCertain);
$this->helper = new ImpossibleCheckTypeHelper($this->reflectionProvider, $this->typeSpecifier, $this->universalObjectCratesClasses, $this->treatPhpDocTypesAsCertain);
}

return $this->helper;
Expand Down
8 changes: 0 additions & 8 deletions tests/PHPStan/Broker/BrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use PHPStan\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber;
use PHPStan\Cache\Cache;
use PHPStan\DependencyInjection\Reflection\DirectClassReflectionExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DirectDynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DirectOperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\File\FileHelper;
use PHPStan\File\SimpleRelativePathHelper;
use PHPStan\Php\PhpVersion;
Expand Down Expand Up @@ -39,8 +37,6 @@ protected function setUp(): void
$anonymousClassNameHelper = new AnonymousClassNameHelper($fileHelper, $relativePathHelper);

$classReflectionExtensionRegistryProvider = new DirectClassReflectionExtensionRegistryProvider([], []);
$dynamicReturnTypeExtensionRegistryProvider = new DirectDynamicReturnTypeExtensionRegistryProvider([], [], []);
$operatorTypeSpecifyingExtensionRegistryProvider = new DirectOperatorTypeSpecifyingExtensionRegistryProvider([]);

$setterReflectionProviderProvider = new SetterReflectionProviderProvider();
$reflectionProvider = new RuntimeReflectionProvider(
Expand All @@ -57,13 +53,9 @@ protected function setUp(): void
$setterReflectionProviderProvider->setReflectionProvider($reflectionProvider);
$this->broker = new Broker(
$reflectionProvider,
$dynamicReturnTypeExtensionRegistryProvider,
$operatorTypeSpecifyingExtensionRegistryProvider,
[]
);
$classReflectionExtensionRegistryProvider->setBroker($this->broker);
$dynamicReturnTypeExtensionRegistryProvider->setBroker($this->broker);
$operatorTypeSpecifyingExtensionRegistryProvider->setBroker($this->broker);
}

public function testClassNotFound(): void
Expand Down

0 comments on commit d578151

Please sign in to comment.