Skip to content

Commit

Permalink
revers listfield method
Browse files Browse the repository at this point in the history
  • Loading branch information
tombroucke committed Nov 13, 2023
1 parent 1d8d502 commit d122c7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Abstracts/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,14 @@ public function map(callable $mapFunction) : static
}
return new static($this->value);
}

/**
* Reverse the list
*
* @return static
*/
public function reverse() : static
{
return new static(array_reverse($this->value));
}
}
6 changes: 6 additions & 0 deletions tests/RepeaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public function testRepeaterHasRows()
{
$this->assertInstanceOf(Row::class, $this->repeater[0]);
}

public function testRepeaterArrayIsReversible()
{
$reversedListField = $this->repeater->reverse();
$this->assertEquals(array_reverse($this->repeaterArray), $reversedListField->value());
}
}

0 comments on commit d122c7f

Please sign in to comment.