Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
166 additions
and
35 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
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,13 @@ | ||
includes: | ||
- vendor/eloquent/phpstan-phony/phony.neon | ||
- vendor/phpstan/phpstan-phpunit/extension.neon | ||
- vendor/phpstan/phpstan-phpunit/rules.neon | ||
|
||
services: | ||
- | ||
class: League\OAuth2\Client\Test\PHPStan\LiberatorExtension | ||
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension] | ||
|
||
parameters: | ||
ignoreErrors: | ||
- '#Method League\\OAuth2\\Client\\Test\\Tool\\ProviderRedirectTraitTest::setRedirectLimit\(\) should return League\\OAuth2\\Client\\Provider\\AbstractProvider but returns \$this\(League\\OAuth2\\Client\\Test\\Tool\\ProviderRedirectTraitTest\)\.#' |
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
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
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,57 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace League\OAuth2\Client\Test\PHPStan; | ||
|
||
use PHPStan\Reflection\ClassMemberReflection; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\MethodReflection; | ||
|
||
final class LiberatedMethod implements MethodReflection | ||
{ | ||
/** @var \PHPStan\Reflection\MethodReflection */ | ||
private $reflection; | ||
|
||
public function __construct(MethodReflection $reflection) | ||
{ | ||
$this->reflection = $reflection; | ||
} | ||
|
||
public function getDeclaringClass(): ClassReflection | ||
{ | ||
return $this->reflection->getDeclaringClass(); | ||
} | ||
|
||
public function isStatic(): bool | ||
{ | ||
return $this->reflection->isStatic(); | ||
} | ||
|
||
public function isPrivate(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPublic(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->reflection->getName(); | ||
} | ||
|
||
public function getPrototype(): ClassMemberReflection | ||
{ | ||
return $this->reflection->getPrototype(); | ||
} | ||
|
||
/** | ||
* @return \PHPStan\Reflection\ParametersAcceptor[] | ||
*/ | ||
public function getVariants(): array | ||
{ | ||
return $this->reflection->getVariants(); | ||
} | ||
} |
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 League\OAuth2\Client\Test\PHPStan; | ||
|
||
use PHPStan\Reflection\ClassMemberAccessAnswerer; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\ObjectType; | ||
|
||
final class LiberatedType extends ObjectType | ||
{ | ||
public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): MethodReflection | ||
{ | ||
return new LiberatedMethod(parent::getMethod($methodName, $scope)); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace League\OAuth2\Client\Test\PHPStan; | ||
|
||
use Eloquent\Liberator\Liberator; | ||
use Eloquent\Pops\ProxyInterface; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\TypeCombinator; | ||
|
||
final class LiberatorExtension implements DynamicStaticMethodReturnTypeExtension | ||
{ | ||
public function getClass(): string | ||
{ | ||
return Liberator::class; | ||
} | ||
|
||
public function isStaticMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return $methodReflection->getName() === 'liberate'; | ||
} | ||
|
||
public function getTypeFromStaticMethodCall( | ||
MethodReflection $methodReflection, | ||
StaticCall $methodCall, | ||
Scope $scope | ||
): Type { | ||
$types = [new ObjectType(ProxyInterface::class)]; | ||
foreach ($scope->getType($methodCall->args[0]->value)->getReferencedClasses() as $class) { | ||
$types[] = new LiberatedType($class); | ||
} | ||
return TypeCombinator::intersect(...$types); | ||
} | ||
} |
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
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
Oops, something went wrong.