Skip to content

Commit f315a2a

Browse files
committed
More code modernization
1 parent f6b239c commit f315a2a

File tree

9 files changed

+29
-23
lines changed

9 files changed

+29
-23
lines changed

src/Adapter/AdapterInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ interface AdapterInterface
2323
{
2424
/**
2525
* Provides initial configuration to the adapter.
26+
*
27+
* @param array<string, mixed> $options Adapter specific options array
2628
*/
27-
public function configure(array $options);
29+
public function configure(array $options): void;
2830

2931
/**
3032
* Processes a datatable's state into a result set fit for further processing.

src/Adapter/Doctrine/ORMAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(ManagerRegistry $registry = null)
7373
$this->registry = $registry;
7474
}
7575

76-
public function configure(array $options)
76+
public function configure(array $options): void
7777
{
7878
$resolver = new OptionsResolver();
7979
$this->configureOptions($resolver);

src/Adapter/Elasticsearch/ElasticaAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ElasticaAdapter extends AbstractAdapter
3232
/** @var array<string, mixed> */
3333
private array $indices = [];
3434

35-
public function configure(array $options)
35+
public function configure(array $options): void
3636
{
3737
$resolver = new OptionsResolver();
3838
$this->configureOptions($resolver);

src/Column/AbstractColumn.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getName(): string
138138
return $this->name;
139139
}
140140

141-
public function getLabel(): ?string
141+
public function getLabel(): string
142142
{
143143
return $this->options['label'] ?? "{$this->dataTable->getName()}.columns.{$this->getName()}";
144144
}
@@ -173,9 +173,9 @@ public function isOrderable(): bool
173173
return $this->options['orderable'] ?? !empty($this->getOrderField());
174174
}
175175

176-
public function getFilter(): AbstractFilter
176+
public function getFilter(): ?AbstractFilter
177177
{
178-
return $this->options['filter'];
178+
return $this->options['filter'] ?? null;
179179
}
180180

181181
public function getOrderField(): ?string
@@ -188,7 +188,7 @@ public function isGlobalSearchable(): bool
188188
return $this->options['globalSearchable'] ?? $this->isSearchable();
189189
}
190190

191-
public function getLeftExpr(): string
191+
public function getLeftExpr(): mixed
192192
{
193193
$leftExpr = $this->options['leftExpr'];
194194
if (null === $leftExpr) {
@@ -201,7 +201,7 @@ public function getLeftExpr(): string
201201
return $leftExpr;
202202
}
203203

204-
public function getRightExpr(mixed $value): string
204+
public function getRightExpr(mixed $value): mixed
205205
{
206206
$rightExpr = $this->options['rightExpr'];
207207
if (null === $rightExpr) {
@@ -219,9 +219,9 @@ public function getOperator(): string
219219
return $this->options['operator'];
220220
}
221221

222-
public function getClassName(): string
222+
public function getClassName(): ?string
223223
{
224-
return $this->options['className'];
224+
return $this->options['className'] ?? null;
225225
}
226226

227227
public function getDataTable(): DataTable
@@ -241,7 +241,7 @@ public function setOption(string $name, mixed $value): static
241241
return $this;
242242
}
243243

244-
public function isValidForSearch(string $value): bool
244+
public function isValidForSearch(mixed $value): bool
245245
{
246246
return true;
247247
}

src/Column/BoolColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getNullValue(): string
6969
return $this->options['nullValue'];
7070
}
7171

72-
public function isValidForSearch(string $value): bool
72+
public function isValidForSearch(mixed $value): bool
7373
{
7474
$value = trim(mb_strtolower($value));
7575

src/Column/NumberColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function isRaw(): bool
4848
return $this->options['raw'];
4949
}
5050

51-
public function isValidForSearch(string $value): bool
51+
public function isValidForSearch(mixed $value): bool
5252
{
5353
return is_numeric($value);
5454
}

src/Column/TwigColumn.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
*/
2424
class TwigColumn extends AbstractColumn
2525
{
26-
protected Environment $twig;
26+
protected readonly Environment $twig;
2727

2828
public function __construct(Environment $twig = null)
2929
{
30-
if (null === ($this->twig = $twig)) {
30+
if (null === $twig) {
3131
throw new MissingDependencyException('You must have TwigBundle installed to use ' . static::class);
3232
}
33+
$this->twig = $twig;
3334
}
3435

3536
protected function render($value, $context): mixed

src/DataTable.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,14 @@ public function getPersistState(): string
219219
return $this->persistState;
220220
}
221221

222-
public function getState(): ?DataTableState
222+
public function getState(): DataTableState
223223
{
224-
return $this->state;
224+
return $this->state ?? throw new InvalidStateException('The DataTable does not know its state yet, did you call handleRequest?');
225+
}
226+
227+
public function hasState(): bool
228+
{
229+
return null !== $this->state;
225230
}
226231

227232
public function getTranslationDomain(): string
@@ -258,9 +263,7 @@ public function handleRequest(Request $request): static
258263

259264
public function getResponse(): Response
260265
{
261-
if (null === $this->state) {
262-
throw new InvalidStateException('The DataTable does not know its state yet, did you call handleRequest?');
263-
}
266+
$state = $this->getState();
264267

265268
// Server side export
266269
if (null !== $this->state->getExporterName()) {

src/Twig/TwigRenderer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
*/
2525
class TwigRenderer implements DataTableRendererInterface
2626
{
27-
/** @var Environment */
28-
private $twig;
27+
private readonly Environment $twig;
2928

3029
public function __construct(Environment $twig = null)
3130
{
32-
if (null === ($this->twig = $twig)) {
31+
if (null === $twig) {
3332
throw new MissingDependencyException('You must have symfony/twig-bundle installed to use the default Twig based DataTables rendering');
3433
}
34+
$this->twig = $twig;
3535
}
3636

3737
/**

0 commit comments

Comments
 (0)