Skip to content

Commit 0807b58

Browse files
committed
PHPstan level 8
1 parent 400b433 commit 0807b58

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 7
2+
level: 8
33
paths:
44
- src
55
excludePaths:

src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function getIdentifier(ClassMetadata $metadata): string
118118
{
119119
$identifiers = $metadata->getIdentifierFieldNames();
120120

121-
return array_shift($identifiers);
121+
return array_shift($identifiers) ?? throw new \LogicException(sprintf('Class %s has no identifiers', $metadata->getName()));
122122
}
123123

124124
private function setIdentifierFromAssociation(string $association, string $key, ClassMetadata $metadata): ClassMetadata

src/Adapter/Doctrine/ORMAdapter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ protected function getAliases(AdapterQuery $query): array
154154

155155
protected function mapPropertyPath(AdapterQuery $query, AbstractColumn $column): ?string
156156
{
157-
return $this->mapFieldToPropertyPath($column->getField(), $query->get('aliases'));
157+
if (null === ($field = $column->getField())) {
158+
throw new InvalidConfigurationException(sprintf('Could not automatically map a field for column "%s"', $column->getName()));
159+
}
160+
161+
return $this->mapFieldToPropertyPath($field, $query->get('aliases'));
158162
}
159163

160164
/**
@@ -169,8 +173,8 @@ protected function getResults(AdapterQuery $query): \Traversable
169173
// Apply definitive view state for current 'page' of the table
170174
foreach ($state->getOrderBy() as list($column, $direction)) {
171175
/** @var AbstractColumn $column */
172-
if ($column->isOrderable()) {
173-
$builder->addOrderBy($column->getOrderField(), $direction);
176+
if ($column->isOrderable() && null !== ($order = $column->getOrderField())) {
177+
$builder->addOrderBy($order, $direction);
174178
}
175179
}
176180
if (null !== $state->getLength()) {

src/DataTable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function createAdapter(string $adapter, array $options = []): static
165165

166166
public function getAdapter(): AdapterInterface
167167
{
168-
return $this->adapter;
168+
return $this->adapter ?? throw new InvalidConfigurationException('DataTable has no adapter');
169169
}
170170

171171
public function getColumn(int $index): AbstractColumn
@@ -266,21 +266,21 @@ public function getResponse(): Response
266266
$state = $this->getState();
267267

268268
// Server side export
269-
if (null !== $this->state->getExporterName()) {
269+
if (null !== $state->getExporterName()) {
270270
return $this->exporterManager
271271
->setDataTable($this)
272-
->setExporterName($this->state->getExporterName())
272+
->setExporterName($state->getExporterName())
273273
->getResponse();
274274
}
275275

276276
$resultSet = $this->getResultSet();
277277
$response = [
278-
'draw' => $this->state->getDraw(),
278+
'draw' => $state->getDraw(),
279279
'recordsTotal' => $resultSet->getTotalRecords(),
280280
'recordsFiltered' => $resultSet->getTotalDisplayRecords(),
281281
'data' => iterator_to_array($resultSet->getData()),
282282
];
283-
if ($this->state->isInitial()) {
283+
if ($state->isInitial()) {
284284
$response['options'] = $this->getInitialResponse();
285285
$response['template'] = $this->renderer->renderDataTable($this, $this->template, $this->templateParams);
286286
}
@@ -314,7 +314,7 @@ protected function getResultSet(): ResultSetInterface
314314
throw new InvalidStateException('No adapter was configured yet to retrieve data with. Call "createAdapter" or "setAdapter" before attempting to return data');
315315
}
316316

317-
return $this->adapter->getData($this->state);
317+
return $this->adapter->getData($this->getState());
318318
}
319319

320320
public function getTransformer(): ?callable

0 commit comments

Comments
 (0)