wiki.techinc.nl/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php
Umherirrender e9e784a09e build: Enable phan-taint-check-plugin and suppress issues
Taint check checks for possible security issues by tracking html
escaping and more by using phan.
This slows done the phan-job a bit and requires more ram

Keep the DoubleEscaped issues out to make reviewer easier

Adds suppression for false positives
Adds taint-annotation to help taint-check
Removes suppression for code phan now understand better by the tracking
of keys in taint-check
Fix some small issues by adding int cast or htmlspecialchars calls

Bug: T216348
Bug: T268920
Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
2020-12-30 19:02:22 +01:00

87 lines
1.7 KiB
PHP

<?php
namespace Wikimedia\Rdbms;
use stdClass;
/**
* Overloads the relevant methods of the real ResultsWrapper so it
* doesn't go anywhere near an actual database.
*/
class FakeResultWrapper implements IResultWrapper {
/** @var stdClass[]|array[] */
protected $result;
/** @var int */
protected $pos = 0;
/**
* @param stdClass[]|array[]|FakeResultWrapper $result
*/
public function __construct( $result ) {
if ( $result instanceof self ) {
$this->result = $result->result;
} else {
$this->result = $result;
}
}
public function numRows() {
return count( $this->result );
}
public function fetchObject() {
$current = $this->current();
$this->next();
return $current;
}
public function fetchRow() {
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable valid() checks for result not null
$row = $this->valid() ? $this->result[$this->pos] : false;
$this->next();
return is_object( $row ) ? get_object_vars( $row ) : $row;
}
public function seek( $pos ) {
$this->pos = $pos;
}
public function free() {
$this->result = null;
}
public function rewind() {
$this->pos = 0;
}
public function current() {
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable valid() checks for result not null
$row = $this->valid() ? $this->result[$this->pos] : false;
return is_array( $row ) ? (object)$row : $row;
}
public function key() {
return $this->pos;
}
public function next() {
$this->pos++;
return $this->current();
}
public function valid() {
return array_key_exists( $this->pos, $this->result );
}
}
/**
* @deprecated since 1.29
*/
class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );