Skip to content

Commit

Permalink
Updated phpstorm-stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 17, 2020
1 parent f5a3df6 commit e1f492c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 43 deletions.
53 changes: 53 additions & 0 deletions compiler/patches/stubs/SimpleXML/SimpleXML.stub.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--- SimpleXML/SimpleXML.stub 2020-07-17 13:50:32.000000000 +0200
+++ SimpleXML/SimpleXML2.stub 2020-07-17 13:51:37.000000000 +0200
@@ -6,7 +6,7 @@
* Represents an element in an XML document.
* @link https://php.net/manual/en/class.simplexmlelement.php
*/
-class SimpleXMLElement implements Traversable, ArrayAccess, Countable, Iterator {
+class SimpleXMLElement implements Traversable, ArrayAccess, Countable {

/**
* Creates a new SimpleXMLElement object
@@ -244,41 +244,6 @@
* @return void
*/
private function offsetUnset ($offset) {}
-
- /**
- * Rewind to the first element
- * @link https://php.net/manual/en/simplexmliterator.rewind.php
- * @return void No value is returned.
- */
- private function rewind () {}
-
- /**
- * Check whether the current element is valid
- * @link https://php.net/manual/en/simplexmliterator.valid.php
- * @return bool <b>TRUE</b> if the current element is valid, otherwise <b>FALSE</b>
- */
- private function valid () {}
-
- /**
- * Returns the current element
- * @link https://php.net/manual/en/simplexmliterator.current.php
- * @return static|null the current element as a <b>SimpleXMLElement</b> object or <b>NULL</b> on failure.
- */
- private function current () {}
-
- /**
- * Return current key
- * @link https://php.net/manual/en/simplexmliterator.key.php
- * @return string|false the XML tag name of the element referenced by the current <b>SimpleXMLIterator</b> object or <b>FALSE</b>
- */
- private function key () {}
-
- /**
- * Move to next element
- * @link https://php.net/manual/en/simplexmliterator.next.php
- * @return void No value is returned.
- */
- private function next () {}
}

/**
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"hoa/exception": "^1.0",
"hoa/regex": "1.17.01.13",
"jean85/pretty-package-versions": "^1.0.3",
"jetbrains/phpstorm-stubs": "dev-master#11e2d07705b8b7063a984f49a27d8c3120288e31",
"jetbrains/phpstorm-stubs": "dev-master#d4db4b4834d8a9c8fc3c0aa6dc3c9bae723bbc9c",
"nette/bootstrap": "^3.0",
"nette/di": "dev-master#4e1e2d1747d61b5da5d84ba77a28b726b6d7744c",
"nette/finder": "^2.5",
Expand All @@ -21,7 +21,7 @@
"nette/utils": "^3.1.1",
"nikic/php-parser": "dev-master",
"ondram/ci-detector": "^3.4.0",
"ondrejmirtes/better-reflection": "^4.3.17",
"ondrejmirtes/better-reflection": "4.3.18",
"phpdocumentor/type-resolver": "1.0.1",
"phpstan/phpdoc-parser": "^0.4.8",
"react/child-process": "^0.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,26 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Generic\TemplateTypeHelper;

class AnnotationsMethodsClassReflectionExtension implements MethodsClassReflectionExtension
{

private FileTypeMapper $fileTypeMapper;

/** @var MethodReflection[][] */
private array $methods = [];

public function __construct(FileTypeMapper $fileTypeMapper)
{
$this->fileTypeMapper = $fileTypeMapper;
}

public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
if (!isset($this->methods[$classReflection->getName()])) {
$this->methods[$classReflection->getName()] = $this->createMethods($classReflection, $classReflection);
if (!isset($this->methods[$classReflection->getCacheKey()])) {
$this->methods[$classReflection->getCacheKey()] = $this->createMethods($classReflection, $classReflection);
}

return isset($this->methods[$classReflection->getName()][$methodName]);
return isset($this->methods[$classReflection->getCacheKey()][$methodName]);
}

public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
{
return $this->methods[$classReflection->getName()][$methodName];
return $this->methods[$classReflection->getCacheKey()][$methodName];
}

/**
Expand Down Expand Up @@ -68,8 +61,8 @@ private function createMethods(
return $methods;
}

$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($fileName, $classReflection->getName(), null, null, $docComment);
foreach ($resolvedPhpDoc->getMethodTags() as $methodName => $methodTag) {
$methodTags = $classReflection->getMethodTags();
foreach ($methodTags as $methodName => $methodTag) {
$parameters = [];
foreach ($methodTag->getParameters() as $parameterName => $parameterTag) {
$parameters[] = new AnnotationsMethodParameterReflection(
Expand All @@ -85,7 +78,10 @@ private function createMethods(
$methods[$methodName] = new AnnotationMethodReflection(
$methodName,
$declaringClass,
$methodTag->getReturnType(),
TemplateTypeHelper::resolveTemplateTypes(
$methodTag->getReturnType(),
$classReflection->getActiveTemplateTypeMap()
),
$parameters,
$methodTag->isStatic(),
$this->detectMethodVariadic($parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,26 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Generic\TemplateTypeHelper;

class AnnotationsPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{

private \PHPStan\Type\FileTypeMapper $fileTypeMapper;

/** @var \PHPStan\Reflection\PropertyReflection[][] */
private array $properties = [];

public function __construct(FileTypeMapper $fileTypeMapper)
{
$this->fileTypeMapper = $fileTypeMapper;
}

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
if (!isset($this->properties[$classReflection->getName()])) {
$this->properties[$classReflection->getName()] = $this->createProperties($classReflection, $classReflection);
if (!isset($this->properties[$classReflection->getCacheKey()])) {
$this->properties[$classReflection->getCacheKey()] = $this->createProperties($classReflection, $classReflection);
}

return isset($this->properties[$classReflection->getName()][$propertyName]);
return isset($this->properties[$classReflection->getCacheKey()][$propertyName]);
}

public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
return $this->properties[$classReflection->getName()][$propertyName];
return $this->properties[$classReflection->getCacheKey()][$propertyName];
}

