We cannot use stubs since PHPStan already has them to overridepull/93/head
parent
2e9d766f82
commit
46ec78839d
7 changed files with 138 additions and 45 deletions
@ -0,0 +1,38 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Readability\Maintenance\PHPStan; |
||||||
|
|
||||||
|
use Readability\JSLikeHTMLElement; |
||||||
|
use PHPStan\Type\Generic\GenericObjectType; |
||||||
|
use PhpParser\Node\Expr\MethodCall; |
||||||
|
use PHPStan\Analyser\Scope; |
||||||
|
use PHPStan\Reflection\MethodReflection; |
||||||
|
use PHPStan\Type\DynamicMethodReturnTypeExtension; |
||||||
|
use PHPStan\Type\Type; |
||||||
|
use PHPStan\Type\ArrayType; |
||||||
|
use PHPStan\Type\ObjectType; |
||||||
|
|
||||||
|
class DOMDocumentGetElementDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension |
||||||
|
{ |
||||||
|
public function getClass(): string |
||||||
|
{ |
||||||
|
return \DOMDocument::class; |
||||||
|
} |
||||||
|
|
||||||
|
public function isMethodSupported(MethodReflection $methodReflection): bool |
||||||
|
{ |
||||||
|
return in_array($methodReflection->getName(), |
||||||
|
[ |
||||||
|
'createElement', |
||||||
|
], true); |
||||||
|
} |
||||||
|
|
||||||
|
public function getTypeFromMethodCall( |
||||||
|
MethodReflection $methodReflection, |
||||||
|
MethodCall $methodCall, |
||||||
|
Scope $scope |
||||||
|
): ?Type |
||||||
|
{ |
||||||
|
return new ObjectType(JSLikeHTMLElement::class); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Readability\Maintenance\PHPStan; |
||||||
|
|
||||||
|
use Readability\JSLikeHTMLElement; |
||||||
|
use PHPStan\Type\Generic\GenericObjectType; |
||||||
|
use PhpParser\Node\Expr\MethodCall; |
||||||
|
use PHPStan\Analyser\Scope; |
||||||
|
use PHPStan\Reflection\MethodReflection; |
||||||
|
use PHPStan\Type\DynamicMethodReturnTypeExtension; |
||||||
|
use PHPStan\Type\Type; |
||||||
|
use PHPStan\Type\ArrayType; |
||||||
|
use PHPStan\Type\ObjectType; |
||||||
|
|
||||||
|
class DOMDocumentGetElementsDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension |
||||||
|
{ |
||||||
|
public function getClass(): string |
||||||
|
{ |
||||||
|
return \DOMDocument::class; |
||||||
|
} |
||||||
|
|
||||||
|
public function isMethodSupported(MethodReflection $methodReflection): bool |
||||||
|
{ |
||||||
|
return in_array($methodReflection->getName(), |
||||||
|
[ |
||||||
|
'getElementsByTagName', |
||||||
|
], true); |
||||||
|
} |
||||||
|
|
||||||
|
public function getTypeFromMethodCall( |
||||||
|
MethodReflection $methodReflection, |
||||||
|
MethodCall $methodCall, |
||||||
|
Scope $scope |
||||||
|
): ?Type |
||||||
|
{ |
||||||
|
$elementType = new ObjectType(JSLikeHTMLElement::class); |
||||||
|
return new GenericObjectType(\DOMNodeList::class, [$elementType]); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Readability\Maintenance\PHPStan; |
||||||
|
|
||||||
|
use Readability\JSLikeHTMLElement; |
||||||
|
use PHPStan\Type\Generic\GenericObjectType; |
||||||
|
use PhpParser\Node\Expr\MethodCall; |
||||||
|
use PHPStan\Analyser\Scope; |
||||||
|
use PHPStan\Reflection\MethodReflection; |
||||||
|
use PHPStan\Type\DynamicMethodReturnTypeExtension; |
||||||
|
use PHPStan\Type\Type; |
||||||
|
use PHPStan\Type\ArrayType; |
||||||
|
use PHPStan\Type\ObjectType; |
||||||
|
|
||||||
|
class DOMElementGetElementsDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension |
||||||
|
{ |
||||||
|
public function getClass(): string |
||||||
|
{ |
||||||
|
return \DOMElement::class; |
||||||
|
} |
||||||
|
|
||||||
|
public function isMethodSupported(MethodReflection $methodReflection): bool |
||||||
|
{ |
||||||
|
return in_array($methodReflection->getName(), |
||||||
|
[ |
||||||
|
'getElementsByTagName', |
||||||
|
], true); |
||||||
|
} |
||||||
|
|
||||||
|
public function getTypeFromMethodCall( |
||||||
|
MethodReflection $methodReflection, |
||||||
|
MethodCall $methodCall, |
||||||
|
Scope $scope |
||||||
|
): ?Type |
||||||
|
{ |
||||||
|
$elementType = new ObjectType(JSLikeHTMLElement::class); |
||||||
|
return new GenericObjectType(\DOMNodeList::class, [$elementType]); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,40 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2022 Ondřej Mirtes |
|
||||||
// SPDX-License-Identifier: MIT |
|
||||||
// Based on https://github.com/phpstan/phpstan-src/blob/b2a9ba4b82d19b01f37eb983746f1840f1213851/stubs/dom.stub |
|
||||||
|
|
||||||
use Readability\JSLikeHTMLElement; |
|
||||||
|
|
||||||
class DOMDocument |
|
||||||
{ |
|
||||||
/** @var JSLikeHTMLElement|null */ |
|
||||||
public $documentElement; |
|
||||||
|
|
||||||
/** |
|
||||||
* @param string $name |
|
||||||
* @return DOMNodeList<JSLikeHTMLElement> |
|
||||||
*/ |
|
||||||
public function getElementsByTagName($name) {} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param string $localName |
|
||||||
* @param string $value |
|
||||||
* @return JSLikeHTMLElement Officially, this can return false but PHPStan decided to ignore that: <https://github.com/phpstan/phpstan-src/pull/1569> |
|
||||||
*/ |
|
||||||
public function createElement($localName, $value = '') {} |
|
||||||
} |
|
||||||
|
|
||||||
class DOMNode |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
class DOMElement extends DOMNode |
|
||||||
{ |
|
||||||
/** |
|
||||||
* @param string $name |
|
||||||
* @return DOMNodeList<JSLikeHTMLElement> |
|
||||||
*/ |
|
||||||
public function getElementsByTagName($name) {} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue