Sort::fields property is incorrectly defined as a string

Created on 6 June 2024, 6 months ago
Updated 11 July 2024, 5 months ago

Problem/Motivation

In \Drupal\jsonapi\Query\Sort, the property $fields is defined as a string, when it is an array. This causes IDEs such as VSCode to flag iteration of the array as an error when it is not.

Steps to reproduce

In an IDE, write something like

$fields = [
  ['path' => 'changed', 'direction' => 'DESC'], 
  ['path' => 'title', 'direction' => 'ASC'],
];
$sort = new \Drupal\jsonapi\Query\Sort($fields);
foreach ($sort->fields() as $field) {
  echo $field['path'];
}

The IDE will complain "Expected type 'iterable|object'. Found 'string'."

Proposed resolution

Define the $fields property as @var array instead of string.

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
JSON API 

Last updated 9 days ago

Created by

🇺🇸United States BenStallings

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024