Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Jan 21, 2024
1 parent 54eb354 commit e351b38
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 127 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"doctrine/doctrine-bundle": "^2.9",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.4",
"dg/bypass-finals": "dev-master"
"dg/bypass-finals": "dev-master",
"openspout/openspout": "^4.23"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon → phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
parameters:
level: 5
checkGenericClassInNonGenericObjectType: false
paths:
- src
- tests
excludePaths:
- src/Resources/skeleton/*
- src/DependencyInjection/Configuration.php
4 changes: 4 additions & 0 deletions src/AbstractExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ private function initTypeExtensions(): void
$typeExtensionClass = $this->getTypeExtensionClass();

foreach ($this->loadTypeExtensions() as $extensions) {
if (!is_array($extensions)) {
$extensions = [$extensions];
}

foreach ($extensions as $extension) {
if (!$extension instanceof $typeExtensionClass) {
throw new UnexpectedTypeException($extension, $typeExtensionClass);
Expand Down
5 changes: 5 additions & 0 deletions src/AbstractRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ private function resolveType($type)
}
}

/**
* @return TResolvedType
*/
abstract public function getType(string $name);

/**
* @return class-string<TType>
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Action/Extension/PreloadedActionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class PreloadedActionExtension extends AbstractActionExtension
{
/**
* @param array<ActionTypeInterface> $types
* @param array<string, array<ActionTypeExtensionInterface>> $typeExtensions
* @param array<ActionTypeInterface> $types
* @param array<ActionTypeExtensionInterface>|array<string, array<ActionTypeExtensionInterface>> $typeExtensions
*/
public function __construct(
private readonly array $types = [],
Expand Down
37 changes: 37 additions & 0 deletions src/Bridge/Doctrine/Orm/Filter/Type/CallbackFilterType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type;

use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Query\DoctrineOrmProxyQueryInterface;
use Kreyu\Bundle\DataTableBundle\Exception\UnexpectedTypeException;
use Kreyu\Bundle\DataTableBundle\Filter\FilterData;
use Kreyu\Bundle\DataTableBundle\Filter\FilterInterface;
use Kreyu\Bundle\DataTableBundle\Filter\Operator;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @deprecated since 0.15, use {@see \Kreyu\Bundle\DataTableBundle\Filter\Type\CallbackFilterType} instead
*/
class CallbackFilterType extends AbstractDoctrineOrmFilterType
{
public function apply(ProxyQueryInterface $query, FilterData $data, FilterInterface $filter, array $options): void
{
if (!$query instanceof DoctrineOrmProxyQueryInterface) {
throw new UnexpectedTypeException($query, DoctrineOrmProxyQueryInterface::class);
}

$options['callback']($query, $data, $filter);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefault('supported_operators', Operator::cases())
->setRequired('callback')
->setAllowedTypes('callback', ['callable'])
;
}
}
85 changes: 0 additions & 85 deletions src/Bridge/OpenSpout/Exporter/OpenSpoutExportHandler.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Column/ColumnFactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Kreyu\Bundle\DataTableBundle\Column\Extension\ColumnExtensionInterface;
use Kreyu\Bundle\DataTableBundle\Column\Extension\ColumnTypeExtensionInterface;
use Kreyu\Bundle\DataTableBundle\Column\Extension\CoreColumnExtension;
use Kreyu\Bundle\DataTableBundle\Column\Extension\PreloadedColumnExtension;
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface;
use Kreyu\Bundle\DataTableBundle\Column\Type\ResolvedColumnTypeFactory;
Expand All @@ -31,11 +30,6 @@ class ColumnFactoryBuilder implements ColumnFactoryBuilderInterface
*/
private array $typeExtensions = [];

public function __construct(
private readonly bool $forceCoreExtension = false,
) {
}

public function setResolvedTypeFactory(ResolvedColumnTypeFactoryInterface $resolvedTypeFactory): static
{
$this->resolvedTypeFactory = $resolvedTypeFactory;
Expand Down Expand Up @@ -95,21 +89,6 @@ public function getColumnFactory(): ColumnFactoryInterface
{
$extensions = $this->extensions;

if ($this->forceCoreExtension) {
$hasCoreExtension = false;

foreach ($extensions as $extension) {
if ($extension instanceof CoreColumnExtension) {
$hasCoreExtension = true;
break;
}
}

if (!$hasCoreExtension) {
array_unshift($extensions, new CoreColumnExtension());
}
}

if (\count($this->types) > 0 || \count($this->typeExtensions) > 0) {
$extensions[] = new PreloadedColumnExtension($this->types, $this->typeExtensions);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Column/Extension/PreloadedColumnExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class PreloadedColumnExtension extends AbstractColumnExtension
{
/**
* @param array<ColumnTypeInterface> $types
* @param array<string, array<ColumnTypeExtensionInterface>> $typeExtensions
* @param array<ColumnTypeInterface> $types
* @param array<ColumnTypeExtensionInterface>|array<string, array<ColumnTypeExtensionInterface>> $typeExtensions
*/
public function __construct(
private readonly array $types = [],
Expand Down
2 changes: 0 additions & 2 deletions src/Column/Type/ColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public function buildExportHeaderView(ColumnHeaderView $view, ColumnInterface $c

public function buildExportValueView(ColumnValueView $view, ColumnInterface $column, array $options): void
{
return;

if (false === $options['export']) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public function getColumns(): array
{
$columns = $this->columns;

uasort($columns, static function (ColumnInterface $columnA, ColumnInterface $columnB) {
return $columnA->getPriority() < $columnB->getPriority();
uasort($columns, static function (ColumnInterface $columnA, ColumnInterface $columnB): int {
return $columnB->getPriority() <=> $columnA->getPriority();
});

return $columns;
Expand Down
9 changes: 4 additions & 5 deletions src/Exporter/Extension/PreloadedExporterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

namespace Kreyu\Bundle\DataTableBundle\Exporter\Extension;

use Kreyu\Bundle\DataTableBundle\Column\Extension\AbstractColumnExtension;
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface;
use Kreyu\Bundle\DataTableBundle\Exporter\Type\ExporterTypeInterface;

class PreloadedExporterExtension extends AbstractColumnExtension
class PreloadedExporterExtension extends AbstractExporterExtension
{
/**
* @param array<ColumnTypeInterface> $types
* @param array<string, array<ExporterTypeExtensionInterface>> $typeExtensions
* @param array<ExporterTypeInterface> $types
* @param array<ExporterTypeExtensionInterface>|array<string, array<ExporterTypeExtensionInterface>> $typeExtensions
*/
public function __construct(
private readonly array $types = [],
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/PreloadedDataTableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class PreloadedDataTableExtension extends AbstractDataTableExtension
{
/**
* @param array<DataTableTypeInterface> $types
* @param array<string, array<DataTableTypeExtensionInterface>> $typeExtensions
* @param array<DataTableTypeInterface> $types
* @param array<DataTableTypeExtensionInterface>|array<string, array<DataTableTypeExtensionInterface>> $typeExtensions
*/
public function __construct(
private readonly array $types = [],
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/Extension/PreloadedFilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class PreloadedFilterExtension extends AbstractFilterExtension
{
/**
* @param array<FilterTypeInterface> $types
* @param array<string, array<FilterTypeExtensionInterface>> $typeExtensions
* @param array<FilterTypeInterface> $types
* @param array<FilterTypeExtensionInterface>|array<string, array<FilterTypeExtensionInterface>> $typeExtensions
*/
public function __construct(
private readonly array $types = [],
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Type/SearchFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function configureOptions(OptionsResolver $resolver): void

public function handle(ProxyQueryInterface $query, FilterData $data, FilterInterface $filter): void
{
$filter->getOption('handler')($query, (string) $data->getValue(), $filter);
$filter->getConfig()->getOption('handler')($query, (string) $data->getValue(), $filter);
}
}
2 changes: 1 addition & 1 deletion src/Type/DataTableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private function createExportValueRowsViews(DataTableView $view, DataTableInterf
$valueRowView = new ValueRowView($view, $index, $data);

foreach ($columns as $column) {
$valueRowView->children[$column->getName()] = $column->createValueView($valueRowView);
$valueRowView->children[$column->getName()] = $column->createExportValueView($valueRowView);
}

yield $valueRowView;
Expand Down
7 changes: 7 additions & 0 deletions src/Type/ResolvedDataTableTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function createBuilder(DataTableFactoryInterface $factory, string $name,

public function createView(DataTableInterface $dataTable): DataTableView;

public function createExportView(DataTableInterface $dataTable): DataTableView;

/**
* @param array<string, mixed> $options
*/
Expand All @@ -42,5 +44,10 @@ public function buildDataTable(DataTableBuilderInterface $builder, array $option
*/
public function buildView(DataTableView $view, DataTableInterface $dataTable, array $options): void;

/**
* @param array<string, mixed> $options
*/
public function buildExportView(DataTableView $view, DataTableInterface $dataTable, array $options): void;

public function getOptionsResolver(): OptionsResolver;
}
4 changes: 3 additions & 1 deletion tests/Unit/Filter/FilterRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public function testCallingGetTypeWithNonExistentClassThrowsException(): void
{
$this->expectExceptionObject(new InvalidArgumentException('Could not load filter type "App\\InvalidFilterType": class does not exist.'));

// @phpstan-ignore-next-line
$this->createRegistry()->getType('App\\InvalidFilterType');
}

public function testCallingGetTypeWithInvalidClassThrowsException(): void
{
$this->expectExceptionObject(new InvalidArgumentException(sprintf('Could not load filter type "%s": class does not implement "%s".', FilterRegistry::class, FilterTypeInterface::class)));

// @phpstan-ignore-next-line
$this->createRegistry()->getType(FilterRegistry::class);
}

Expand Down Expand Up @@ -80,7 +82,7 @@ public function testGetTypeResolvesParentUsingExtension(): void
$resolvedFilterTypeFactory
->expects($matcher = $this->exactly(2))
->method('createResolvedType')
->willReturnCallback(function ($type, $typeExtensions, $parent) use ($matcher, $filterTypeExtension, $parentFilterType) {
->willReturnCallback(function ($type, $typeExtensions, $parent) use ($matcher, $filterTypeExtension) {
// @phpstan-ignore-next-line
match ($matcher->numberOfInvocations()) {
1 => $this->assertInstanceOf(FilterType::class, $type),
Expand Down

0 comments on commit e351b38

Please sign in to comment.