Issues (1369)

classes/DBAL/DbAbstractResultIterator.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Created by Gorlum 25.11.2017 20:02
4
 */
5
6
namespace DBAL;
7
8
use \mysqli_result;
0 ignored issues
show
The type \mysqli_result was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Common\Interfaces\ICountableIterator;
10
11
/**
12
 * Class DbAbstractResultIterator
13
 *
14
 * Base class which makes Iterator from internal $mysqli_result
15
 * Other classes which inherits from this will implement their own methods to obtain mysqli_result (or fill it internally)
16
 *
17
 * @package DBAL
18
 */
19
abstract class DbAbstractResultIterator implements ICountableIterator {
20
  /**
21
   * @var mysqli_result|false $mysqli_result
22
   */
23
  protected $mysqli_result;
24
25
  /**
26
   * @var int|float|null
27
   */
28
  protected $counter = null;
29
  /**
30
   * @var array|null $currentRow
31
   */
32
  protected $currentRow = null;
33
34
  /**
35
   * Seeks mysqli_result to first record
36
   */
37
  protected function seekToFirst() {
38
    if ($this->mysqli_result instanceof mysqli_result) {
39
      $this->mysqli_result->data_seek(0);
40
    }
41
  }
42
43
  /**
44
   * @inheritdoc
45
   */
46
  public function rewind() {
47
    if ($this->mysqli_result instanceof mysqli_result) {
48
      $this->seekToFirst();
49
      $this->next();
50
    }
51
    $this->counter = $this->valid() ? 0 : null;
52
  }
53
54
  /**
55
   * @inheritdoc
56
   */
57
  public function valid() {
58
    return $this->mysqli_result instanceof mysqli_result && $this->currentRow !== null;
59
  }
60
61
  /**
62
   * @inheritdoc
63
   */
64
  public function next() {
65
    if ($this->mysqli_result instanceof mysqli_result) {
66
      $this->currentRow = $this->mysqli_result->fetch_assoc();
67
      $this->counter++;
68
    }
69
  }
70
71
  /**
72
   * @inheritdoc
73
   */
74
  public function key() {
75
    return $this->mysqli_result instanceof mysqli_result ? $this->counter : null;
76
  }
77
78
  /**
79
   * @inheritdoc
80
   */
81
  public function current() {
82
    return $this->currentRow;
83
  }
84
85
  /**
86
   * @inheritdoc
87
   */
88
  public function count() {
89
    return $this->mysqli_result instanceof mysqli_result ? $this->mysqli_result->num_rows : 0;
90
  }
91
92
}
93