-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MethodsClassReflectionExtension for SoapClient magic methods
- Loading branch information
1 parent
179107e
commit f6107ad
Showing
7 changed files
with
170 additions
and
1 deletion.
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,106 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\Php\Soap; | ||
|
||
use PHPStan\Reflection\ClassMemberReflection; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\FunctionVariant; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\Generic\TemplateTypeMap; | ||
use PHPStan\Type\MixedType; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
|
||
class SoapClientMethodReflection implements MethodReflection | ||
{ | ||
|
||
private ClassReflection $declaringClass; | ||
|
||
private string $name; | ||
|
||
public function __construct(ClassReflection $declaringClass, string $name) | ||
{ | ||
$this->declaringClass = $declaringClass; | ||
$this->name = $name; | ||
} | ||
|
||
public function getDeclaringClass(): ClassReflection | ||
{ | ||
return $this->declaringClass; | ||
} | ||
|
||
public function isStatic(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPrivate(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPublic(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getDocComment(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getPrototype(): ClassMemberReflection | ||
{ | ||
return $this; | ||
} | ||
|
||
public function getVariants(): array | ||
{ | ||
return [ | ||
new FunctionVariant( | ||
TemplateTypeMap::createEmpty(), | ||
TemplateTypeMap::createEmpty(), | ||
[], | ||
true, | ||
new MixedType(true) | ||
), | ||
]; | ||
} | ||
|
||
public function isDeprecated(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function getDeprecatedDescription(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function isFinal(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isInternal(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function getThrowType(): ?Type | ||
{ | ||
return new ObjectType('SoapFault'); | ||
} | ||
|
||
public function hasSideEffects(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/Reflection/Php/Soap/SoapClientMethodsClassReflectionExtension.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,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\Php\Soap; | ||
|
||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Reflection\MethodsClassReflectionExtension; | ||
|
||
class SoapClientMethodsClassReflectionExtension implements MethodsClassReflectionExtension | ||
{ | ||
|
||
public function hasMethod(ClassReflection $classReflection, string $methodName): bool | ||
{ | ||
return $classReflection->getName() === 'SoapClient' || $classReflection->isSubclassOf('SoapClient'); | ||
} | ||
|
||
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection | ||
{ | ||
return new SoapClientMethodReflection($classReflection, $methodName); | ||
} | ||
|
||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Bug4822; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
function save(): void { | ||
|
||
} | ||
|
||
function doFoo() | ||
{ | ||
$soapClient = new \SoapClient('https://example.com/?wsdl'); | ||
|
||
try { | ||
$response = $soapClient->test(); | ||
|
||
if (is_array($response)) { | ||
$this->save(); | ||
} | ||
} catch (\Exception $e) { | ||
assertVariableCertainty(TrinaryLogic::createMaybe(), $response); | ||
} | ||
} | ||
|
||
} |