diff --git a/src/Psalm/Internal/Stubs/CoreGenericClasses.php b/src/Psalm/Internal/Stubs/CoreGenericClasses.php index 0b94448c0..bfed4cfc3 100644 --- a/src/Psalm/Internal/Stubs/CoreGenericClasses.php +++ b/src/Psalm/Internal/Stubs/CoreGenericClasses.php @@ -922,3 +922,231 @@ class SplQueue extends SplDoublyLinkedList { */ public function dequeue () {} } + +/** + * The SplObjectStorage class provides a map from objects to data or, by + * ignoring data, an object set. This dual purpose can be useful in many + * cases involving the need to uniquely identify objects. + * @link https://php.net/manual/en/class.splobjectstorage.php + * @template TObject as object + * @template TArrayValue + * @template-extends ArrayAccess + * @template-extends Iterator + */ +class SplObjectStorage implements Countable, Iterator, Serializable, ArrayAccess { + public function __construct() {} + + /** + * Adds an object in the storage + * @link https://php.net/manual/en/splobjectstorage.attach.php + * @param TObject $object

+ * The object to add. + *

+ * @param mixed $data [optional]

+ * The data to associate with the object. + *

+ * @return void + * @since 5.1.0 + */ + public function attach ($object, $data = null) {} + + /** + * Removes an object from the storage + * @link https://php.net/manual/en/splobjectstorage.detach.php + * @param TObject $object

+ * The object to remove. + *

+ * @return void + * @since 5.1.0 + */ + public function detach ($object) {} + + /** + * Checks if the storage contains a specific object + * @link https://php.net/manual/en/splobjectstorage.contains.php + * @param TObject $object

+ * The object to look for. + *

+ * @return bool true if the object is in the storage, false otherwise. + * @since 5.1.0 + */ + public function contains ($object) {} + + /** + * Adds all objects from another storage + * @link https://php.net/manual/en/splobjectstorage.addall.php + * @param SplObjectStorage $storage

+ * The storage you want to import. + *

+ * @return void + * @since 5.3.0 + */ + public function addAll ($storage) {} + + /** + * Removes objects contained in another storage from the current storage + * @link https://php.net/manual/en/splobjectstorage.removeall.php + * @param SplObjectStorage $storage

+ * The storage containing the elements to remove. + *

+ * @return void + * @since 5.3.0 + */ + public function removeAll ($storage) {} + + /** + * Removes all objects except for those contained in another storage from the current storage + * @link https://php.net/manual/en/splobjectstorage.removeallexcept.php + * @param SplObjectStorage $storage

+ * The storage containing the elements to retain in the current storage. + *

+ * @return void + * @since 5.3.6 + */ + public function removeAllExcept ($storage) {} + + /** + * Returns the data associated with the current iterator entry + * @link https://php.net/manual/en/splobjectstorage.getinfo.php + * @return mixed The data associated with the current iterator position. + * @since 5.3.0 + */ + public function getInfo () {} + + /** + * Sets the data associated with the current iterator entry + * @link https://php.net/manual/en/splobjectstorage.setinfo.php + * @param mixed $data

+ * The data to associate with the current iterator entry. + *

+ * @return void + * @since 5.3.0 + */ + public function setInfo ($data) {} + + /** + * Returns the number of objects in the storage + * @link https://php.net/manual/en/splobjectstorage.count.php + * @return int The number of objects in the storage. + * @since 5.1.0 + */ + public function count () {} + + /** + * Rewind the iterator to the first storage element + * @link https://php.net/manual/en/splobjectstorage.rewind.php + * @return void + * @since 5.1.0 + */ + public function rewind () {} + + /** + * Returns if the current iterator entry is valid + * @link https://php.net/manual/en/splobjectstorage.valid.php + * @return bool true if the iterator entry is valid, false otherwise. + * @since 5.1.0 + */ + public function valid () {} + + /** + * Returns the index at which the iterator currently is + * @link https://php.net/manual/en/splobjectstorage.key.php + * @return int The index corresponding to the position of the iterator. + * @since 5.1.0 + */ + public function key () {} + + /** + * Returns the current storage entry + * @link https://php.net/manual/en/splobjectstorage.current.php + * @return TObject The object at the current iterator position. + * @since 5.1.0 + */ + public function current () {} + + /** + * Move to the next entry + * @link https://php.net/manual/en/splobjectstorage.next.php + * @return void + * @since 5.1.0 + */ + public function next () {} + + /** + * Unserializes a storage from its string representation + * @link https://php.net/manual/en/splobjectstorage.unserialize.php + * @param string $serialized

+ * The serialized representation of a storage. + *

+ * @return void + * @since 5.2.2 + */ + public function unserialize ($serialized) {} + + /** + * Serializes the storage + * @link https://php.net/manual/en/splobjectstorage.serialize.php + * @return string A string representing the storage. + * @since 5.2.2 + */ + public function serialize () {} + + /** + * Checks whether an object exists in the storage + * @link https://php.net/manual/en/splobjectstorage.offsetexists.php + * @param TObject $object

+ * The object to look for. + *

+ * @return bool true if the object exists in the storage, + * and false otherwise. + * @since 5.3.0 + */ + public function offsetExists ($object) {} + + /** + * Associates data to an object in the storage + * @link https://php.net/manual/en/splobjectstorage.offsetset.php + * @param TObject $object

+ * The object to associate data with. + *

+ * @param mixed $data [optional]

+ * The data to associate with the object. + *

+ * @return void + * @since 5.3.0 + */ + public function offsetSet ($object, $data = null) {} + + /** + * Removes an object from the storage + * @link https://php.net/manual/en/splobjectstorage.offsetunset.php + * @param TObject $object

+ * The object to remove. + *

+ * @return void + * @since 5.3.0 + */ + public function offsetUnset ($object) {} + + /** + * Returns the data associated with an object + * @link https://php.net/manual/en/splobjectstorage.offsetget.php + * @param TObject $object

+ * The object to look for. + *

+ * @return mixed The data previously associated with the object in the storage. + * @since 5.3.0 + */ + public function offsetGet ($object) {} + + /** + * Calculate a unique identifier for the contained objects + * @link https://php.net/manual/en/splobjectstorage.gethash.php + * @param $object

+ * object whose identifier is to be calculated. + * @return string A string with the calculated identifier. + * @since 5.4.0 + */ + public function getHash($object) {} + +} diff --git a/tests/Template/TemplateExtendsTest.php b/tests/Template/TemplateExtendsTest.php index 6efc0f036..adb4e886a 100644 --- a/tests/Template/TemplateExtendsTest.php +++ b/tests/Template/TemplateExtendsTest.php @@ -1014,6 +1014,42 @@ class TemplateExtendsTest extends TestCase '$a' => 'null|int', ] ], + 'splObjectStorage' => [ + ' + */ + public $handlers; + + /** + * @param SplObjectStorage<\stdClass, mixed> $handlers + */ + public function __construct(SplObjectStorage $handlers) + { + $this->handlers = $handlers; + } + } + + /** @var SplObjectStorage<\stdClass, mixed> */ + $storage = new SplObjectStorage(); + new SomeService($storage);', + ], + 'extendsArrayIterator' => [ + ' + */ + class Users extends ArrayIterator + { + public function __construct(User ...$users) { + parent::__construct($users); + } + }', + ], ]; }