Skip to content

Commit

Permalink
Fix undefined XMLReader properties with local phpstorm-stubs patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 21, 2024
1 parent 59ae706 commit 2d364d7
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 8 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@
"jetbrains/phpstorm-stubs": [
"patches/PDO.patch",
"patches/ReflectionProperty.patch",
"patches/SessionHandler.patch"
"patches/SessionHandler.patch",
"patches/xmlreader.patch",
"patches/dom_c.patch"
]
}
},
Expand Down
13 changes: 6 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions patches/dom_c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- dom/dom_c.php 2024-01-02 12:04:54
+++ dom/dom_c.php 2024-01-21 10:41:56
@@ -1347,6 +1347,14 @@
*/
class DOMNamedNodeMap implements IteratorAggregate, Countable
{
+
+ /**
+ * The number of nodes in the map. The range of valid child node indices is 0 to length - 1 inclusive.
+ * @var int
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $length;
/**
* Retrieves a node specified by name
* @link https://php.net/manual/en/domnamednodemap.getnameditem.php
122 changes: 122 additions & 0 deletions patches/xmlreader.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
--- xmlreader/xmlreader.php 2024-01-21 10:44:31
+++ xmlreader/xmlreader.php 2024-01-21 10:48:24
@@ -28,7 +28,119 @@
*/
class XMLReader
{
+ /**
+ * The number of attributes on the node
+ * @var int
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $attributeCount;
+
+ /**
+ * The base URI of the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $baseURI;
+
+ /**
+ * Depth of the node in the tree, starting at 0
+ * @var int
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $depth;
+
+ /**
+ * Indicates if node has attributes
+ * @var bool
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $hasAttributes;
+
+ /**
+ * Indicates if node has a text value
+ * @var bool
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $hasValue;
+
+ /**
+ * Indicates if attribute is defaulted from DTD
+ * @var bool
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $isDefault;
+
+ /**
+ * Indicates if node is an empty element tag
+ * @var bool
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $isEmptyElement;
+
+ /**
+ * The local name of the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $localName;
+
/**
+ * The qualified name of the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $name;
+
+ /**
+ * The URI of the namespace associated with the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $namespaceURI;
+
+ /**
+ * The node type for the node
+ * @var int
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $nodeType;
+
+ /**
+ * The prefix of the namespace associated with the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $prefix;
+
+ /**
+ * The text value of the node
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $value;
+
+ /**
+ * The xml:lang scope which the node resides
+ * @var string
+ * @readonly
+ */
+ #[PhpStormStubsElementAvailable(from: '8.1')]
+ public $xmlLang;
+
+ /**
* No node type
*/
public const NONE = 0;
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,12 @@ public function testRequireExtends(): void
]);
}

public function testBug8629(): void
{
$this->checkThisOnly = false;
$this->checkUnionTypes = true;
$this->checkDynamicProperties = true;
$this->analyse([__DIR__ . '/data/bug-8629.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-8629.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Bug8629;

use XMLReader;

function (): void {
$reader = new XMLReader();
var_dump($reader->nodeType);
};

0 comments on commit 2d364d7

Please sign in to comment.