Skip to content

Commit

Permalink
Various ext/spl stub fixes
Browse files Browse the repository at this point in the history
Closes GH-7215
  • Loading branch information
kocsismate committed Jul 12, 2021
1 parent 8cec7db commit 80e5ad5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 53 deletions.
11 changes: 10 additions & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public static function fromNode(Node $node): SimpleType {
return new SimpleType($node->toString(), true);
}

if ($node->toLowerString() === 'self') {
throw new Exception('The exact class name must be used instead of "self"');
}

assert($node->isFullyQualified());
return new SimpleType($node->toString(), false);
}
Expand All @@ -142,9 +146,10 @@ public static function fromPhpDoc(string $type): SimpleType
case "object":
case "resource":
case "mixed":
case "self":
case "static":
return new SimpleType(strtolower($type), true);
case "self":
throw new Exception('The exact class name must be used instead of "self"');
}

if (strpos($type, "[]") !== false) {
Expand Down Expand Up @@ -1162,6 +1167,10 @@ function parseFunctionLike(
}
}

if ($param->default instanceof Expr\ClassConstFetch && $param->default->class->toLowerString() === "self") {
throw new Exception('The exact class name must be used instead of "self"');
}

$foundVariadic = $param->variadic;

$args[] = new ArgInfo(
Expand Down
40 changes: 12 additions & 28 deletions ext/spl/spl_array.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
{
public function __construct(array|object $array = [], int $flags = 0, string $iteratorClass = ArrayIterator::class) {}

/**
* @param string|int $key
* @return bool
*/
public function offsetExists($key) {}
/** @return bool */
public function offsetExists(mixed $key) {}

/**
* @param string|int $key
* @return mixed
*/
public function offsetGet($key) {}
/** @return mixed */
public function offsetGet(mixed $key) {}

/**
* @param string|int $key
* @return void
*/
public function offsetSet($key, mixed $value) {}
/** @return void */
public function offsetSet(mixed $key, mixed $value) {}

/**
* @param string|int $key
* @return void
*/
public function offsetUnset($key) {}
/** @return void */
public function offsetUnset(mixed $key) {}

/** @return void */
public function append(mixed $value) {}
Expand Down Expand Up @@ -96,32 +84,28 @@ class ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Coun
public function __construct(array|object $array = [], int $flags = 0) {}

/**
* @param string|int $key
* @return bool
* @implementation-alias ArrayObject::offsetExists
*/
public function offsetExists($key) {}
public function offsetExists(mixed $key) {}

/**
* @param string|int $key
* @return mixed
* @implementation-alias ArrayObject::offsetGet
*/
public function offsetGet($key) {}
public function offsetGet(mixed $key) {}

/**
* @param string|int $key
* @return void
* @implementation-alias ArrayObject::offsetSet
*/
public function offsetSet($key, mixed $value) {}
public function offsetSet(mixed $key, mixed $value) {}

/**
* @param string|int $key
* @return void
* @implementation-alias ArrayObject::offsetUnset
*/
public function offsetUnset($key) {}
public function offsetUnset(mixed $key) {}

/**
* @return void
Expand Down
6 changes: 3 additions & 3 deletions ext/spl/spl_array_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a4bc5ec5a95aae6bfa53988316cfa396f4f9fb92 */
* Stub hash: 89f431b33667e7ee6538a2a50ed7aabcf0449d36 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0)
ZEND_ARG_TYPE_MASK(0, array, MAY_BE_ARRAY|MAY_BE_OBJECT, "[]")
Expand All @@ -8,13 +8,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject_offsetExists, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_TYPE_INFO(0, key, IS_MIXED, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_ArrayObject_offsetGet arginfo_class_ArrayObject_offsetExists

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_TYPE_INFO(0, key, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

Expand Down
8 changes: 4 additions & 4 deletions ext/spl/spl_directory.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function rewind() {}
/** @return string */
public function key() {}

/** @return string|SplFileInfo|self */
/** @return string|SplFileInfo|FilesystemIterator */
public function current() {}

/** @return int */
Expand Down Expand Up @@ -211,7 +211,7 @@ public function fgetcsv(string $separator = ",", string $enclosure = "\"", strin
/** @return int|false */
public function fputcsv(array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\") {}

/** @return bool|null */
/** @return void */
public function setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\") {}

/** @return array */
Expand All @@ -238,7 +238,7 @@ public function fgetc() {}
/** @return int */
public function fpassthru() {}

/** @return array|int|false|null */
/** @return array|int|null */
public function fscanf(string $format, mixed &...$vars) {}

/** @return int|false */
Expand Down Expand Up @@ -274,7 +274,7 @@ public function getMaxLineLen() {}
/** @return bool */
public function hasChildren() {}

/** @return null */
/** @return RecursiveIterator|null */
public function getChildren() {}

/** @return void */
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/spl_directory_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 285af54cf7b3f3ef3f0d673b248c5afbd4cc440e */
* Stub hash: d9110bb238c9edb5c013bd482649ed96e24ff7b6 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
Expand Down
16 changes: 8 additions & 8 deletions ext/spl/spl_iterators.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ interface RecursiveIterator extends Iterator
/** @return bool */
public function hasChildren();

/** @return RecursiveIterator */
/** @return RecursiveIterator|null */
public function getChildren();
}

class RecursiveIteratorIterator implements OuterIterator
{
public function __construct(Traversable $iterator, int $mode = self::LEAVES_ONLY, int $flags = 0) {}
public function __construct(Traversable $iterator, int $mode = RecursiveIteratorIterator::LEAVES_ONLY, int $flags = 0) {}

/** @return void */
public function rewind() {}
Expand Down Expand Up @@ -200,7 +200,7 @@ public function getPosition() {}

class CachingIterator extends IteratorIterator implements ArrayAccess, Countable
{
public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {}
public function __construct(Iterator $iterator, int $flags = CachingIterator::CALL_TOSTRING) {}

/** @return void */
public function rewind() {}
Expand Down Expand Up @@ -255,7 +255,7 @@ public function count() {}

class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator
{
public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {}
public function __construct(Iterator $iterator, int $flags = RecursiveCachingIterator::CALL_TOSTRING) {}

/** @return bool */
public function hasChildren() {}
Expand Down Expand Up @@ -320,7 +320,7 @@ public function next() {}

class RegexIterator extends FilterIterator
{
public function __construct(Iterator $iterator, string $pattern, int $mode = self::MATCH, int $flags = 0, int $pregFlags = 0) {}
public function __construct(Iterator $iterator, string $pattern, int $mode = RegexIterator::MATCH, int $flags = 0, int $pregFlags = 0) {}

/** @return bool */
public function accept() {}
Expand Down Expand Up @@ -349,7 +349,7 @@ public function setPregFlags(int $pregFlags) {}

class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator
{
public function __construct(RecursiveIterator $iterator, string $pattern, int $mode = self::MATCH, int $flags = 0, int $pregFlags = 0) {}
public function __construct(RecursiveIterator $iterator, string $pattern, int $mode = RecursiveRegexIterator::MATCH, int $flags = 0, int $pregFlags = 0) {}

/** @return bool */
public function accept() {}
Expand All @@ -369,9 +369,9 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator
/** @param RecursiveIterator|IteratorAggregate $iterator */
public function __construct(
$iterator,
int $flags = self::BYPASS_KEY,
int $flags = RecursiveTreeIterator::BYPASS_KEY,
int $cachingIteratorFlags = CachingIterator::CATCH_GET_CHILD,
int $mode = self::SELF_FIRST
int $mode = RecursiveTreeIterator::SELF_FIRST
) {}

/** @return mixed */
Expand Down
19 changes: 11 additions & 8 deletions ext/spl/spl_iterators_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ae7df94646bf08874d7b9804833d0081c40e0348 */
* Stub hash: da35c3e48b3a09f5f013fdd760ddab6bdfb37967 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_EmptyIterator_current, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -34,7 +34,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveIteratorIterator___construct, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::LEAVES_ONLY")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveIteratorIterator::LEAVES_ONLY")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -139,7 +139,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_CachingIterator___construct, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "self::CALL_TOSTRING")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "CachingIterator::CALL_TOSTRING")
ZEND_END_ARG_INFO()

#define arginfo_class_CachingIterator_rewind arginfo_class_EmptyIterator_current
Expand Down Expand Up @@ -176,7 +176,10 @@ ZEND_END_ARG_INFO()

#define arginfo_class_CachingIterator_count arginfo_class_EmptyIterator_current

#define arginfo_class_RecursiveCachingIterator___construct arginfo_class_CachingIterator___construct
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveCachingIterator___construct, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "RecursiveCachingIterator::CALL_TOSTRING")
ZEND_END_ARG_INFO()

#define arginfo_class_RecursiveCachingIterator_hasChildren arginfo_class_EmptyIterator_current

Expand Down Expand Up @@ -217,7 +220,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RegexIterator___construct, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0)
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::MATCH")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RegexIterator::MATCH")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pregFlags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -245,7 +248,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveRegexIterator___construct, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0)
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::MATCH")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveRegexIterator::MATCH")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pregFlags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
Expand All @@ -258,9 +261,9 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveTreeIterator___construct, 0, 0, 1)
ZEND_ARG_INFO(0, iterator)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "self::BYPASS_KEY")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "RecursiveTreeIterator::BYPASS_KEY")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cachingIteratorFlags, IS_LONG, 0, "CachingIterator::CATCH_GET_CHILD")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::SELF_FIRST")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveTreeIterator::SELF_FIRST")
ZEND_END_ARG_INFO()

#define arginfo_class_RecursiveTreeIterator_key arginfo_class_EmptyIterator_current
Expand Down

0 comments on commit 80e5ad5

Please sign in to comment.