Skip to content

Commit

Permalink
PHPstan level 8
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Oct 25, 2023
1 parent 400b433 commit 0807b58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 7
level: 8
paths:
- src
excludePaths:
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function getIdentifier(ClassMetadata $metadata): string
{
$identifiers = $metadata->getIdentifierFieldNames();

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

private function setIdentifierFromAssociation(string $association, string $key, ClassMetadata $metadata): ClassMetadata
Expand Down
10 changes: 7 additions & 3 deletions src/Adapter/Doctrine/ORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ protected function getAliases(AdapterQuery $query): array

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

return $this->mapFieldToPropertyPath($field, $query->get('aliases'));
}

/**
Expand All @@ -169,8 +173,8 @@ protected function getResults(AdapterQuery $query): \Traversable
// Apply definitive view state for current 'page' of the table
foreach ($state->getOrderBy() as list($column, $direction)) {
/** @var AbstractColumn $column */
if ($column->isOrderable()) {
$builder->addOrderBy($column->getOrderField(), $direction);
if ($column->isOrderable() && null !== ($order = $column->getOrderField())) {
$builder->addOrderBy($order, $direction);
}
}
if (null !== $state->getLength()) {
Expand Down
12 changes: 6 additions & 6 deletions src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function createAdapter(string $adapter, array $options = []): static

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

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

// Server side export
if (null !== $this->state->getExporterName()) {
if (null !== $state->getExporterName()) {
return $this->exporterManager
->setDataTable($this)
->setExporterName($this->state->getExporterName())
->setExporterName($state->getExporterName())
->getResponse();
}

$resultSet = $this->getResultSet();
$response = [
'draw' => $this->state->getDraw(),
'draw' => $state->getDraw(),
'recordsTotal' => $resultSet->getTotalRecords(),
'recordsFiltered' => $resultSet->getTotalDisplayRecords(),
'data' => iterator_to_array($resultSet->getData()),
];
if ($this->state->isInitial()) {
if ($state->isInitial()) {
$response['options'] = $this->getInitialResponse();
$response['template'] = $this->renderer->renderDataTable($this, $this->template, $this->templateParams);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ protected function getResultSet(): ResultSetInterface
throw new InvalidStateException('No adapter was configured yet to retrieve data with. Call "createAdapter" or "setAdapter" before attempting to return data');
}

return $this->adapter->getData($this->state);
return $this->adapter->getData($this->getState());
}

public function getTransformer(): ?callable
Expand Down

0 comments on commit 0807b58

Please sign in to comment.