docs: Declare UserArray/TitleArray as Iterator<User>/Iterator<Title>

Declaring the abstract functions and using return type hints helps
phan to understands foreach loop over TitleArray objects

$extraPages = TitleArray::newFromResult( ... );
foreach ( $extraPages as $oldSubpage ) {
	$oldSubpage->getDBkey();
}

It also helps phan-seccheck to decide another issue type in
UploadFromFile

Change-Id: I5f9a0dd5578bd9b585fb4d086a3e133a5ca35cf6
This commit is contained in:
Umherirrender 2021-08-30 22:08:17 +02:00
parent 5c4cd08943
commit 24d64c7557
5 changed files with 30 additions and 9 deletions

View file

@ -29,6 +29,8 @@ use Wikimedia\Rdbms\IResultWrapper;
/**
* The TitleArray class only exists to provide the newFromResult method at pre-
* sent.
* The documentation of the return types for the abstract current/key functions
* helps static code analyzer to treat this as Iterator<Title>
*
* @method int count()
*/
@ -44,4 +46,14 @@ abstract class TitleArray implements Iterator {
// TitleArrayFromResult hook has been removed
return new TitleArrayFromResult( $res );
}
/**
* @return Title
*/
abstract public function current(): Title;
/**
* @return int
*/
abstract public function key(): int;
}

View file

@ -35,8 +35,10 @@ class TitleArrayFromResult extends TitleArray implements Countable {
/** @var IResultWrapper */
public $res;
/** @var int */
public $key;
/** @var Title|false */
public $current;
/**
@ -69,11 +71,11 @@ class TitleArrayFromResult extends TitleArray implements Countable {
return $this->res->numRows();
}
public function current() {
public function current(): Title {
return $this->current;
}
public function key() {
public function key(): int {
return $this->key;
}

View file

@ -53,7 +53,7 @@ class UploadFromFile extends UploadBase {
*/
public function initialize( $name, $webRequestUpload ) {
$this->mUpload = $webRequestUpload;
// @phan-suppress-next-line SecurityCheckMulti False positive T268920
// @phan-suppress-next-line SecurityCheck-PathTraversal False positive T268920
$this->initializePathInfo( $name,
$this->mUpload->getTempName(), $this->mUpload->getSize() );
}

View file

@ -96,4 +96,14 @@ abstract class UserArray implements Iterator {
);
return self::newFromResult( $res );
}
/**
* @return User
*/
abstract public function current(): User;
/**
* @return int
*/
abstract public function key(): int;
}

View file

@ -29,7 +29,7 @@ class UserArrayFromResult extends UserArray implements Countable {
/** @var int */
public $key;
/** @var bool|User */
/** @var User|false */
public $current;
/**
@ -60,14 +60,11 @@ class UserArrayFromResult extends UserArray implements Countable {
return $this->res->numRows();
}
/**
* @return User
*/
public function current() {
public function current(): User {
return $this->current;
}
public function key() {
public function key(): int {
return $this->key;
}