Skip to content

Commit b5e9ee4

Browse files
committed
Syntactic sugar
1 parent d7c31a0 commit b5e9ee4

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/DataTable.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,16 @@ public function getTranslationDomain(): string
265265

266266
public function isCallback(): bool
267267
{
268-
return (null === $this->state) ? false : $this->state->isCallback();
268+
return null !== $this->state && $this->state->isCallback();
269269
}
270270

271271
public function handleRequest(Request $request): static
272272
{
273-
switch ($this->getMethod()) {
274-
case Request::METHOD_GET:
275-
$parameters = $request->query;
276-
break;
277-
case Request::METHOD_POST:
278-
$parameters = $request->request;
279-
break;
280-
default:
281-
throw new InvalidConfigurationException(sprintf("Unknown request method '%s'", $this->getMethod()));
282-
}
273+
$parameters = match ($this->getMethod()) {
274+
Request::METHOD_GET => $request->query,
275+
Request::METHOD_POST => $request->request,
276+
default => throw new InvalidConfigurationException(sprintf("Unknown request method '%s'", $this->getMethod())),
277+
};
283278
if ($this->getName() === $parameters->get('_dt')) {
284279
if (null === $this->state) {
285280
$this->state = DataTableState::fromDefaults($this);

tests/Unit/DataTableTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ public function testDataTableState(): void
104104
$this->assertSame(10, $state->getLength());
105105
$this->assertSame('foo', $state->getGlobalSearch());
106106
$this->assertCount(2, $state->getOrderBy());
107-
foreach ($state->getOrderBy() as $order) {
108-
$this->assertContains($order[1], [DataTable::SORT_ASCENDING, DataTable::SORT_DESCENDING]);
109-
}
110107
$this->assertSame('bar', $state->getSearchColumns(onlySearchable: false)['foo']['search']);
111108

112109
// Test boundaries
@@ -142,9 +139,6 @@ public function testDataTableStateSearchColumns(): void
142139
$this->assertSame('foo', $searchColumns['foo']['search']);
143140
}
144141

145-
/**
146-
* If ordering is false, ensure columns are not ordered.
147-
*/
148142
public function testSortDirectionValidation(): void
149143
{
150144
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)