/**
Expand Down Expand Up @@ -69,11 +62,14 @@ private function createProperties(
return $properties;
}

$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($fileName, $classReflection->getName(), null, null, $docComment);
foreach ($resolvedPhpDoc->getPropertyTags() as $propertyName => $propertyTag) {
$propertyTags = $classReflection->getPropertyTags();
foreach ($propertyTags as $propertyName => $propertyTag) {
$properties[$propertyName] = new AnnotationPropertyReflection(
$declaringClass,
$propertyTag->getType(),
TemplateTypeHelper::resolveTemplateTypes(
$propertyTag->getType(),
$classReflection->getActiveTemplateTypeMap()
),
$propertyTag->isReadable(),
$propertyTag->isWritable()
);
Expand Down
28 changes: 28 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\PhpDoc\Tag\ExtendsTag;
use PHPStan\PhpDoc\Tag\ImplementsTag;
use PHPStan\PhpDoc\Tag\MethodTag;
use PHPStan\PhpDoc\Tag\MixinTag;
use PHPStan\PhpDoc\Tag\PropertyTag;
use PHPStan\PhpDoc\Tag\TemplateTag;
use PHPStan\Reflection\Php\PhpClassReflectionExtension;
use PHPStan\Reflection\Php\PhpPropertyReflection;
Expand Down Expand Up @@ -979,6 +981,32 @@ public function getMixinTags(): array
return $resolvedPhpDoc->getMixinTags();
}

/**
* @return array<PropertyTag>
*/
public function getPropertyTags(): array
{
$resolvedPhpDoc = $this->getResolvedPhpDoc();
if ($resolvedPhpDoc === null) {
return [];
}

return $resolvedPhpDoc->getPropertyTags();
}

/**
* @return array<MethodTag>
*/
public function getMethodTags(): array
{
$resolvedPhpDoc = $this->getResolvedPhpDoc();
if ($resolvedPhpDoc === null) {
return [];
}

return $resolvedPhpDoc->getMethodTags();
}

/**
* @return array<Type>
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ public function create(

};
$phpDocInheritanceResolver = new PhpDocInheritanceResolver($fileTypeMapper);
$annotationsMethodsClassReflectionExtension = new AnnotationsMethodsClassReflectionExtension($fileTypeMapper);
$annotationsPropertiesClassReflectionExtension = new AnnotationsPropertiesClassReflectionExtension($fileTypeMapper);
$annotationsMethodsClassReflectionExtension = new AnnotationsMethodsClassReflectionExtension();
$annotationsPropertiesClassReflectionExtension = new AnnotationsPropertiesClassReflectionExtension();
$signatureMapProvider = self::getContainer()->getByType(SignatureMapProvider::class);
$methodReflectionFactory->reflectionProvider = $actualReflectionProvider;
$phpExtension = new PhpClassReflectionExtension(self::getContainer()->getByType(ScopeFactory::class), self::getContainer()->getByType(NodeScopeResolver::class), $methodReflectionFactory, $phpDocInheritanceResolver, $annotationsMethodsClassReflectionExtension, $annotationsPropertiesClassReflectionExtension, $signatureMapProvider, $parser, self::getContainer()->getByType(StubPhpDocProvider::class), $actualReflectionProvider, true, []);
Expand Down
5 changes: 4 additions & 1 deletion src/Type/Php/FilterVarDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public function __construct(ReflectionProvider $reflectionProvider)
$this->getConstant('FILTER_VALIDATE_REGEXP') => $stringType,
$this->getConstant('FILTER_VALIDATE_URL') => $stringType,
$this->getConstant('FILTER_SANITIZE_MAGIC_QUOTES') => $stringType,
$this->getConstant('FILTER_SANITIZE_ADD_SLASHES') => $stringType,
];

if ($this->reflectionProvider->hasConstant(new Node\Name('FILTER_SANITIZE_ADD_SLASHES'), null)) {
$this->filterTypeMap[$this->getConstant('FILTER_SANITIZE_ADD_SLASHES')] = $stringType;
}

$this->flagsString = new ConstantStringType('flags');
}

Expand Down
1 change: 1 addition & 0 deletions stubs/ReflectionClass.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/**
* @template-covariant T of object
* @property-read class-string<T> $name
*/
class ReflectionClass
{
Expand Down
4 changes: 0 additions & 4 deletions tests/PHPStan/Analyser/data/generics.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,6 @@ function () {
class GenericReflectionClass extends \ReflectionClass
{

public $name;

public function newInstanceWithoutConstructor()
{
return parent::newInstanceWithoutConstructor();
Expand All @@ -1117,8 +1115,6 @@ public function newInstanceWithoutConstructor()
class SpecificReflectionClass extends \ReflectionClass
{

public $name;

public function newInstanceWithoutConstructor()
{
return parent::newInstanceWithoutConstructor();
Expand Down
4 changes: 0 additions & 4 deletions tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ public function testCoalesceRule(): void
'Static property CoalesceRule\FooCoalesce::$staticString (string) on left side of ?? is not nullable.',
131,
],
[
'Property ReflectionClass<object>::$name (class-string<object>) on left side of ?? is not nullable.',
136,
],
]);
}

Expand Down

0 comments on commit e1f492c

Please sign in to comment.