-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new ClosureTypeChangingExtension
- Loading branch information
Showing
13 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/DependencyInjection/Type/ClosureTypeChangingExtensionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\DependencyInjection\Type; | ||
|
||
use PHPStan\Type\FunctionClosureTypeChangingExtension; | ||
use PHPStan\Type\MethodClosureTypeChangingExtension; | ||
use PHPStan\Type\StaticMethodClosureTypeChangingExtension; | ||
|
||
interface ClosureTypeChangingExtensionProvider | ||
{ | ||
|
||
/** @return FunctionClosureTypeChangingExtension[] */ | ||
public function getFunctionClosureTypeChangingExtensions(): array; | ||
|
||
/** @return MethodClosureTypeChangingExtension[] */ | ||
public function getMethodClosureTypeChangingExtensions(): array; | ||
|
||
/** @return StaticMethodClosureTypeChangingExtension[] */ | ||
public function getStaticMethodClosureTypeChangingExtensions(): array; | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/DependencyInjection/Type/LazyClosureTypeChangingExtensionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\DependencyInjection\Type; | ||
|
||
use PHPStan\DependencyInjection\Container; | ||
|
||
class LazyClosureTypeChangingExtensionProvider implements ClosureTypeChangingExtensionProvider | ||
{ | ||
|
||
public const FUNCTION_TAG = 'phpstan.functionClosureTypeChangingExtension'; | ||
public const METHOD_TAG = 'phpstan.methodClosureTypeChangingExtension'; | ||
public const STATIC_METHOD_TAG = 'phpstan.staticMethodClosureTypeChangingExtension'; | ||
|
||
public function __construct(private Container $container) | ||
{ | ||
} | ||
|
||
public function getFunctionClosureTypeChangingExtensions(): array | ||
{ | ||
return $this->container->getServicesByTag(self::FUNCTION_TAG); | ||
} | ||
|
||
public function getMethodClosureTypeChangingExtensions(): array | ||
{ | ||
return $this->container->getServicesByTag(self::METHOD_TAG); | ||
} | ||
|
||
public function getStaticMethodClosureTypeChangingExtensions(): array | ||
{ | ||
return $this->container->getServicesByTag(self::STATIC_METHOD_TAG); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type; | ||
|
||
use PhpParser\Node\Expr\FuncCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\FunctionReflection; | ||
|
||
interface FunctionClosureTypeChangingExtension | ||
{ | ||
|
||
public function isFunctionSupported(FunctionReflection $functionReflection): bool; | ||
|
||
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type; | ||
|
||
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
|
||
interface MethodClosureTypeChangingExtension | ||
{ | ||
|
||
public function isMethodSupported(MethodReflection $methodReflection): bool; | ||
|
||
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type; | ||
|
||
use PhpParser\Node\Expr\StaticCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
|
||
interface StaticMethodClosureTypeChangingExtension | ||
{ | ||
|
||
public function isStaticMethodSupported(MethodReflection $methodReflection): bool; | ||
|
||
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/PHPStan/Analyser/ClosureTypeChangingExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
class ClosureTypeChangingExtensionTest extends TypeInferenceTestCase | ||
{ | ||
|
||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-type-changing-extension.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args, | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/closure-type-changing-extension.neon', | ||
]; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/PHPStan/Analyser/closure-type-changing-extension.neon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
- | ||
class: ClosureTypeChangingExtension\FunctionClosureTypeChangingExtension | ||
tags: | ||
- phpstan.functionClosureTypeChangingExtension | ||
|
||
- | ||
class: ClosureTypeChangingExtension\MethodClosureTypeChangingExtension | ||
tags: | ||
- phpstan.methodClosureTypeChangingExtension | ||
|
||
- | ||
class: ClosureTypeChangingExtension\StaticMethodClosureTypeChangingExtension | ||
tags: | ||
- phpstan.staticMethodClosureTypeChangingExtension | ||
|
Oops, something went wrong.