Skip to content

Commit

Permalink
Fix internal error in SimpleXMLElementConstructorThrowTypeExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Aug 5, 2023
1 parent a5e5719 commit 4f6b051
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
use PHPStan\Type\TypeCombinator;
use SimpleXMLElement;
use function count;
use function extension_loaded;

class SimpleXMLElementConstructorThrowTypeExtension implements DynamicStaticMethodThrowTypeExtension
{

public function isStaticMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === '__construct' && $methodReflection->getDeclaringClass()->getName() === SimpleXMLElement::class;
return extension_loaded('simplexml')
&& $methodReflection->getName() === '__construct'
&& $methodReflection->getDeclaringClass()->getName() === SimpleXMLElement::class;
}

public function getThrowTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use SimpleXMLElement;
use function extension_loaded;

class SimpleXMLElementXpathMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
Expand All @@ -24,7 +25,7 @@ public function getClass(): string

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'xpath';
return extension_loaded('simplexml') && $methodReflection->getName() === 'xpath';
}

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
Expand Down

0 comments on commit 4f6b051

Please sign in to comment.