DocumentShape::field() should only allow arrays #21

Closed
opened 2026-08-21 06:58:23 +02:00 by c.fahner · 0 comments
Owner

The DocumentShape::field() method currently allows three different input types, but the use case of allowing three variants is unclear.

  • A string as a shorthand for new FieldPath([ string-here ])
    • This saves 4 characters of typing but introduces an unnecessary if-check for all other cases
  • An array that is passed directly to the constructor
    • This avoids having to explicitly import the FieldPath class and typing Q::field() looks more consistent with the builder utility
    • This is the primary use case of this method
  • A FieldPath instance
    • Why not use it directly, static analysis can already prove if your variable is a FieldPath already

All cases but the array case should be removed from the method. It essentially is a shorthand for:

use Slendium\Ocd\Common\FieldPath;
// ...
$query = Q::shape([
    'field' => new FieldPath([ 'otherField' ]) // it is more consistent to have a Q::field([ 'otherField' ]) here
]);
The `DocumentShape::field()` method currently allows three different input types, but the use case of allowing three variants is unclear. * A string as a shorthand for `new FieldPath([ string-here ])` * This saves 4 characters of typing but introduces an unnecessary if-check for all other cases * An array that is passed directly to the constructor * This avoids having to explicitly import the `FieldPath` class and typing `Q::field()` looks more consistent with the builder utility * This is the primary use case of this method * A `FieldPath` instance * Why not use it directly, static analysis can already prove if your variable is a `FieldPath` already All cases but the array case should be removed from the method. It essentially is a shorthand for: ```php use Slendium\Ocd\Common\FieldPath; // ... $query = Q::shape([ 'field' => new FieldPath([ 'otherField' ]) // it is more consistent to have a Q::field([ 'otherField' ]) here ]); ```
c.fahner added this to the v0.1 milestone 2026-08-21 06:58:23 +02:00
c.fahner stopped working 2026-08-22 09:56:20 +02:00
4 minutes 5 seconds
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 4 minutes 5 seconds
c.fahner
4 minutes 5 seconds
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
slendium/ocd#21
No description provided.