Verified Commit 87883408 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3524656 by alexpott: Fix Drupal\Core\Database\Fetch* types as they are wrong

parent 9ee9a05f
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -433,7 +433,7 @@ public function getFullQualifiedTableName($table) {
  public function prepareStatement(string $query, array $options, bool $allow_row_count = FALSE): StatementInterface {
    assert(!isset($options['return']), 'Passing "return" option to prepareStatement() has no effect. See https://www.drupal.org/node/3185520');
    if (isset($options['fetch']) && is_int($options['fetch'])) {
      @trigger_error("Passing the 'fetch' key as an integer to \$options in prepareStatement() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the 'fetch' key as an integer to \$options in prepareStatement() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
    }

    try {
@@ -654,7 +654,7 @@ public function query($query, array $args = [], $options = []) {
    assert(!isset($options['return']), 'Passing "return" option to query() has no effect. See https://www.drupal.org/node/3185520');
    assert(!isset($options['target']), 'Passing "target" option to query() has no effect. See https://www.drupal.org/node/2993033');
    if (isset($options['fetch']) && is_int($options['fetch'])) {
      @trigger_error("Passing the 'fetch' key as an integer to \$options in query() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the 'fetch' key as an integer to \$options in query() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
    }

    // Use default values if not already set.
+5 −5
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ trait PdoTrait {
  /**
   * Converts a FetchAs mode to a \PDO::FETCH_* constant value.
   *
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   The FetchAs mode.
   *
   * @return int
@@ -34,7 +34,7 @@ protected function fetchAsToPdo(FetchAs $mode): int {
   * @param int $mode
   *   The \PDO::FETCH_* constant value.
   *
   * @return \Drupal\Core\Database\FetchAs
   * @return \Drupal\Core\Database\Statement\FetchAs
   *   A FetchAs mode.
   */
  protected function pdoToFetchAs(int $mode): FetchAs {
@@ -70,7 +70,7 @@ public function getClientStatement(): \PDOStatement {
  /**
   * Sets the default fetch mode for the PDO statement.
   *
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   One of the cases of the FetchAs enum.
   * @param int|class-string|null $columnOrClass
   *   If $mode is FetchAs::Column, the index of the column to fetch.
@@ -118,7 +118,7 @@ protected function clientExecute(?array $arguments = [], array $options = []): b
  /**
   * Fetches the next row from the PDO statement.
   *
   * @param \Drupal\Core\Database\FetchAs|null $mode
   * @param \Drupal\Core\Database\Statement\FetchAs|null $mode
   *   (Optional) one of the cases of the FetchAs enum. If not specified,
   *   defaults to what is specified by setFetchMode().
   * @param int|null $cursorOrientation
@@ -175,7 +175,7 @@ protected function clientFetchObject(?string $class = NULL, array $constructorAr
  /**
   * Returns an array containing all of the result set rows.
   *
   * @param \Drupal\Core\Database\FetchAs|null $mode
   * @param \Drupal\Core\Database\Statement\FetchAs|null $mode
   *   (Optional) one of the cases of the FetchAs enum. If not specified,
   *   defaults to what is specified by setFetchMode().
   * @param int|class-string|null $columnOrClass
+4 −4
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ abstract public function rowCount(): ?int;
  /**
   * Sets the default fetch mode for this result set.
   *
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   One of the cases of the FetchAs enum.
   * @param array{class: class-string, constructor_args: list<mixed>, column: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions
   *   An array of fetch options.
@@ -55,7 +55,7 @@ abstract public function setFetchMode(FetchAs $mode, array $fetchOptions): bool;
  /**
   * Fetches the next row.
   *
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   One of the cases of the FetchAs enum.
   * @param array{class?: class-string, constructor_args?: list<mixed>, column?: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions
   *   An array of fetch options.
@@ -68,7 +68,7 @@ abstract public function fetch(FetchAs $mode, array $fetchOptions): array|object
  /**
   * Returns an array containing all of the result set rows.
   *
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   One of the cases of the FetchAs enum.
   * @param array{class?: class-string, constructor_args?: list<mixed>, column?: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions
   *   An array of fetch options.
@@ -120,7 +120,7 @@ public function fetchAllKeyed(int $keyIndex = 0, int $valueIndex = 1): array {
   *
   * @param string $column
   *   The name of the field on which to index the array.
   * @param \Drupal\Core\Database\FetchAs $mode
   * @param \Drupal\Core\Database\Statement\FetchAs $mode
   *   One of the cases of the FetchAs enum. If set to FetchAs::Associative
   *   or FetchAs::List the returned value with be an array of arrays. For any
   *   other value it will be an array of objects. If not specified, defaults to
+4 −4
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ public function getQueryString() {
   */
  public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
    if (is_int($mode)) {
      @trigger_error("Passing the \$mode argument as an integer to setFetchMode() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the \$mode argument as an integer to setFetchMode() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      $mode = $this->pdoToFetchAs($mode);
    }
    assert($mode instanceof FetchAs);
@@ -217,7 +217,7 @@ public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
   */
  public function fetch($mode = NULL, $cursorOrientation = NULL, $cursorOffset = NULL) {
    if (is_int($mode)) {
      @trigger_error("Passing the \$mode argument as an integer to fetch() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the \$mode argument as an integer to fetch() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      $mode = $this->pdoToFetchAs($mode);
    }
    assert($mode === NULL || $mode instanceof FetchAs);
@@ -292,7 +292,7 @@ public function fetchField($index = 0) {
   */
  public function fetchAll($mode = NULL, $columnIndex = NULL, $constructorArguments = NULL) {
    if (is_int($mode)) {
      @trigger_error("Passing the \$mode argument as an integer to fetchAll() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the \$mode argument as an integer to fetchAll() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      $mode = $this->pdoToFetchAs($mode);
    }

@@ -325,7 +325,7 @@ public function fetchCol($index = 0) {
   */
  public function fetchAllAssoc($key, $fetch = NULL) {
    if (is_int($fetch)) {
      @trigger_error("Passing the \$fetch argument as an integer to fetchAllAssoc() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      @trigger_error("Passing the \$fetch argument as an integer to fetchAllAssoc() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      $fetch = $this->pdoToFetchAs($fetch);
    }
    assert($fetch === NULL || $fetch instanceof FetchAs);
+4 −4
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public function rowCount();
  /**
   * Sets the default fetch mode for this statement.
   *
   * @param \Drupal\Core\Database\FetchAs|int $mode
   * @param \Drupal\Core\Database\Statement\FetchAs|int $mode
   *   One of the cases of the FetchAs enum, or (deprecated) a \PDO::FETCH_*
   *   constant.
   * @param string|int|null $a1
@@ -87,7 +87,7 @@ public function setFetchMode($mode, $a1 = NULL, $a2 = []);
  /**
   * Fetches the next row from a result set.
   *
   * @param \Drupal\Core\Database\FetchAs|int|null $mode
   * @param \Drupal\Core\Database\Statement\FetchAs|int|null $mode
   *   (Optional) one of the cases of the FetchAs enum, or (deprecated) a
   *   \PDO::FETCH_* constant. If not specified, defaults to what is specified
   *   by setFetchMode().
@@ -147,7 +147,7 @@ public function fetchAssoc();
  /**
   * Returns an array containing all of the result set rows.
   *
   * @param \Drupal\Core\Database\FetchAs|int|null $mode
   * @param \Drupal\Core\Database\Statement\FetchAs|int|null $mode
   *   (Optional) one of the cases of the FetchAs enum, or (deprecated) a
   *   \PDO::FETCH_* constant. If not specified, defaults to what is specified
   *   by setFetchMode().
@@ -206,7 +206,7 @@ public function fetchAllKeyed($key_index = 0, $value_index = 1);
   *
   * @param string $key
   *   The name of the field on which to index the array.
   * @param \Drupal\Core\Database\FetchAs|int|string|null $fetch
   * @param \Drupal\Core\Database\Statement\FetchAs|int|string|null $fetch
   *   (Optional) the fetch mode to use. One of the cases of the FetchAs enum,
   *   or (deprecated) a \PDO::FETCH_* constant. If set to FetchAs::Associative
   *   or FetchAs::List the returned value with be an array of arrays. For any
Loading