diff --git a/phpstan.neon b/phpstan.neon index 9b77b0f..27ab5f4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src excludePaths: diff --git a/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php b/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php index f387a23..17e76ee 100644 --- a/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php +++ b/src/Adapter/Doctrine/ORM/AutomaticQueryBuilder.php @@ -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 diff --git a/src/Adapter/Doctrine/ORMAdapter.php b/src/Adapter/Doctrine/ORMAdapter.php index 8625b1d..24f4eb5 100644 --- a/src/Adapter/Doctrine/ORMAdapter.php +++ b/src/Adapter/Doctrine/ORMAdapter.php @@ -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')); } /** @@ -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()) { diff --git a/src/DataTable.php b/src/DataTable.php index 5247983..7def904 100644 --- a/src/DataTable.php +++ b/src/DataTable.php @@ -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 @@ -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); } @@ -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