diff --git a/.github/workflows/codesniffer.yml b/.github/workflows/codesniffer.yml index 429610ad0..60ccf9258 100644 --- a/.github/workflows/codesniffer.yml +++ b/.github/workflows/codesniffer.yml @@ -14,4 +14,4 @@ jobs: name: "Codesniffer" uses: contributte/.github/.github/workflows/codesniffer.yml@v1 with: - php: "8.1" + php: "8.2" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 995e29439..bd2a484af 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -14,7 +14,7 @@ jobs: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1 with: - php: "8.1" + php: "8.2" database: tests coverage: true makefile: coverage diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 69fdbbea9..131be8ea9 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -14,4 +14,4 @@ jobs: name: "Phpstan" uses: contributte/.github/.github/workflows/phpstan.yml@v1 with: - php: "8.1" + php: "8.2" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a6f8382c3..4cf547523 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,31 +10,23 @@ on: - cron: "0 8 * * 1" jobs: - test81: - name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1 - with: - php: "8.1" - database: tests - - test80: + test82: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1 with: - php: "8.0" - database: tests + php: "8.2" + database: tests - test74: + test81: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1 with: - php: "7.4" + php: "8.1" database: tests - test74-lower: + test80: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1 with: - php: "7.4" - composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" + php: "8.0" database: tests diff --git a/Makefile b/Makefile index 4bf15899e..91465024a 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ csf: vendor/bin/phpcbf --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=tests/tmp --colors -nsp src tests phpstan: - vendor/bin/phpstan analyse -c phpstan.neon + vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=4G tests: vendor/bin/tester -s -p php --colors 1 -C tests/Cases diff --git a/composer.json b/composer.json index 74a93d004..371f46e78 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ } }, "require": { - "php": ">=7.2", + "php": ">=8.0", "contributte/application": "^0.5.0", "nette/di": "^3.0.0", "nette/forms": "^3.1.3", @@ -42,19 +42,20 @@ "symfony/property-access": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0" }, "require-dev": { + "contributte/qa": "^0.3.0", "dibi/dibi": "^3.0.0 || ^4.0.0", + "doctrine/annotations": "^1.12.1", "doctrine/cache": "^1.11.0", "doctrine/orm": "^2.11.1", - "doctrine/annotations": "^1.12.1", "elasticsearch/elasticsearch": "^7.1", - "contributte/code-rules": "^1.1.0", "mockery/mockery": "^1.3.3", "nette/database": "^3.0.2", "nette/tester": "^2.3.4", "nextras/dbal": "^3.0.1 || ^4.0", "nextras/orm": "^3.1.0 || ^4.0", - "ninjify/coding-standard": "^0.12.1", + "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-nette": "^1.0.0", + "phpstan/phpstan-strict-rules": "^1.4", "tharos/leanmapper": "^3.4.2 || ^4.0.0", "tracy/tracy": "^2.6.3" }, @@ -69,7 +70,7 @@ }, "extra": { "branch-alias": { - "dev-master": "6.10.x-dev" + "dev-master": "7.x-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 2c2f287a4..3ea0babd2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,8 @@ includes: - - ./vendor/contributte/code-rules/paveljanda/phpstan.neon - - ./vendor/phpstan/phpstan-nette/extension.neon - - ./vendor/phpstan/phpstan-nette/rules.neon +# - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-nette/extension.neon + - vendor/phpstan/phpstan-nette/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: level: 8 @@ -9,7 +10,8 @@ parameters: paths: - src - reportMaybesInPropertyPhpDocTypes: false + checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false ignoreErrors: - @@ -20,10 +22,6 @@ parameters: message: '/^Instanceof between Ublaboo\\DataGrid\\Filter\\Filter and Ublaboo\\DataGrid\\Filter\\FilterDateRange will always evaluate to false\.$/' count: 1 path: src/DataGrid.php - - - message: '/^Class dibi referenced with incorrect case\: Dibi\.$/' - count: 1 - path: src/DataModel.php - message: '/^Call to an undefined method Nextras\\Orm\\Collection\\ICollection\:\:getQueryBuilder\(\)\.$/' count: 2 diff --git a/ruleset.xml b/ruleset.xml index 72336d57d..078f8886d 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,17 +1,14 @@ - - - - - - - - - - - + + + + + + + + @@ -25,21 +22,25 @@ - - - - - - - - - - - - tests/Cases/DataSources/NextrasDataSourceTest.phpt tests/Cases/DataSources/DoctrineDataSourceTest.phpt + + + *tests/Cases/* + + + + *tests/Cases/* + + + + *tests/Cases/* + + + + *tests/Cases/* + diff --git a/src/AggregationFunction/FunctionSum.php b/src/AggregationFunction/FunctionSum.php index a5e800da1..849010c1b 100644 --- a/src/AggregationFunction/FunctionSum.php +++ b/src/AggregationFunction/FunctionSum.php @@ -1,6 +1,4 @@ -column = $column; - $this->dataType = $dataType; + public function __construct(protected string $column, protected string $dataType = IAggregationFunction::DATA_TYPE_PAGINATED) + { } - public function getFilterDataType(): string { return $this->dataType; } - - /** - * @param Fluent|QueryBuilder|Collection|Selection|ICollection $dataSource - */ - public function processDataSource($dataSource): void + public function processDataSource(Fluent|QueryBuilder|Collection|Selection|ICollection $dataSource): void { if ($dataSource instanceof Fluent) { $connection = $dataSource->getConnection(); @@ -65,7 +37,7 @@ public function processDataSource($dataSource): void } if ($dataSource instanceof QueryBuilder) { - $column = Strings::contains($this->column, '.') + $column = str_contains($this->column, '.') ? $this->column : current($dataSource->getRootAliases()) . '.' . $this->column; @@ -85,17 +57,13 @@ public function processDataSource($dataSource): void }); } - if ( $dataSource instanceof DbalCollection) { - foreach( $dataSource->fetchAll() as $item ) - $this->result += $item->getValue( $this->column ); + if ($dataSource instanceof DbalCollection) { + foreach ($dataSource->fetchAll() as $item) + $this->result += $item->getValue($this->column); } } - - /** - * @return mixed - */ - public function renderResult() + public function renderResult(): mixed { $result = $this->result; @@ -106,7 +74,6 @@ public function renderResult() return $result; } - /** * @return static */ @@ -116,4 +83,5 @@ public function setRenderer(?callable $callback = null): self return $this; } + } diff --git a/src/AggregationFunction/IAggregatable.php b/src/AggregationFunction/IAggregatable.php index 79b8c6382..5872a37f2 100644 --- a/src/AggregationFunction/IAggregatable.php +++ b/src/AggregationFunction/IAggregatable.php @@ -1,6 +1,4 @@ -aggregationFunctions !== [] || $this->multipleAggregationFunction !== null; } - /** * @return array */ @@ -177,9 +164,9 @@ public function getAggregationFunctions(): array return $this->aggregationFunctions; } - public function getMultipleAggregationFunction(): ?IMultipleAggregationFunction { return $this->multipleAggregationFunction; } + } diff --git a/src/Column/Action.php b/src/Column/Action.php index 6107c5e55..236b7176b 100644 --- a/src/Column/Action.php +++ b/src/Column/Action.php @@ -1,6 +1,4 @@ -href = $href; - $this->params = $params; $this->class = sprintf('btn btn-xs %s', $grid::$btnSecondaryClass); } - - /** - * @return mixed - */ - public function render(Row $row) + public function render(Row $row): mixed { if (!$this->shouldBeRendered($row)) { return null; @@ -108,7 +68,8 @@ public function render(Row $row) try { return $this->useRenderer($row); - } catch (DataGridColumnRendererException $e) { + } catch (DataGridColumnRendererException) { + // No need to worry. } $link = $this->createLink( @@ -156,7 +117,6 @@ public function render(Row $row) return $a; } - /** * @return static */ @@ -167,13 +127,11 @@ public function addParameters(array $parameters): self return $this; } - /** - * @param string|callable $title * @return static * @throws DataGridException */ - public function setTitle($title): self + public function setTitle(string|callable $title): self { $this->checkPropertyStringOrCallable($title, 'title'); @@ -182,7 +140,6 @@ public function setTitle($title): self return $this; } - /** * @throws DataGridException */ @@ -194,13 +151,11 @@ public function getTitle(Row $row): ?string return $this->getPropertyStringOrCallableGetString($row, $this->title, 'title'); } - /** - * @param string|callable $class * @return static * @throws DataGridException */ - public function setClass($class): self + public function setClass(null|string|callable $class): self { $this->checkPropertyStringOrCallable($class, 'class'); @@ -209,7 +164,6 @@ public function setClass($class): self return $this; } - /** * @throws DataGridException */ @@ -221,13 +175,11 @@ public function getClass(Row $row): ?string return $this->getPropertyStringOrCallableGetString($row, $this->class, 'class'); } - /** - * @param string|callable $icon * @return static * @throws DataGridException */ - public function setIcon($icon): self + public function setIcon(string|callable $icon): self { $this->checkPropertyStringOrCallable($icon, 'icon'); @@ -236,7 +188,6 @@ public function setIcon($icon): self return $this; } - /** * @throws DataGridException */ @@ -248,7 +199,6 @@ public function getIcon(Row $row): ?string return $this->getPropertyStringOrCallableGetString($row, $this->icon, 'icon'); } - /** * @return static */ @@ -259,7 +209,6 @@ public function setConfirmation(IConfirmation $confirmation): self return $this; } - /** * @throws DataGridException */ @@ -290,19 +239,16 @@ public function getConfirmationDialog(Row $row): ?string throw new DataGridException('Unsupported confirmation'); } - /** - * @param mixed $value * @return static */ - public function setDataAttribute(string $key, $value): self + public function setDataAttribute(string $key, mixed $value): self { $this->dataAttributes[$key] = $value; return $this; } - /** * @return static */ @@ -313,14 +259,12 @@ public function addAttributes(array $attrs): self return $this; } - /** - * @param string|callable|null $property * @throws DataGridException */ public function getPropertyStringOrCallableGetString( Row $row, - $property, + string|callable|null $property, string $name ): ?string { @@ -332,7 +276,7 @@ public function getPropertyStringOrCallableGetString( $value = call_user_func($property, $row->getItem()); if (!is_string($value)) { - throw new DataGridException("Action {$name} callback has to return a string"); + throw new DataGridException(sprintf('Action %s callback has to return a string', $name)); } return $value; @@ -341,13 +285,11 @@ public function getPropertyStringOrCallableGetString( return $property; } - public function isOpenInNewTab(): bool { return $this->openInNewTab; } - /** * @return static */ @@ -358,12 +300,10 @@ public function setOpenInNewTab(bool $openInNewTab = true): self return $this; } - /** - * @param mixed $property * @throws DataGridException */ - protected function checkPropertyStringOrCallable($property, string $name): void + protected function checkPropertyStringOrCallable(mixed $property, string $name): void { if (!is_string($property) && !is_callable($property) && $property !== null) { throw new DataGridException( @@ -372,9 +312,9 @@ protected function checkPropertyStringOrCallable($property, string $name): void } } - protected function translate(string $message): string { return $this->grid->getTranslator()->translate($message); } + } diff --git a/src/Column/Action/Confirmation/CallbackConfirmation.php b/src/Column/Action/Confirmation/CallbackConfirmation.php index 911dcb3a4..2c662b163 100644 --- a/src/Column/Action/Confirmation/CallbackConfirmation.php +++ b/src/Column/Action/Confirmation/CallbackConfirmation.php @@ -1,26 +1,21 @@ -callback = $callback; } - public function getCallback(): callable { return $this->callback; } + } diff --git a/src/Column/Action/Confirmation/IConfirmation.php b/src/Column/Action/Confirmation/IConfirmation.php index 942f34346..d180a701b 100644 --- a/src/Column/Action/Confirmation/IConfirmation.php +++ b/src/Column/Action/Confirmation/IConfirmation.php @@ -1,6 +1,4 @@ -question = $question; - $this->placeholderName = $placeholderName; } - public function getQuestion(): string { return $this->question; } - public function getPlaceholderName(): ?string { return $this->placeholderName; } + } diff --git a/src/Column/ActionCallback.php b/src/Column/ActionCallback.php index 68b339f2e..2382f07ba 100644 --- a/src/Column/ActionCallback.php +++ b/src/Column/ActionCallback.php @@ -1,6 +1,4 @@ -grid->link('actionCallback!', $params); } + } diff --git a/src/Column/Column.php b/src/Column/Column.php index e7e4f7efb..8e443533c 100644 --- a/src/Column/Column.php +++ b/src/Column/Column.php @@ -1,6 +1,4 @@ - 'form-control']]; + /** @var array */ + protected array $editableElement = ['textarea', ['class' => 'form-control']]; - /** - * @var bool - */ - protected $defaultHide = false; + protected bool $defaultHide = false; - /** - * @var array|Html[]|null[] - */ - protected $elementCache = ['td' => null, 'th' => null]; + /** @var array|Html[]|null[] */ + protected array $elementCache = ['td' => null, 'th' => null]; - /** - * @var callable|null - */ + /** @var callable|null */ protected $editableValueCallback = null; - /** - * @return mixed - */ - public function render(Row $row) + public function render(Row $row): mixed { try { return $this->useRenderer($row); - } catch (DataGridColumnRendererException $e) { + } catch (DataGridColumnRendererException) { /** * Do not use renderer */ @@ -121,7 +75,6 @@ public function render(Row $row) return $this->getColumnValue($row); } - /** * Should be column values escaped in latte? * @@ -134,13 +87,11 @@ public function setTemplateEscaping(bool $templateEscaping = true): self return $this; } - public function isTemplateEscaped(): bool { return $this->templateEscaping; } - /** * Should be column header escaped in latte? * @@ -153,20 +104,17 @@ public function setHeaderEscaping(bool $headerEscaping = false): self return $this; } - public function isHeaderEscaped(): bool { return $this->headerEscaping; } - /** * Set column sortable or not * - * @param bool|string $sortable * @return static */ - public function setSortable($sortable = true): self + public function setSortable(bool|string $sortable = true): self { $this->sortable = is_string($sortable) ? $sortable @@ -175,7 +123,6 @@ public function setSortable($sortable = true): self return $this; } - /** * Tell whether column is sortable */ @@ -188,7 +135,6 @@ public function isSortable(): bool return $this->sortable !== ''; } - /** * Set column translatable or not * @@ -201,7 +147,6 @@ public function setTranslatableHeader(bool $translatableHeader = true): self return $this; } - /** * Tell wheter column is translatable */ @@ -210,7 +155,6 @@ public function isTranslatableHeader(): bool return $this->translatableHeader; } - /** * Shoud be the pagination reseted after sorting? * @@ -223,7 +167,6 @@ public function setSortableResetPagination(bool $sortableResetPagination = true) return $this; } - /** * Do reset pagination after sorting? */ @@ -232,7 +175,6 @@ public function sortableResetPagination(): bool return $this->sortableResetPagination; } - /** * Set custom ORDER BY clause * @@ -245,7 +187,6 @@ public function setSortableCallback(callable $sortableCallback): self return $this; } - /** * Get custom ORDER BY clause */ @@ -254,7 +195,6 @@ public function getSortableCallback(): ?callable return $this->sortableCallback; } - public function getSortingColumn(): string { return is_string($this->sortable) @@ -262,28 +202,21 @@ public function getSortingColumn(): string : $this->column; } - public function getColumnName(): string { return $this->column; } - - /** - * @return mixed - */ - public function getColumnValue(Row $row) + public function getColumnValue(Row $row): mixed { return $row->getValue($this->column); } - public function getName(): string { return $this->name; } - /** * Column may have its own template * @@ -297,7 +230,6 @@ public function setTemplate(?string $template, array $templateVariables = []): s return $this; } - /** * Column can have variables that will be passed to custom template scope */ @@ -306,7 +238,6 @@ public function getTemplateVariables(): array return $this->templateVariables; } - /** * Tell whether column has its owntemplate */ @@ -315,7 +246,6 @@ public function hasTemplate(): bool return $this->template !== null; } - /** * Get column template path */ @@ -324,7 +254,6 @@ public function getTemplate(): ?string return $this->template; } - /** * Tell whether data source is sorted by this column */ @@ -333,7 +262,6 @@ public function isSortedBy(): bool return (bool) $this->sort; } - /** * Tell column his sorting options * @@ -346,7 +274,6 @@ public function setSort(string $sort): self return $this; } - /** * What sorting will be applied after next click? */ @@ -365,7 +292,6 @@ public function getSortNext(): array return [$this->key => 'ASC']; } - public function hasSortNext(): bool { foreach ($this->getSortNext() as $order) { @@ -375,13 +301,11 @@ public function hasSortNext(): bool return false; } - public function isSortAsc(): bool { return $this->sort === 'ASC'; } - /** * Set column alignment * @@ -394,7 +318,6 @@ public function setAlign(string $align): self return $this; } - /** * Has column some alignment? */ @@ -403,7 +326,6 @@ public function hasAlign(): bool return (bool) $this->align; } - /** * Get column alignment */ @@ -412,7 +334,6 @@ public function getAlign(): string return $this->align ?? 'left'; } - /** * @return static */ @@ -425,7 +346,6 @@ public function setFitContent(bool $fitContent = true): self return $this; } - /** * Set callback that will be called after inline editing * @@ -438,7 +358,6 @@ public function setEditableCallback(callable $editableCallback): self return $this; } - /** * Return callback that is used after inline editing */ @@ -447,7 +366,6 @@ public function getEditableCallback(): ?callable return $this->editableCallback; } - /** * Set inline editing just if condition is truthy * @@ -460,13 +378,11 @@ public function setEditableOnConditionCallback(callable $editableConditionCallba return $this; } - public function getEditableOnConditionCallback(): ?callable { return $this->editableConditionCallback; } - public function isEditable(?Row $row = null): bool { if ($this->getEditableCallback() !== null) { @@ -484,7 +400,6 @@ public function isEditable(?Row $row = null): bool return false; } - /** * Element is by default textarea, user can change that * @@ -497,7 +412,6 @@ public function setEditableInputType(string $elType, array $attrs = []): self return $this; } - /** * Change small inline edit input type to select * @@ -518,7 +432,6 @@ public function setEditableInputTypeSelect(array $options = [], array $attrs = [ return $this->setEditableInputType('select', $attrs); } - /** * @return static */ @@ -529,19 +442,16 @@ public function setEditableValueCallback(callable $editableValueCallback): self return $this; } - public function getEditableValueCallback(): ?callable { return $this->editableValueCallback; } - public function getEditableInputType(): array { return $this->editableElement; } - /** * Set attributes for both th and td element * @@ -555,7 +465,6 @@ public function addCellAttributes(array $attrs): self return $this; } - /** * Get th/td column element */ @@ -568,7 +477,6 @@ public function getElementPrototype(string $tag): Html return $this->elementCache[$tag] = Html::el($tag); } - /** * Method called from datagrid template, set appropriate classes and another attributes */ @@ -597,7 +505,7 @@ public function getElementForRender(string $tag, string $key, ?Row $row = null): $el->data('datagrid-editable-url', $link); $el->data('datagrid-editable-type', $this->editableElement[0]); - $el->data('datagrid-editable-attrs', json_encode($this->editableElement[1])); + $el->data('datagrid-editable-attrs', json_encode($this->editableElement[1], JSON_THROW_ON_ERROR)); if ($this->getEditableValueCallback() !== null) { $el->data( @@ -610,7 +518,6 @@ public function getElementForRender(string $tag, string $key, ?Row $row = null): return $el; } - /** * @return static */ @@ -625,13 +532,11 @@ public function setDefaultHide(bool $defaultHide = true): self return $this; } - public function getDefaultHide(): bool { return $this->defaultHide; } - public function getColumn(): string { return $this->column; @@ -647,7 +552,6 @@ public function setReplacement(array $replacements): self return $this; } - /** * Get row item params (E.g. action may be called id => $item->id, name => $item->name, ...) */ @@ -661,4 +565,5 @@ protected function getItemParams(Row $row, array $paramsList): array return $return; } + } diff --git a/src/Column/ColumnDateTime.php b/src/Column/ColumnDateTime.php index 212846629..3570581ca 100644 --- a/src/Column/ColumnDateTime.php +++ b/src/Column/ColumnDateTime.php @@ -1,6 +1,4 @@ -format($this->format); - } catch (DataGridDateTimeHelperException $e) { + } catch (DataGridDateTimeHelperException) { /** * Otherwise just return raw string */ @@ -45,7 +37,6 @@ public function getColumnValue(Row $row): string return $value->format($this->format); } - /** * @return static */ @@ -55,4 +46,5 @@ public function setFormat(string $format): self return $this; } + } diff --git a/src/Column/ColumnLink.php b/src/Column/ColumnLink.php index 3e3ccd045..6d465c9ff 100644 --- a/src/Column/ColumnLink.php +++ b/src/Column/ColumnLink.php @@ -1,6 +1,4 @@ -href = $href; - $this->params = $params; } - - /** - * @return mixed - */ - public function render(Row $row) + public function render(Row $row): mixed { /** * Renderer function may be used */ try { return $this->useRenderer($row); - } catch (DataGridColumnRendererException $e) { + } catch (DataGridColumnRendererException) { /** * Do not use renderer */ @@ -137,7 +101,6 @@ public function render(Row $row) return $element; } - /** * @return static */ @@ -148,7 +111,6 @@ public function addParameters(array $parameters): self return $this; } - /** * @return static */ @@ -159,19 +121,16 @@ public function setIcon(?string $icon = null): self return $this; } - /** - * @param mixed $value * @return static */ - public function setDataAttribute(string $key, $value): self + public function setDataAttribute(string $key, mixed $value): self { $this->dataAttributes[$key] = $value; return $this; } - /** * @return static */ @@ -182,13 +141,11 @@ public function setTitle(string $title): self return $this; } - public function getTitle(): ?string { return $this->title; } - /** * @return static */ @@ -199,19 +156,16 @@ public function setClass(?string $class): self return $this; } - public function getClass(): ?string { return $this->class; } - public function isOpenInNewTab(): bool { return $this->openInNewTab; } - /** * @return static */ @@ -221,4 +175,5 @@ public function setOpenInNewTab(bool $openInNewTab = true): self return $this; } + } diff --git a/src/Column/ColumnNumber.php b/src/Column/ColumnNumber.php index c2b6a9611..1db19893d 100644 --- a/src/Column/ColumnNumber.php +++ b/src/Column/ColumnNumber.php @@ -1,6 +1,4 @@ -numberFormat[2], ]; } + } diff --git a/src/Column/ColumnStatus.php b/src/Column/ColumnStatus.php index d013e33fd..ae14f0e46 100644 --- a/src/Column/ColumnStatus.php +++ b/src/Column/ColumnStatus.php @@ -1,6 +1,4 @@ -setTemplate(__DIR__ . '/../templates/column_status.latte'); } - public function getKey(): string { return $this->key; } - public function getOptions(): array { return $this->options; } - /** - * @param mixed $value * @throws DataGridColumnStatusException */ - public function getOption($value): Option + public function getOption(mixed $value): Option { foreach ($this->options as $option) { if ($option->getValue() === $value) { @@ -77,16 +63,14 @@ public function getOption($value): Option } } - throw new DataGridColumnStatusException("Option [$value] does not exist"); + throw new DataGridColumnStatusException(sprintf('Option [%s] does not exist', $value)); } - public function getColumn(): string { return $this->column; } - /** * Find selected option for current item/row */ @@ -101,12 +85,10 @@ public function getCurrentOption(Row $row): ?Option return null; } - /** - * @param mixed $value * @throws DataGridColumnStatusException */ - public function addOption($value, string $text): Option + public function addOption(mixed $value, string $text): Option { if (!is_scalar($value)) { throw new DataGridColumnStatusException('Option value has to be scalar'); @@ -119,7 +101,6 @@ public function addOption($value, string $text): Option return $option; } - /** * Set all options at once * @@ -134,11 +115,7 @@ public function setOptions(array $options): self return $this; } - - /** - * @param mixed $value - */ - public function removeOption($value): void + public function removeOption(mixed $value): void { foreach ($this->options as $key => $option) { if ($option->getValue() === $value) { @@ -147,7 +124,6 @@ public function removeOption($value): void } } - /** * Column can have variables that will be passed to custom template scope */ @@ -161,11 +137,11 @@ public function getTemplateVariables(): array ]); } - public function setReplacement(array $replacements): Column { throw new DataGridColumnStatusException( 'Cannot set replacement for Column Status. For status texts replacement use ->setOptions($replacements)' ); } + } diff --git a/src/Column/ColumnText.php b/src/Column/ColumnText.php index 2d34e188c..198f9c0fe 100644 --- a/src/Column/ColumnText.php +++ b/src/Column/ColumnText.php @@ -1,6 +1,4 @@ -grid = $grid; - $this->key = $key; - $this->column = $column; - $this->name = $name; } - - /** - * @param string|array|null $columns - */ - public function setFilterText($columns = null): FilterText + public function setFilterText(string|array|null $columns = null): FilterText { if ($columns === null) { $columns = [$this->column]; @@ -66,55 +30,51 @@ public function setFilterText($columns = null): FilterText return $this->grid->addFilterText($this->key, $this->name, $columns); } - public function setFilterSelect( array $options, ?string $column = null ): FilterSelect { - $column = $column ?? $this->column; + $column ??= $this->column; return $this->grid->addFilterSelect($this->key, $this->name, $options, $column); } - public function setFilterMultiSelect( array $options, ?string $column = null ): FilterMultiSelect { - $column = $column ?? $this->column; + $column ??= $this->column; return $this->grid->addFilterMultiSelect($this->key, $this->name, $options, $column); } - public function setFilterDate(?string $column = null): FilterDate { - $column = $column ?? $this->column; + $column ??= $this->column; return $this->grid->addFilterDate($this->key, $this->name, $column); } - public function setFilterRange( ?string $column = null, string $nameSecond = '-' ): FilterRange { - $column = $column ?? $this->column; + $column ??= $this->column; return $this->grid->addFilterRange($this->key, $this->name, $column, $nameSecond); } - public function setFilterDateRange( ?string $column = null, string $nameSecond = '-' ): FilterDateRange { - $column = $column ?? $this->column; + $column ??= $this->column; return $this->grid->addFilterDateRange($this->key, $this->name, $column, $nameSecond); } + } diff --git a/src/Column/ItemDetail.php b/src/Column/ItemDetail.php index 563009b21..813d5e5f4 100644 --- a/src/Column/ItemDetail.php +++ b/src/Column/ItemDetail.php @@ -1,6 +1,4 @@ -grid = $grid; - $this->primaryWhereColumn = $primaryWhereColumn; - $this->title = 'ublaboo_datagrid.show'; $this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass); $this->icon = 'eye'; } - /** * Render row item detail button */ @@ -98,19 +68,14 @@ public function renderButton(Row $row): Html ); } - if ($this->class !== null) { + if ($this->class !== '') { $a->setAttribute('class', $this->class); } return $a; } - - /** - * @param mixed $item - * @return mixed - */ - public function render($item) + public function render(mixed $item): mixed { if ($this->getType() === 'block') { throw new DataGridItemDetailException('ItemDetail is set to render as block, but block #detail is not defined'); @@ -123,13 +88,11 @@ public function render($item) return call_user_func($this->getRenderer(), $item); } - public function getPrimaryWhereColumn(): string { return $this->primaryWhereColumn; } - /** * Set item detail type * @@ -142,7 +105,6 @@ public function setType(string $type): self return $this; } - /** * Get item detail type */ @@ -151,7 +113,6 @@ public function getType(): ?string return $this->type; } - /** * Set item detail template * @@ -164,7 +125,6 @@ public function setTemplate(string $template): self return $this; } - /** * Get item detail template */ @@ -173,7 +133,6 @@ public function getTemplate(): ?string return $this->template; } - /** * @return static */ @@ -184,13 +143,11 @@ public function setRenderer(callable $renderer): self return $this; } - public function getRenderer(): ?callable { return $this->renderer; } - /** * @return static */ @@ -201,13 +158,11 @@ public function setForm(ItemDetailForm $form): self return $this; } - public function getForm(): ?ItemDetailForm { return $this->form; } - /** * @return static */ @@ -218,7 +173,6 @@ public function setTemplateParameters(array $templateParameters): self return $this; } - public function getTemplateVariables(): array { return $this->templateParameters; diff --git a/src/Column/MultiAction.php b/src/Column/MultiAction.php index 0770e0db5..1ec71398e 100644 --- a/src/Column/MultiAction.php +++ b/src/Column/MultiAction.php @@ -1,6 +1,4 @@ -setTemplate(__DIR__ . '/../templates/column_multi_action.latte'); } - public function renderButton(): Html { $button = Html::el('button') @@ -85,7 +71,6 @@ public function renderButton(): Html return $button; } - /** * @return static */ @@ -102,7 +87,7 @@ public function addAction( ); } - $href = $href ?? $key; + $href ??= $key; if ($params === null) { $params = [$this->grid->getPrimaryKey()]; @@ -117,7 +102,6 @@ public function addAction( return $this; } - /** * @return array */ @@ -126,7 +110,6 @@ public function getActions(): array return $this->actions; } - public function getAction(string $key): Action { if (!isset($this->actions[$key])) { @@ -138,7 +121,6 @@ public function getAction(string $key): Action return $this->actions[$key]; } - /** * Column can have variables that will be passed to custom template scope */ @@ -149,7 +131,6 @@ public function getTemplateVariables(): array ]); } - public function setRowCondition( string $actionKey, callable $rowCondition @@ -158,7 +139,6 @@ public function setRowCondition( $this->rowConditions[$actionKey] = $rowCondition; } - public function testRowCondition(string $actionKey, Row $row): bool { if (!isset($this->rowConditions[$actionKey])) { @@ -167,4 +147,5 @@ public function testRowCondition(string $actionKey, Row $row): bool return (bool) call_user_func($this->rowConditions[$actionKey], $row->getItem()); } + } diff --git a/src/Column/Renderer.php b/src/Column/Renderer.php index 70b168ed6..18d25893c 100644 --- a/src/Column/Renderer.php +++ b/src/Column/Renderer.php @@ -1,23 +1,16 @@ -conditionCallback = $conditionCallback; } - /** * Get custom renderer callback */ @@ -36,7 +28,6 @@ public function getCallback(): callable return $this->callback; } - /** * Get custom renderer condition callback */ @@ -44,4 +35,5 @@ public function getConditionCallback(): ?callable { return $this->conditionCallback; } + } diff --git a/src/ColumnsSummary.php b/src/ColumnsSummary.php index efa9e69a7..defd334af 100644 --- a/src/ColumnsSummary.php +++ b/src/ColumnsSummary.php @@ -1,6 +1,4 @@ -summary = array_fill_keys(array_values($columns), 0); - $this->datagrid = $datagrid; $this->rowCallback = $rowCallback; foreach (array_keys($this->summary) as $key) { @@ -67,7 +47,6 @@ public function __construct( } } - public function add(Row $row): void { foreach (array_keys($this->summary) as $key) { @@ -78,12 +57,12 @@ public function add(Row $row): void } } - public function render(string $key): ?string { try { return $this->useRenderer($key); - } catch (DataGridColumnRendererException $e) { + } catch (DataGridColumnRendererException) { + // No need to worry. } if (!isset($this->summary[$key])) { @@ -98,11 +77,7 @@ public function render(string $key): ?string ); } - - /** - * @return mixed - */ - public function useRenderer(string $key) + public function useRenderer(string $key): mixed { if (!isset($this->summary[$key])) { return null; @@ -111,19 +86,17 @@ public function useRenderer(string $key) $renderer = $this->getRenderer(); if ($renderer === null) { - throw new DataGridColumnRendererException; + throw new DataGridColumnRendererException(); } return call_user_func_array($renderer->getCallback(), [$this->summary[$key], $key]); } - public function getRenderer(): ?Renderer { return $this->renderer; } - /** * @return static */ @@ -134,7 +107,6 @@ public function setRenderer(callable $renderer): self return $this; } - /** * @return static */ @@ -150,7 +122,6 @@ public function setFormat( return $this; } - public function someColumnsExist(array $columns): bool { foreach (array_keys($columns) as $key) { @@ -162,7 +133,6 @@ public function someColumnsExist(array $columns): bool return false; } - /** * @return static */ @@ -173,19 +143,15 @@ public function setPositionTop(bool $top = true): self return $this; } - public function getPositionTop(): bool { return $this->positionTop; } - /** * Get value from column using Row::getValue() or custom callback - * - * @return mixed */ - private function getValue(Row $row, Column $column) + private function getValue(Row $row, Column $column): mixed { if ($this->rowCallback === null) { return $row->getValue($column->getColumn()); @@ -193,4 +159,5 @@ private function getValue(Row $row, Column $column) return call_user_func_array($this->rowCallback, [$row->getItem(), $column->getColumn()]); } + } diff --git a/src/Components/DataGridPaginator/DataGridPaginator.php b/src/Components/DataGridPaginator/DataGridPaginator.php index ee4c5c39d..a82bce529 100644 --- a/src/Components/DataGridPaginator/DataGridPaginator.php +++ b/src/Components/DataGridPaginator/DataGridPaginator.php @@ -1,6 +1,4 @@ -translator = $translator; - $this->iconPrefix = $iconPrefix; - $this->btnSecondaryClass = $btnSecondaryClass; + public function __construct(private ITranslator $translator, private string $iconPrefix = 'fa fa-', private string $btnSecondaryClass = 'btn-default btn-secondary') + { } - public function setTemplateFile(string $templateFile): void { $this->templateFile = $templateFile; } - public function getTemplateFile(): string { return $this->templateFile ?? __DIR__ . '/templates/data_grid_paginator.latte'; } - public function getOriginalTemplateFile(): string { return __DIR__ . '/templates/data_grid_paginator.latte'; } - public function getPaginator(): Paginator { if ($this->paginator === null) { @@ -88,7 +54,6 @@ public function getPaginator(): Paginator return $this->paginator; } - public function render(): void { $paginator = $this->getPaginator(); @@ -101,10 +66,8 @@ public function render(): void $arr = range(max($paginator->firstPage, $page - 2), (int) min($paginator->lastPage, $page + 2)); /** - * Something to do with steps in tempale... + * Something to do with steps in template... * [Default $count = 3;] - * - * @var int */ $count = 1; @@ -141,7 +104,6 @@ public function render(): void $this->getTemplate()->render(); } - /** * Loads state informations. */ @@ -153,4 +115,5 @@ public function loadState(array $params): void $this->getPaginator()->page = $this->getParent()->page; } } + } diff --git a/src/CsvDataModel.php b/src/CsvDataModel.php index c53aca4dc..27f18fc16 100644 --- a/src/CsvDataModel.php +++ b/src/CsvDataModel.php @@ -1,6 +1,4 @@ - - */ - protected $columns; - - /** - * @var ITranslator + * @param Column[] $columns */ - protected $translator; - - - public function __construct( - array $data, - array $columns, - ITranslator $translator - ) + public function __construct(protected array $data, protected array $columns, protected ITranslator $translator) { - $this->data = $data; - $this->columns = $columns; - $this->translator = $translator; } - /** * Get data with header and "body" */ @@ -56,7 +33,6 @@ public function getSimpleData(bool $includeHeader = true): array return $return; } - public function getHeader(): array { $header = []; @@ -68,13 +44,10 @@ public function getHeader(): array return $header; } - /** * Get item values saved into row - * - * @param mixed $item */ - public function getRow($item): array + public function getRow(mixed $item): array { $row = []; diff --git a/src/DataGrid.php b/src/DataGrid.php index eead1cd20..346948e92 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -1,11 +1,10 @@ - - */ - protected $columns = []; + /** @var array */ + protected array $columns = []; - /** - * @var array|array - */ - protected $actions = []; + /** @var array|array */ + protected array $actions = []; - /** - * @var GroupActionCollection|null - */ - protected $groupActionCollection; + protected ?GroupActionCollection $groupActionCollection = null; - /** - * @var array - */ - protected $filters = []; + /** @var array */ + protected array $filters = []; - /** - * @var array - */ - protected $exports = []; + /** @var array */ + protected array $exports = []; - /** - * @var array - */ - protected $toolbarButtons = []; + /** @var array */ + protected array $toolbarButtons = []; - /** - * @var DataModel|null - */ - protected $dataModel; + protected ?DataModel $dataModel = null; - /** - * @var string - */ - protected $primaryKey = 'id'; + protected string $primaryKey = 'id'; - /** - * @var bool - */ - protected $doPaginate = true; + protected bool $doPaginate = true; - /** - * @var bool - */ - protected $csvExport = true; + protected bool $csvExport = true; - /** - * @var bool - */ - protected $csvExportFiltered = true; + protected bool $csvExportFiltered = true; - /** - * @var bool - */ - protected $sortable = false; + protected bool $sortable = false; - /** - * @var bool - */ - protected $multiSort = false; + protected bool $multiSort = false; - /** - * @var string - */ - protected $sortableHandler = 'sort!'; + protected string $sortableHandler = 'sort!'; - /** - * @var string|null - */ - protected $originalTemplate = null; + protected ?string $originalTemplate = null; - /** - * @var array - */ - protected $redrawItem = []; + /** @var array */ + protected array $redrawItem = []; - /** - * @var ITranslator|null - */ - protected $translator = null; + protected ?ITranslator $translator = null; - /** - * @var bool - */ - protected $forceFilterActive = false; + protected bool $forceFilterActive = false; - /** - * @var callable|null - */ + /** @var callable|null */ protected $treeViewChildrenCallback = null; - /** - * @var callable|null - */ + /** @var callable|null */ protected $treeViewHasChildrenCallback = null; - /** - * @var string|null - */ - protected $treeViewHasChildrenColumn = null; + protected ?string $treeViewHasChildrenColumn = null; - /** - * @var bool - */ - protected $outerFilterRendering = false; + protected bool $outerFilterRendering = false; - /** - * @var int - */ - protected $outerFilterColumnsCount = 2; + protected int $outerFilterColumnsCount = 2; - /** - * @var bool - */ - protected $collapsibleOuterFilters = true; + protected bool $collapsibleOuterFilters = true; - /** - * @var array|string[] - */ - protected $columnsExportOrder = []; + /** @var array|string[] */ + protected array $columnsExportOrder = []; - /** - * @var bool - */ - protected $rememberState = true; + protected bool $rememberState = true; - /** - * @var bool - */ - protected $rememberHideableColumnsState = true; + protected bool $rememberHideableColumnsState = true; - /** - * @var bool - */ - protected $refreshURL = true; + protected bool $refreshURL = true; - /** - * @var SessionSection - */ - protected $gridSession; + protected SessionSection $gridSession; - /** - * @var ItemDetail|null - */ - protected $itemsDetail; + protected ?ItemDetail $itemsDetail = null; - /** - * @var array - */ - protected $rowConditions = [ + /** @var array */ + protected array $rowConditions = [ 'group_action' => false, 'action' => [], ]; - /** - * @var array - */ - protected $columnCallbacks = []; + /** @var array */ + protected array $columnCallbacks = []; - /** - * @var bool - */ - protected $canHideColumns = false; + protected bool $canHideColumns = false; - /** - * @var array - */ - protected $columnsVisibility = []; + /** @var array */ + protected array $columnsVisibility = []; - /** - * @var InlineEdit|null - */ - protected $inlineEdit = null; + protected ?InlineEdit $inlineEdit = null; - /** - * @var InlineAdd|null - */ - protected $inlineAdd = null; + protected ?InlineAdd $inlineAdd = null; - /** - * @var bool - */ - protected $snippetsSet = false; - - /** - * @var bool - */ - protected $someColumnDefaultHide = false; + protected bool $snippetsSet = false; - /** - * @var ColumnsSummary|null - */ - protected $columnsSummary; + protected bool $someColumnDefaultHide = false; - /** - * @var bool - */ - protected $autoSubmit = true; + protected ?ColumnsSummary $columnsSummary = null; - /** - * @var SubmitButton|null - */ - protected $filterSubmitButton = null; + protected bool $autoSubmit = true; - /** - * @var bool - */ - protected $hasColumnReset = true; + protected ?SubmitButton $filterSubmitButton = null; - /** - * @var bool - */ - protected $showSelectedRowsCount = true; + protected bool $hasColumnReset = true; - /** - * @var string|null - */ - private $customPaginatorTemplate = null; + protected bool $showSelectedRowsCount = true; - /** - * @var string|null - */ - private $componentFullName; + private ?string $customPaginatorTemplate = null; + private ?string $componentFullName = null; public function __construct(?IContainer $parent = null, ?string $name = null) { @@ -446,7 +268,7 @@ public function __construct(?IContainer $parent = null, ?string $name = null) $parent->addComponent($this, $name); } - $this->monitor('Nette\Application\UI\Presenter'); + $this->monitor(Presenter::class); /** * Try to find previous filters, pagination, perPage and other values in session @@ -487,10 +309,10 @@ function (Presenter $presenter): void { } $this->componentFullName = $this->lookupPath(); - }); + } + ); } - /******************************************************************************** * RENDERING * ********************************************************************************/ @@ -510,7 +332,7 @@ public function render(): void $template = $this->getTemplate(); if (!$template instanceof Template) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $template->setTranslator($this->getTranslator()); @@ -525,15 +347,11 @@ public function render(): void */ $rows = []; - if ($this->redrawItem !== []) { - $items = $this->dataModel->filterRow($this->redrawItem); - } else { - $items = $this->dataModel->filterData( - $this->getPaginator(), - $this->createSorting($this->sort, $this->sortCallback), - $this->assembleFilters() - ); - } + $items = $this->redrawItem !== [] ? $this->dataModel->filterRow($this->redrawItem) : $this->dataModel->filterData( + $this->getPaginator(), + $this->createSorting($this->sort, $this->sortCallback), + $this->assembleFilters() + ); $hasGroupActionOnRows = false; @@ -637,13 +455,11 @@ public function setPrimaryKey(string $primaryKey): self return $this; } - /** - * @param mixed $source * @return static * @throws InvalidArgumentException */ - public function setDataSource($source): self + public function setDataSource(mixed $source): self { $this->dataModel = new DataModel($source, $this->primaryKey); @@ -654,11 +470,7 @@ public function setDataSource($source): self return $this; } - - /** - * @return IDataSource|array|null - */ - public function getDataSource() + public function getDataSource(): IDataSource|array|null { return isset($this->dataModel) ? $this->dataModel->getDataSource() @@ -680,13 +492,11 @@ public function setTemplateFile(string $templateFile): self return $this; } - public function getTemplateFile(): string { return $this->templateFile ?? $this->getOriginalTemplateFile(); } - public function getOriginalTemplateFile(): string { return __DIR__ . '/templates/datagrid.latte'; @@ -702,7 +512,6 @@ public function useHappyComponents(bool $useHappyComponents): self return $this; } - public function shouldUseHappyComponents(): bool { return $this->useHappyComponents; @@ -713,11 +522,10 @@ public function shouldUseHappyComponents(): bool * SORTING * ********************************************************************************/ - /** - * @param string|array $sort - * @return static - */ - public function setDefaultSort($sort, bool $useOnReset = true): self + /** + * @return static + */ + public function setDefaultSort(string|array $sort, bool $useOnReset = true): self { $sort = is_string($sort) ? [$sort => 'ASC'] @@ -729,7 +537,6 @@ public function setDefaultSort($sort, bool $useOnReset = true): self return $this; } - /** * Return default sort for column, if specified */ @@ -742,7 +549,6 @@ public function getColumnDefaultSort(string $columnKey): ?string return null; } - /** * User may set default sorting, apply it */ @@ -763,7 +569,6 @@ public function findDefaultSort(): void $this->saveSessionData('_grid_sort', $this->sort); } - /** * @return static * @throws DataGridException @@ -779,7 +584,6 @@ public function setSortable(bool $sortable = true): self return $this; } - public function isSortable(): bool { return $this->sortable; @@ -795,7 +599,6 @@ public function setMultiSortEnabled(bool $multiSort = true): self return $this; } - public function isMultiSortEnabled(): bool { return $this->multiSort; @@ -811,13 +614,11 @@ public function setSortableHandler(string $handler = 'sort!'): self return $this; } - public function getSortableHandler(): string { return $this->sortableHandler; } - public function getSortNext(Column $column): array { $sort = $column->getSortNext(); @@ -829,7 +630,6 @@ public function getSortNext(Column $column): array return array_filter($sort); } - /******************************************************************************** * TREE VIEW * ********************************************************************************/ @@ -838,14 +638,12 @@ public function isTreeView(): bool return $this->treeViewChildrenCallback !== null; } - /** - * @param string|callable $treeViewHasChildrenColumn * @return static */ public function setTreeView( callable $getChildrenCallback, - $treeViewHasChildrenColumn = 'has_children' + string|callable $treeViewHasChildrenColumn = 'has_children' ): self { if (is_callable($treeViewHasChildrenColumn)) { @@ -871,26 +669,20 @@ public function setTreeView( return $this; } - public function hasTreeViewChildrenCallback(): bool { return is_callable($this->treeViewHasChildrenCallback); } - - /** - * @param mixed $item - */ - public function treeViewChildrenCallback($item): bool + public function treeViewChildrenCallback(mixed $item): bool { if ($this->treeViewHasChildrenCallback === null) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } return (bool) call_user_func($this->treeViewHasChildrenCallback, $item); } - /******************************************************************************** * COLUMNS * ********************************************************************************/ @@ -900,7 +692,7 @@ public function addColumnText( ?string $column = null ): ColumnText { - $column = $column ?? $key; + $column ??= $key; $columnText = new ColumnText($this, $key, $column, $name); $this->addColumn($key, $columnText); @@ -908,7 +700,6 @@ public function addColumnText( return $columnText; } - public function addColumnLink( string $key, string $name, @@ -917,8 +708,8 @@ public function addColumnLink( ?array $params = null ): ColumnLink { - $column = $column ?? $key; - $href = $href ?? $key; + $column ??= $key; + $href ??= $key; if ($params === null) { $params = [$this->primaryKey]; @@ -930,14 +721,13 @@ public function addColumnLink( return $columnLink; } - public function addColumnNumber( string $key, string $name, ?string $column = null ): ColumnNumber { - $column = $column ?? $key; + $column ??= $key; $columnNumber = new ColumnNumber($this, $key, $column, $name); $this->addColumn($key, $columnNumber); @@ -945,14 +735,13 @@ public function addColumnNumber( return $columnNumber; } - public function addColumnDateTime( string $key, string $name, ?string $column = null ): ColumnDateTime { - $column = $column ?? $key; + $column ??= $key; $columnDateTime = new ColumnDateTime($this, $key, $column, $name); $this->addColumn($key, $columnDateTime); @@ -960,14 +749,13 @@ public function addColumnDateTime( return $columnDateTime; } - public function addColumnStatus( string $key, string $name, ?string $column = null ): ColumnStatus { - $column = $column ?? $key; + $column ??= $key; $columnStatus = new ColumnStatus($this, $key, $column, $name); $this->addColumn($key, $columnStatus); @@ -975,7 +763,6 @@ public function addColumnStatus( return $columnStatus; } - /** * @throws DataGridColumnNotFoundException */ @@ -1000,7 +787,6 @@ public function removeColumn(string $key): self return $this; } - /******************************************************************************** * ACTIONS * ********************************************************************************/ @@ -1013,7 +799,7 @@ public function addAction( { $this->addActionCheck($key); - $href = $href ?? $key; + $href ??= $key; if ($params === null) { $params = [$this->primaryKey]; @@ -1022,7 +808,6 @@ public function addAction( return $this->actions[$key] = new Action($this, $key, $href, $name, $params); } - public function addActionCallback( string $key, string $name, @@ -1042,7 +827,6 @@ public function addActionCallback( return $action; } - public function addMultiAction(string $key, string $name): MultiAction { $this->addActionCheck($key); @@ -1054,12 +838,10 @@ public function addMultiAction(string $key, string $name): MultiAction return $action; } - /** - * @return Action|MultiAction * @throws DataGridException */ - public function getAction(string $key) + public function getAction(string $key): Action|MultiAction { if (!isset($this->actions[$key])) { throw new DataGridException(sprintf('There is no action at key [%s] defined.', $key)); @@ -1078,14 +860,10 @@ public function removeAction(string $key): self return $this; } - - /** - * @param array|string $columns - */ public function addFilterText( string $key, string $name, - $columns = null + array|string|null $columns = null ): FilterText { $columns = $columns === null ? [$key] : (is_string($columns) ? [$columns] : $columns); @@ -1095,7 +873,6 @@ public function addFilterText( return $this->filters[$key] = new FilterText($this, $key, $name, $columns); } - public function addFilterSelect( string $key, string $name, @@ -1103,14 +880,13 @@ public function addFilterSelect( ?string $column = null ): FilterSelect { - $column = $column ?? $key; + $column ??= $key; $this->addFilterCheck($key); return $this->filters[$key] = new FilterSelect($this, $key, $name, $options, $column); } - public function addFilterMultiSelect( string $key, string $name, @@ -1118,24 +894,22 @@ public function addFilterMultiSelect( ?string $column = null ): FilterMultiSelect { - $column = $column ?? $key; + $column ??= $key; $this->addFilterCheck($key); return $this->filters[$key] = new FilterMultiSelect($this, $key, $name, $options, $column); } - public function addFilterDate(string $key, string $name, ?string $column = null): FilterDate { - $column = $column ?? $key; + $column ??= $key; $this->addFilterCheck($key); return $this->filters[$key] = new FilterDate($this, $key, $name, $column); } - public function addFilterRange( string $key, string $name, @@ -1143,14 +917,13 @@ public function addFilterRange( string $nameSecond = '-' ): FilterRange { - $column = $column ?? $key; + $column ??= $key; $this->addFilterCheck($key); return $this->filters[$key] = new FilterRange($this, $key, $name, $column, $nameSecond); } - /** * @throws DataGridException */ @@ -1161,17 +934,13 @@ public function addFilterDateRange( string $nameSecond = '-' ): FilterDateRange { - $column = $column ?? $key; + $column ??= $key; $this->addFilterCheck($key); return $this->filters[$key] = new FilterDateRange($this, $key, $name, $column, $nameSecond); } - - - - /** * Fill array of Filter\Filter[] with values from $this->filter persistent parameter * Fill array of Column\Column[] with values from $this->sort persistent parameter @@ -1187,7 +956,7 @@ public function assembleFilters(): array continue; } - if (is_array($value) || $value instanceof Traversable) { + if (is_iterable($value)) { if (!ArraysHelper::testEmpty($value)) { $this->filters[$key]->setValue($value); } @@ -1219,7 +988,6 @@ public function removeFilter(string $key): self return $this; } - public function getFilter(string $key): Filter { if (!isset($this->filters[$key])) { @@ -1239,7 +1007,6 @@ public function setStrictSessionFilterValues(bool $strictSessionFilterValues = t return $this; } - /******************************************************************************** * FILTERING * ********************************************************************************/ @@ -1250,7 +1017,6 @@ public function isFilterActive(): bool return $is_filter || $this->forceFilterActive; } - /** * Tell that filter is active from whatever reasons * @@ -1263,7 +1029,6 @@ public function setFilterActive(): self return $this; } - /** * Set filter values (force - overwrite user data) * @@ -1278,7 +1043,6 @@ public function setFilter(array $filter): self return $this; } - /** * If we want to sent some initial filter * @@ -1330,7 +1094,6 @@ public function setDefaultFilter(array $defaultFilter, bool $useOnReset = true): return $this; } - public function findDefaultFilter(): void { if ($this->filter !== []) { @@ -1350,7 +1113,6 @@ public function findDefaultFilter(): void } } - public function createComponentFilter(): Form { $form = new Form($this, 'filter'); @@ -1447,7 +1209,6 @@ public function createComponentFilter(): Form return $form; } - public function setFilterContainerDefaults(Container $container, array $values, ?string $parentKey = null): void { foreach ($container->getComponents() as $key => $control) { @@ -1463,12 +1224,8 @@ public function setFilterContainerDefaults(Container $container, array $values, $value = $values[$key]; - if ($value instanceof \DateTime) { - if ($parentKey !== null) { - $filter = $this->getFilter($parentKey); - } else { - $filter = $this->getFilter((string) $key); - } + if ($value instanceof DateTime) { + $filter = $parentKey !== null ? $this->getFilter($parentKey) : $this->getFilter((string) $key); if ($filter instanceof IFilterDate) { $value = $value->format($filter->getPhpFormat()); @@ -1477,7 +1234,7 @@ public function setFilterContainerDefaults(Container $container, array $values, try { if (!$control instanceof IControl) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $control->setValue($value); @@ -1490,7 +1247,6 @@ public function setFilterContainerDefaults(Container $container, array $values, } } - /** * Set $this->filter values after filter form submitted */ @@ -1532,7 +1288,7 @@ public function filterSucceeded(NetteForm $form): void || !$edit['submit'] instanceof FormsSubmitButton || !$edit['cancel'] instanceof FormsSubmitButton ) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } if ($edit['submit']->isSubmittedBy() || $edit['cancel']->isSubmittedBy()) { @@ -1577,7 +1333,7 @@ public function filterSucceeded(NetteForm $form): void || !$add['submit'] instanceof FormsSubmitButton || !$add['cancel'] instanceof FormsSubmitButton ) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } if ($add['submit']->isSubmittedBy() || $add['cancel']->isSubmittedBy()) { @@ -1599,7 +1355,7 @@ public function filterSucceeded(NetteForm $form): void $values = $values['filter']; if (!$values instanceof ArrayHash) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } foreach ($values as $key => $value) { @@ -1651,13 +1407,11 @@ public function setOuterFilterRendering(bool $outerFilterRendering = true): self return $this; } - public function hasOuterFilterRendering(): bool { return $this->outerFilterRendering; } - /** * @return static * @throws InvalidArgumentException @@ -1679,7 +1433,6 @@ public function setOuterFilterColumnsCount(int $count): self return $this; } - public function getOuterFilterColumnsCount(): int { return $this->outerFilterColumnsCount; @@ -1695,13 +1448,11 @@ public function setCollapsibleOuterFilters(bool $collapsibleOuterFilters = true) return $this; } - public function hasCollapsibleOuterFilters(): bool { return $this->collapsibleOuterFilters; } - /** * Try to restore session stuff * @@ -1752,7 +1503,7 @@ public function findSessionValues(): void $this->filter[$key] = $value; - } catch (DataGridException $e) { + } catch (DataGridException) { if ($this->strictSessionFilterValues) { throw new DataGridFilterNotFoundException( sprintf('Session filter: Filter [%s] not found', $key) @@ -1770,7 +1521,7 @@ public function findSessionValues(): void try { $column = $this->getColumn((string) $key); - } catch (DataGridColumnNotFoundException $e) { + } catch (DataGridColumnNotFoundException) { $this->deleteSessionData('_grid_sort'); $this->sort = []; @@ -1784,7 +1535,6 @@ public function findSessionValues(): void } } - /******************************************************************************** * EXPORTS * ********************************************************************************/ @@ -1797,7 +1547,6 @@ public function addExportCallback( return $this->addToExports(new Export($this, $text, $callback, $filtered)); } - public function addExportCsvFiltered( string $text, string $csvFileName, @@ -1809,7 +1558,6 @@ public function addExportCsvFiltered( return $this->addExportCsv($text, $csvFileName, $outputEncoding, $delimiter, $includeBom, true); } - public function addExportCsv( string $text, string $csvFileName, @@ -1826,7 +1574,6 @@ public function addExportCsv( return $exportCsv; } - public function resetExportsLinks(): void { foreach ($this->exports as $id => $export) { @@ -1859,7 +1606,6 @@ public function addToolbarButton( return $this->toolbarButtons[$href] = new ToolbarButton($this, $href, $text, $params); } - /** * @throws DataGridException */ @@ -1884,7 +1630,6 @@ public function removeToolbarButton(string $key): self return $this; } - /******************************************************************************** * GROUP ACTIONS * ********************************************************************************/ @@ -1893,37 +1638,31 @@ public function addGroupAction(string $title, array $options = []): GroupAction return $this->getGroupActionCollection()->addGroupSelectAction($title, $options); } - public function addGroupButtonAction(string $title, ?string $class = null): GroupButtonAction { return $this->getGroupActionCollection()->addGroupButtonAction($title, $class); } - public function addGroupSelectAction(string $title, array $options = []): GroupAction { return $this->getGroupActionCollection()->addGroupSelectAction($title, $options); } - public function addGroupMultiSelectAction(string $title, array $options = []): GroupAction { return $this->getGroupActionCollection()->addGroupMultiSelectAction($title, $options); } - public function addGroupTextAction(string $title): GroupAction { return $this->getGroupActionCollection()->addGroupTextAction($title); } - public function addGroupTextareaAction(string $title): GroupAction { return $this->getGroupActionCollection()->addGroupTextareaAction($title); } - public function getGroupActionCollection(): GroupActionCollection { if ($this->groupActionCollection === null) { @@ -1933,13 +1672,11 @@ public function getGroupActionCollection(): GroupActionCollection return $this->groupActionCollection; } - public function hasGroupActions(): bool { return $this->groupActionCollection instanceof GroupActionCollection; } - public function shouldShowSelectedRowsCount(): bool { return $this->showSelectedRowsCount; @@ -1955,7 +1692,6 @@ public function setShowSelectedRowsCount(bool $show = true): self return $this; } - /******************************************************************************** * HANDLERS * ********************************************************************************/ @@ -1967,7 +1703,6 @@ public function handlePage(int $page): void $this->reload(['table']); } - /** * @throws DataGridColumnNotFoundException */ @@ -1981,7 +1716,7 @@ public function handleSort(array $sort): void try { $column = $this->getColumn($key); - } catch (DataGridColumnNotFoundException $e) { + } catch (DataGridColumnNotFoundException) { unset($sort[$key]); continue; @@ -2002,7 +1737,6 @@ public function handleSort(array $sort): void $this->reloadTheWholeGrid(); } - public function handleResetFilter(): void { /** @@ -2023,17 +1757,7 @@ public function handleResetFilter(): void : iterator_to_array($this->getSessionData()); foreach (array_keys($sessionData) as $key) { - if ( - !in_array($key, [ - '_grid_perPage', - '_grid_sort', - '_grid_page', - '_grid_has_filtered', - '_grid_has_sorted', - '_grid_hidden_columns', - '_grid_hidden_columns_manipulated', - ], true) - ) { + if (!in_array($key, ['_grid_perPage', '_grid_sort', '_grid_page', '_grid_has_filtered', '_grid_has_sorted', '_grid_hidden_columns', '_grid_hidden_columns_manipulated'], true)) { $this->deleteSessionData((string) $key); } } @@ -2043,7 +1767,6 @@ public function handleResetFilter(): void $this->reloadTheWholeGrid(); } - public function handleResetColumnFilter(string $key): void { $this->deleteSessionData($key); @@ -2062,13 +1785,11 @@ public function setColumnReset(bool $reset = true): self return $this; } - public function hasColumnReset(): bool { return $this->hasColumnReset; } - /** * @param array $filters */ @@ -2089,14 +1810,10 @@ public function sendNonEmptyFiltersInPayload(array $filters): void $this->getPresenterInstance()->payload->non_empty_filters = $non_empty_filters; } - - /** - * @param mixed $id - */ - public function handleExport($id): void + public function handleExport(mixed $id): void { if (!isset($this->exports[$id])) { - throw new Nette\Application\ForbiddenRequestException; + throw new ForbiddenRequestException(); } if ($this->columnsExportOrder !== []) { @@ -2145,14 +1862,10 @@ public function handleExport($id): void } } - - /** - * @param mixed $parent - */ - public function handleGetChildren($parent): void + public function handleGetChildren(mixed $parent): void { if (!is_callable($this->treeViewChildrenCallback)) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $this->setDataSource(call_user_func($this->treeViewChildrenCallback, $parent)); @@ -2169,22 +1882,18 @@ public function handleGetChildren($parent): void } } - - /** - * @param mixed $id - */ - public function handleGetItemDetail($id): void + public function handleGetItemDetail(mixed $id): void { $template = $this->getTemplate(); if (!$template instanceof Template) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $template->add('toggle_detail', $id); if ($this->itemsDetail === null) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $this->redrawItem = [$this->itemsDetail->getPrimaryWhereColumn() => $id]; @@ -2207,25 +1916,20 @@ public function handleGetItemDetail($id): void } } - - /** - * @param mixed $id - * @param mixed $key - */ - public function handleEdit($id, $key): void + public function handleEdit(mixed $id, mixed $key): void { $column = $this->getColumn($key); $request = $this->getPresenterInstance()->getRequest(); if (!$request instanceof Request) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $value = $request->getPost('value'); // Could be null of course if ($column->getEditableCallback() === null) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $newValue = $column->getEditableCallback()($id, $value); @@ -2239,7 +1943,6 @@ public function handleEdit($id, $key): void } } - /** * @param array|string[] $snippets */ @@ -2270,7 +1973,6 @@ public function reload(array $snippets = []): void } } - public function reloadTheWholeGrid(): void { if ($this->getPresenterInstance()->isAjax()) { @@ -2285,7 +1987,6 @@ public function reloadTheWholeGrid(): void } } - public function handleChangeStatus(string $id, string $key, string $value): void { if (!isset($this->columns[$key])) { @@ -2293,18 +1994,13 @@ public function handleChangeStatus(string $id, string $key, string $value): void } if (!$this->columns[$key] instanceof ColumnStatus) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $this->columns[$key]->onChange($id, $value); } - - /** - * @param string|int $id - * @param mixed $primaryWhereColumn - */ - public function redrawItem($id, $primaryWhereColumn = null): void + public function redrawItem(string|int $id, mixed $primaryWhereColumn = null): void { $this->snippetsSet = true; @@ -2317,7 +2013,6 @@ public function redrawItem($id, $primaryWhereColumn = null): void $this->onRedraw(); } - public function handleShowAllColumns(): void { $this->deleteSessionData('_grid_hidden_columns'); @@ -2328,7 +2023,6 @@ public function handleShowAllColumns(): void $this->onRedraw(); } - public function handleShowDefaultColumns(): void { $this->deleteSessionData('_grid_hidden_columns'); @@ -2339,7 +2033,6 @@ public function handleShowDefaultColumns(): void $this->onRedraw(); } - public function handleShowColumn(string $column): void { $columns = $this->getSessionData('_grid_hidden_columns'); @@ -2360,7 +2053,6 @@ public function handleShowColumn(string $column): void $this->onRedraw(); } - public function handleHideColumn(string $column): void { /** @@ -2382,12 +2074,7 @@ public function handleHideColumn(string $column): void $this->onRedraw(); } - - /** - * @param mixed $__key - * @param mixed $__id - */ - public function handleActionCallback($__key, $__id): void + public function handleActionCallback(mixed $__key, mixed $__id): void { $action = $this->getAction($__key); @@ -2412,7 +2099,7 @@ public function handleActionCallback($__key, $__id): void public function setItemsPerPageList(array $itemsPerPageList, bool $includeAll = true): self { if ($itemsPerPageList === []) { - throw new \InvalidArgumentException('$itemsPerPageList can not be an empty array'); + throw new InvalidArgumentException('$itemsPerPageList can not be an empty array'); } $this->itemsPerPageList = $itemsPerPageList; @@ -2434,7 +2121,6 @@ public function setDefaultPerPage(int $count): self return $this; } - /** * User may set default "items per page" value, apply it */ @@ -2451,7 +2137,6 @@ public function findDefaultPerPage(): void $this->saveSessionData('_grid_perPage', $this->perPage); } - public function createComponentPaginator(): DataGridPaginator { $component = new DataGridPaginator( @@ -2474,11 +2159,7 @@ public function createComponentPaginator(): DataGridPaginator return $component; } - - /** - * @return int|string - */ - public function getPerPage() + public function getPerPage(): int|string { $itemsPerPageList = array_keys($this->getItemsPerPageList()); @@ -2494,7 +2175,6 @@ public function getPerPage() : (int) $perPage; } - /** * @return array|array|int[]|array|string[] */ @@ -2513,7 +2193,6 @@ public function getItemsPerPageList(): array return $list; } - /** * @return static */ @@ -2524,13 +2203,11 @@ public function setPagination(bool $doPaginate): self return $this; } - public function isPaginated(): bool { return $this->doPaginate; } - public function getPaginator(): ?DataGridPaginator { if ($this->isPaginated() && $this->perPage !== 'all') { @@ -2555,11 +2232,10 @@ public function setTranslator(ITranslator $translator): self return $this; } - public function getTranslator(): ITranslator { if ($this->translator === null) { - $this->translator = new SimpleTranslator; + $this->translator = new SimpleTranslator(); } return $this->translator; @@ -2586,7 +2262,7 @@ public function setColumnsOrder(array $order): self } } - if (sizeof($new_order) === sizeof($this->columns)) { + if (count($new_order) === count($this->columns)) { $this->columns = $new_order; } else { throw new DataGridException('When changing columns order, you have to specify all columns'); @@ -2595,7 +2271,6 @@ public function setColumnsOrder(array $order): self return $this; } - /** * Columns order may be different for export and normal grid * @@ -2609,7 +2284,6 @@ public function setColumnsExportOrder(array $order): self return $this; } - /******************************************************************************** * SESSION & URL * ********************************************************************************/ @@ -2620,7 +2294,6 @@ public function getSessionSectionName(): string return $presenter->getName() . ':' . $this->getUniqueId(); } - /** * @return static */ @@ -2632,7 +2305,6 @@ public function setRememberState(bool $remember = true, bool $rememberHideableCo return $this; } - /** * @return static */ @@ -2643,16 +2315,9 @@ public function setRefreshUrl(bool $refresh = true): self return $this; } - - /** - * @param mixed $defaultValue - * @return mixed - */ - public function getSessionData(?string $key = null, $defaultValue = null) + public function getSessionData(?string $key = null, mixed $defaultValue = null): mixed { - $getValue = function() use ($key, $defaultValue) { - return ($key !== null ? $this->gridSession[$key] : $this->gridSession) ?? $defaultValue; - }; + $getValue = fn () => ($key !== null ? $this->gridSession[$key] : $this->gridSession) ?? $defaultValue; if ($this->rememberState) { return ($getValue)(); @@ -2667,11 +2332,7 @@ public function getSessionData(?string $key = null, $defaultValue = null) : $defaultValue; } - - /** - * @param mixed $value - */ - public function saveSessionData(string $key, $value): void + public function saveSessionData(string $key, mixed $value): void { if ($this->rememberState) { $this->gridSession[$key] = $value; @@ -2680,7 +2341,6 @@ public function saveSessionData(string $key, $value): void } } - public function deleteSessionData(string $key): void { unset($this->gridSession[$key]); @@ -2699,11 +2359,10 @@ public function getItemsDetail(): ?ItemDetail return $this->itemsDetail; } - /** * @param mixed $detail callable|string|bool */ - public function setItemsDetail($detail = true, ?string $primaryWhereColumn = null): ItemDetail + public function setItemsDetail(mixed $detail = true, ?string $primaryWhereColumn = null): ItemDetail { if ($this->isSortable()) { throw new DataGridException('You can not use both sortable datagrid and items detail.'); @@ -2738,7 +2397,6 @@ public function setItemsDetail($detail = true, ?string $primaryWhereColumn = nul return $this->itemsDetail; } - /** * @return static */ @@ -2755,7 +2413,6 @@ public function setItemsDetailForm(callable $callableSetContainer): self throw new DataGridException('Please set the ItemDetail first.'); } - public function getItemDetailForm(): ?Container { if ($this->itemsDetail instanceof ItemDetail) { @@ -2765,7 +2422,6 @@ public function getItemDetailForm(): ?Container return null; } - /******************************************************************************** * ROW PRIVILEGES * ********************************************************************************/ @@ -2774,19 +2430,16 @@ public function allowRowsGroupAction(callable $condition): void $this->rowConditions['group_action'] = $condition; } - public function allowRowsInlineEdit(callable $condition): void { $this->rowConditions['inline_edit'] = $condition; } - public function allowRowsAction(string $key, callable $condition): void { $this->rowConditions['action'][$key] = $condition; } - /** * @throws DataGridException */ @@ -2811,11 +2464,7 @@ public function allowRowsMultiAction( $this->actions[$multiActionKey]->setRowCondition($actionKey, $condition); } - - /** - * @return bool|callable - */ - public function getRowCondition(string $name, ?string $key = null) + public function getRowCondition(string $name, ?string $key = null): bool|callable { if (!isset($this->rowConditions[$name])) { return false; @@ -2830,7 +2479,6 @@ public function getRowCondition(string $name, ?string $key = null) return $condition[$key] ?? false; } - /******************************************************************************** * COLUMN CALLBACK * ********************************************************************************/ @@ -2839,13 +2487,11 @@ public function addColumnCallback(string $key, callable $callback): void $this->columnCallbacks[$key] = $callback; } - public function getColumnCallback(string $key): ?callable { return $this->columnCallbacks[$key] ?? null; } - /******************************************************************************** * INLINE EDIT * ********************************************************************************/ @@ -2856,13 +2502,11 @@ public function addInlineEdit(?string $primaryWhereColumn = null): InlineEdit return $this->inlineEdit; } - public function getInlineEdit(): ?InlineEdit { return $this->inlineEdit; } - public function handleShowInlineAdd(): void { if ($this->inlineAdd !== null) { @@ -2881,11 +2525,7 @@ public function handleShowInlineAdd(): void } } - - /** - * @param mixed $id - */ - public function handleInlineEdit($id): void + public function handleInlineEdit(mixed $id): void { if ($this->inlineEdit !== null) { $this->inlineEdit->setItemId($id); @@ -2896,7 +2536,7 @@ public function handleInlineEdit($id): void $inlineEditContainer = $filterContainer['inline_edit']; if (!$inlineEditContainer instanceof Container) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $inlineEditContainer->addHidden('_id', $id); @@ -2913,7 +2553,6 @@ public function handleInlineEdit($id): void } } - /******************************************************************************** * INLINE ADD * ********************************************************************************/ @@ -2928,7 +2567,6 @@ public function addInlineAdd(): InlineAdd return $this->inlineAdd; } - public function getInlineAdd(): ?InlineAdd { return $this->inlineAdd; @@ -2947,7 +2585,6 @@ public function canHideColumns(): bool return $this->canHideColumns; } - /** * Order Grid to set columns hideable. * @@ -2960,7 +2597,6 @@ public function setColumnsHideable(): self return $this; } - /******************************************************************************** * COLUMNS SUMMARY * ********************************************************************************/ @@ -2969,7 +2605,6 @@ public function hasColumnsSummary(): bool return $this->columnsSummary instanceof ColumnsSummary; } - /** * @param array|string[] $columns */ @@ -2984,7 +2619,6 @@ public function setColumnsSummary(array $columns, ?callable $rowCallback = null) return $this->columnsSummary; } - public function getColumnsSummary(): ?ColumnsSummary { return $this->columnsSummary; @@ -2997,6 +2631,7 @@ public function getColumnsSummary(): ?ColumnsSummary /** * Gets component's full name in component tree + * * @throws DataGridHasToBeAttachedToPresenterComponentException */ public function getFullName(): string @@ -3008,7 +2643,6 @@ public function getFullName(): string return $this->componentFullName; } - /** * Tell grid filters to by submitted automatically * @@ -3021,13 +2655,11 @@ public function setAutoSubmit(bool $autoSubmit = true): self return $this; } - public function hasAutoSubmit(): bool { return $this->autoSubmit; } - public function getFilterSubmitButton(): SubmitButton { if ($this->hasAutoSubmit()) { @@ -3051,7 +2683,7 @@ public function getFilterSubmitButton(): SubmitButton */ public function getColumnsCount(): int { - $count = sizeof($this->getColumns()); + $count = count($this->getColumns()); if ($this->actions !== [] || $this->isSortable() @@ -3068,7 +2700,6 @@ public function getColumnsCount(): int return $count; } - /** * @internal */ @@ -3077,7 +2708,6 @@ public function getPrimaryKey(): string return $this->primaryKey; } - /** * @return array * @internal @@ -3115,13 +2745,13 @@ public function getColumns(): array unset($return[$column]); } } - } catch (DataGridHasToBeAttachedToPresenterComponentException $e) { + } catch (DataGridHasToBeAttachedToPresenterComponentException) { + // No need to worry } return $return; } - /** * @internal */ @@ -3136,7 +2766,6 @@ public function getColumnsVisibility(): array return $return; } - /** * @internal */ @@ -3148,7 +2777,7 @@ public function getParentComponent(): Component throw new DataGridHasToBeAttachedToPresenterComponentException( sprintf( 'DataGrid is attached to: "%s", but instance of %s is needed.', - ($parent !== null ? get_class($parent) : 'null'), + ($parent !== null ? $parent::class : 'null'), Component::class ) ); @@ -3157,10 +2786,9 @@ public function getParentComponent(): Component return $parent; } - /** * @internal - * @throws \UnexpectedValueException + * @throws UnexpectedValueException */ public function getSortableParentPath(): string { @@ -3171,7 +2799,7 @@ public function getSortableParentPath(): string $presenter = $this->getParentComponent()->lookupPath(IPresenter::class, false); if ($presenter === null) { - throw new \UnexpectedValueException( + throw new UnexpectedValueException( sprintf('%s needs %s', self::class, IPresenter::class) ); } @@ -3179,7 +2807,6 @@ public function getSortableParentPath(): string return $presenter; } - /** * Some of datagrid columns may be hidden by default * @@ -3193,7 +2820,6 @@ public function setSomeColumnDefaultHide(bool $defaultHide): self return $this; } - /** * Are some of columns hidden bydefault? * @@ -3204,7 +2830,6 @@ public function hasSomeColumnDefaultHide(): bool return $this->someColumnDefaultHide; } - /** * Simply refresh url * @@ -3221,7 +2846,6 @@ public function handleRefreshState(): void $this->redrawControl('non-existing-snippet'); } - /** * @internal */ @@ -3230,7 +2854,6 @@ public function setCustomPaginatorTemplate(string $templateFile): void $this->customPaginatorTemplate = $templateFile; } - protected function createSorting(array $sort, ?callable $sortCallback = null): Sorting { foreach ($sort as $key => $order) { @@ -3243,7 +2866,7 @@ protected function createSorting(array $sort, ?callable $sortCallback = null): S try { $column = $this->getColumn($key); - } catch (DataGridColumnNotFoundException $e) { + } catch (DataGridColumnNotFoundException) { continue; } @@ -3257,7 +2880,6 @@ protected function createSorting(array $sort, ?callable $sortCallback = null): S return new Sorting($sort, $sortCallback); } - /** * @throws DataGridException */ @@ -3276,7 +2898,6 @@ protected function addColumn(string $key, Column $column): Column return $this->columns[$key] = $column; } - /** * Check whether given key already exists in $this->filters * @@ -3290,9 +2911,8 @@ protected function addActionCheck(string $key): void ); } }/******************************************************************************** - * FILTERS * - ********************************************************************************/ - + * FILTERS * + ********************************************************************************/ /** * Check whether given key already exists in $this->filters @@ -3308,14 +2928,9 @@ protected function addFilterCheck(string $key): void } } - protected function addToExports(Export $export): Export { - if (sizeof($this->exports) > 0) { - $id = sizeof($this->exports) + 1; - } else { - $id = 1; - } + $id = count($this->exports) > 0 ? count($this->exports) + 1 : 1; $link = new Link($this, 'export!', ['id' => $id]); @@ -3324,7 +2939,6 @@ protected function addToExports(Export $export): Export return $this->exports[$id] = $export; } - private function getPresenterInstance(): Presenter { return $this->getPresenter(); diff --git a/src/DataModel.php b/src/DataModel.php index d6a4394f0..498b968f4 100644 --- a/src/DataModel.php +++ b/src/DataModel.php @@ -1,13 +1,16 @@ -getConnection()->getDriver(); - if ($driver instanceof Dibi\Drivers\OdbcDriver) { + if ($driver instanceof OdbcDriver) { $source = new DibiFluentMssqlDataSource($source, $primaryKey); - } elseif ($driver instanceof Dibi\Drivers\MsSqlDriver) { + } elseif ($driver instanceof MsSqlDriver) { $source = new DibiFluentMssqlDataSource($source, $primaryKey); - } elseif ($driver instanceof Dibi\Drivers\PostgreDriver) { + } elseif ($driver instanceof PostgreDriver) { $source = new DibiFluentPostgreDataSource($source, $primaryKey); - } elseif ($driver instanceof Dibi\Drivers\SqlsrvDriver) { + } elseif ($driver instanceof SqlsrvDriver) { $source = new DibiFluentMssqlDataSource($source, $primaryKey); } else { @@ -91,11 +76,7 @@ public function __construct($source, string $primaryKey) } elseif ($source instanceof Selection) { $driver = NetteDatabaseSelectionHelper::getDriver($source); - if ($driver instanceof NDBDrivers\MsSqlDriver || $driver instanceof NDBDrivers\SqlsrvDriver) { - $source = new NetteDatabaseTableMssqlDataSource($source, $primaryKey); - } else { - $source = new NetteDatabaseTableDataSource($source, $primaryKey); - } + $source = $driver instanceof NDBMsSqlDriver || $driver instanceof NDBSqlsrvDriver ? new NetteDatabaseTableMssqlDataSource($source, $primaryKey) : new NetteDatabaseTableDataSource($source, $primaryKey); } elseif ($source instanceof QueryBuilder) { $source = new DoctrineDataSource($source, $primaryKey); @@ -105,23 +86,21 @@ public function __construct($source, string $primaryKey) } elseif ($source instanceof ICollection) { $source = new NextrasDataSource($source, $primaryKey); - } else { + } elseif (!($source instanceof IDataSource)) { throw new DataGridWrongDataSourceException(sprintf( 'DataGrid can not take [%s] as data source.', - is_object($source) ? get_class($source) : 'null' + is_object($source) ? $source::class : 'null' )); } $this->dataSource = $source; } - public function getDataSource(): IDataSource { return $this->dataSource; } - public function filterData( ?DataGridPaginator $paginatorComponent, Sorting $sorting, @@ -154,15 +133,12 @@ public function filterData( return $this->dataSource->sort($sorting)->getData(); } - - /** - * @return mixed - */ - public function filterRow(array $condition) + public function filterRow(array $condition): mixed { $this->onBeforeFilter($this->dataSource); $this->onAfterFilter($this->dataSource); return $this->dataSource->filterOne($condition)->getData(); } + } diff --git a/src/DataSource/ApiDataSource.php b/src/DataSource/ApiDataSource.php index 3626bbeeb..83c9cfc65 100644 --- a/src/DataSource/ApiDataSource.php +++ b/src/DataSource/ApiDataSource.php @@ -1,6 +1,4 @@ -url = $url; - $this->queryParams = $queryParams; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { return $this->getResponse(['count' => '']); } - /** * {@inheritDoc} */ @@ -89,7 +48,6 @@ public function getData(): array ]); } - /** * {@inheritDoc} */ @@ -122,7 +80,6 @@ public function filter(array $filters): void } } - /** * {@inheritDoc} */ @@ -134,7 +91,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->offset = $offset; @@ -143,7 +99,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { /** @@ -157,13 +112,10 @@ public function sort(Sorting $sorting): IDataSource return $this; } - /** * Get data of remote source - * - * @return mixed */ - protected function getResponse(array $params = []) + protected function getResponse(array $params = []): mixed { $queryString = http_build_query($params + $this->queryParams); $url = sprintf('%s?%s', $this->url, $queryString); @@ -174,6 +126,7 @@ protected function getResponse(array $params = []) throw new UnexpectedValueException(sprintf('Could not open URL %s', $url)); } - return json_decode($content); + return json_decode($content, null, 512, JSON_THROW_ON_ERROR); } + } diff --git a/src/DataSource/ArrayDataSource.php b/src/DataSource/ArrayDataSource.php index aecc8c17a..a8912441d 100644 --- a/src/DataSource/ArrayDataSource.php +++ b/src/DataSource/ArrayDataSource.php @@ -1,6 +1,4 @@ -setData($dataSource); } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { - return sizeof($this->data); + return count($this->data); } - /** * {@inheritDoc} */ @@ -61,7 +44,6 @@ public function getData(): array return $this->data; } - /** * {@inheritDoc} */ @@ -76,16 +58,13 @@ public function filter(array $filters): void ); $this->setData($data); } else { - $data = array_filter($this->data, function ($row) use ($filter) { - return $this->applyFilter($row, $filter); - }); + $data = array_filter($this->data, fn ($row) => $this->applyFilter($row, $filter)); $this->setData($data); } } } } - /** * {@inheritDoc} */ @@ -106,7 +85,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $data = array_slice($this->data, $offset, $limit); @@ -115,7 +93,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -167,12 +144,7 @@ public function sort(Sorting $sorting): IDataSource return $this; } - - /** - * @param mixed $row - * @return mixed - */ - protected function applyFilter($row, Filter $filter) + protected function applyFilter(mixed $row, Filter $filter): mixed { if (is_array($row) || $row instanceof ArrayAccess) { if ($filter instanceof FilterDate) { @@ -210,7 +182,7 @@ protected function applyFilter($row, Filter $filter) $row_value = strtolower(Strings::toAscii((string) $row[$column])); foreach ($words as $word) { - if (strpos($row_value, strtolower(Strings::toAscii($word))) !== false) { + if (str_contains($row_value, strtolower(Strings::toAscii($word)))) { return $row; } } @@ -220,11 +192,7 @@ protected function applyFilter($row, Filter $filter) return false; } - - /** - * @param mixed $row - */ - protected function applyFilterMultiSelect($row, FilterMultiSelect $filter): bool + protected function applyFilterMultiSelect(mixed $row, FilterMultiSelect $filter): bool { $condition = $filter->getCondition(); $values = $condition[$filter->getColumn()]; @@ -232,11 +200,7 @@ protected function applyFilterMultiSelect($row, FilterMultiSelect $filter): bool return in_array($row[$filter->getColumn()], $values, true); } - - /** - * @param mixed $row - */ - protected function applyFilterRange($row, FilterRange $filter): bool + protected function applyFilterRange(mixed $row, FilterRange $filter): bool { $condition = $filter->getCondition(); $values = $condition[$filter->getColumn()]; @@ -256,11 +220,7 @@ protected function applyFilterRange($row, FilterRange $filter): bool return true; } - - /** - * @param mixed $row - */ - protected function applyFilterDateRange($row, FilterDateRange $filter): bool + protected function applyFilterDateRange(mixed $row, FilterDateRange $filter): bool { $format = $filter->getPhpFormat(); $condition = $filter->getCondition(); @@ -277,7 +237,7 @@ protected function applyFilterDateRange($row, FilterDateRange $filter): bool */ try { $row_value = DateTimeHelper::tryConvertToDate($row_value); - } catch (DataGridDateTimeHelperException $e) { + } catch (DataGridDateTimeHelperException) { /** * Otherwise just return raw string */ @@ -300,7 +260,7 @@ protected function applyFilterDateRange($row, FilterDateRange $filter): bool */ try { $row_value = DateTimeHelper::tryConvertToDate($row_value); - } catch (DataGridDateTimeHelperException $e) { + } catch (DataGridDateTimeHelperException) { /** * Otherwise just return raw string */ @@ -316,13 +276,10 @@ protected function applyFilterDateRange($row, FilterDateRange $filter): bool return true; } - /** * Apply fitler date and tell whether row value matches or not - * - * @param mixed $row */ - protected function applyFilterDate($row, FilterDate $filter): bool + protected function applyFilterDate(mixed $row, FilterDate $filter): bool { $format = $filter->getPhpFormat(); $condition = $filter->getCondition(); @@ -338,7 +295,7 @@ protected function applyFilterDate($row, FilterDate $filter): bool */ try { $row_value = DateTimeHelper::tryConvertToDateTime($row_value); - } catch (DataGridDateTimeHelperException $e) { + } catch (DataGridDateTimeHelperException) { /** * Otherwise just return raw string */ @@ -352,7 +309,6 @@ protected function applyFilterDate($row, FilterDate $filter): bool return false; } - /** * Set the data */ @@ -362,4 +318,5 @@ private function setData(array $dataSource): IDataSource return $this; } + } diff --git a/src/DataSource/DibiFluentDataSource.php b/src/DataSource/DibiFluentDataSource.php index 81336b20a..666521791 100755 --- a/src/DataSource/DibiFluentDataSource.php +++ b/src/DataSource/DibiFluentDataSource.php @@ -1,9 +1,8 @@ -dataSource = $dataSource; - $this->primaryKey = $primaryKey; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { return $this->dataSource->count(); } - /** * {@inheritDoc} */ @@ -64,7 +41,6 @@ public function getData(): array return $this->data !== [] ? $this->data : $this->dataSource->fetchAll(); } - /** * {@inheritDoc} */ @@ -75,7 +51,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->dataSource->limit($limit)->offset($offset); @@ -85,7 +60,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -123,13 +97,11 @@ public function sort(Sorting $sorting): IDataSource return $this; } - public function processAggregation(IAggregationFunction $function): void { $function->processDataSource(clone $this->dataSource); } - protected function applyFilterDate(FilterDate $filter): void { $conditions = $filter->getCondition(); @@ -138,12 +110,11 @@ protected function applyFilterDate(FilterDate $filter): void $date = DateTimeHelper::tryConvertToDateTime($conditions[$filter->getColumn()], [$filter->getPhpFormat()]); $this->dataSource->where('DATE(%n) = ?', $filter->getColumn(), $date->format('Y-m-d')); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -157,7 +128,7 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateFrom->setTime(0, 0, 0); $this->dataSource->where('DATE(%n) >= ?', $filter->getColumn(), $dateFrom); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -168,13 +139,12 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateTo->setTime(23, 59, 59); $this->dataSource->where('DATE(%n) <= ?', $filter->getColumn(), $dateTo); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterRange(FilterRange $filter): void { $conditions = $filter->getCondition(); @@ -191,7 +161,6 @@ protected function applyFilterRange(FilterRange $filter): void } } - protected function applyFilterText(FilterText $filter): void { $condition = $filter->getCondition(); @@ -199,10 +168,10 @@ protected function applyFilterText(FilterText $filter): void $or = []; foreach ($condition as $column => $value) { - $column = Helpers::escape($driver, $column, \dibi::IDENTIFIER); + $column = Helpers::escape($driver, $column, dibi::IDENTIFIER); if ($filter->isExactSearch()) { - $this->dataSource->where("$column = %s", $value); + $this->dataSource->where(sprintf('%s = %%s', $column), $value); continue; } @@ -210,26 +179,25 @@ protected function applyFilterText(FilterText $filter): void $words = $filter->hasSplitWordsSearch() === false ? [$value] : explode(' ', $value); foreach ($words as $word) { - $or[] = ["$column LIKE %~like~", $word]; + $or[] = [sprintf('%s LIKE %%~like~', $column), $word]; } } - if (sizeof($or) > 1) { + if (count($or) > 1) { $this->dataSource->where('(%or)', $or); } else { $this->dataSource->where($or); } } - protected function applyFilterMultiSelect(FilterMultiSelect $filter): void { $condition = $filter->getCondition(); $values = $condition[$filter->getColumn()]; - if (sizeof($values) > 1) { + if ((is_countable($values) ? count($values) : 0) > 1) { $value1 = array_shift($values); - $length = sizeof($values); + $length = count($values); $i = 1; $this->dataSource->where('(%n = ?', $filter->getColumn(), $value1); @@ -248,18 +216,14 @@ protected function applyFilterMultiSelect(FilterMultiSelect $filter): void } } - protected function applyFilterSelect(FilterSelect $filter): void { $this->dataSource->where($filter->getCondition()); } - - /** - * {@inheritDoc} - */ - protected function getDataSource() + protected function getDataSource(): Fluent { return $this->dataSource; } + } diff --git a/src/DataSource/DibiFluentMssqlDataSource.php b/src/DataSource/DibiFluentMssqlDataSource.php index fe6b76145..945dcb165 100755 --- a/src/DataSource/DibiFluentMssqlDataSource.php +++ b/src/DataSource/DibiFluentMssqlDataSource.php @@ -1,9 +1,8 @@ -dataSource; @@ -42,7 +32,6 @@ public function getCount(): int return $clone->count(); } - /** * {@inheritDoc} */ @@ -53,7 +42,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $sql = (string) $this->dataSource; @@ -70,7 +58,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - protected function applyFilterDate(FilterDate $filter): void { $conditions = $filter->getCondition(); @@ -86,12 +73,11 @@ protected function applyFilterDate(FilterDate $filter): void $filter->getColumn(), $date->format('Ymd') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -116,7 +102,6 @@ protected function applyFilterDateRange(FilterDateRange $filter): void } } - protected function applyFilterText(FilterText $filter): void { $condition = $filter->getCondition(); @@ -124,21 +109,22 @@ protected function applyFilterText(FilterText $filter): void $or = []; foreach ($condition as $column => $value) { - $column = Helpers::escape($driver, $column, \dibi::IDENTIFIER); + $column = Helpers::escape($driver, $column, dibi::IDENTIFIER); if ($filter->isExactSearch()) { - $this->dataSource->where("$column = %s", $value); + $this->dataSource->where(sprintf('%s = %%s', $column), $value); continue; } - $or[] = "$column LIKE \"%$value%\""; + $or[] = sprintf('%s LIKE "%%%s%%"', $column, $value); } - if (sizeof($or) > 1) { + if (count($or) > 1) { $this->dataSource->where('(%or)', $or); } else { $this->dataSource->where($or); } } + } diff --git a/src/DataSource/DibiFluentPostgreDataSource.php b/src/DataSource/DibiFluentPostgreDataSource.php index 3c9f08074..c2cd0fb68 100755 --- a/src/DataSource/DibiFluentPostgreDataSource.php +++ b/src/DataSource/DibiFluentPostgreDataSource.php @@ -1,6 +1,4 @@ -isExactSearch()) { - $this->dataSource->where("$column = %s", $value); + $this->dataSource->where(sprintf('%s = %%s', $column), $value); continue; } @@ -28,14 +26,15 @@ protected function applyFilterText(FilterText $filter): void $words = $filter->hasSplitWordsSearch() === false ? [$value] : explode(' ', $value); foreach ($words as $word) { - $or[] = "$column ILIKE " . $driver->escapeText('%' . $word . '%'); + $or[] = $column . ' ILIKE ' . $driver->escapeText('%' . $word . '%'); } } - if (sizeof($or) > 1) { + if (count($or) > 1) { $this->dataSource->where('(%or)', $or); } else { $this->dataSource->where($or); } } + } diff --git a/src/DataSource/DoctrineCollectionDataSource.php b/src/DataSource/DoctrineCollectionDataSource.php index 9f4806c19..a47787c6d 100755 --- a/src/DataSource/DoctrineCollectionDataSource.php +++ b/src/DataSource/DoctrineCollectionDataSource.php @@ -1,12 +1,11 @@ -criteria = Criteria::create(); $this->dataSource = $collection; - $this->primaryKey = $primaryKey; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { return $this->dataSource->matching($this->criteria)->count(); } - /** * {@inheritDoc} */ @@ -71,7 +51,6 @@ public function getData(): array return $this->dataSource->matching($this->criteria)->toArray(); } - /** * {@inheritDoc} */ @@ -89,7 +68,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->criteria->setFirstResult($offset)->setMaxResults($limit); @@ -97,7 +75,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -121,22 +98,19 @@ public function sort(Sorting $sorting): IDataSource return $this; } - public function processAggregation(IAggregationFunction $function): void { $function->processDataSource(clone $this->dataSource); } - /** - * {@inheritDoc} + * @return Collection&Selectable */ - public function getDataSource() + public function getDataSource(): mixed { return $this->dataSource; } - protected function applyFilterDate(FilterDate $filter): void { foreach ($filter->getCondition() as $value) { @@ -147,13 +121,12 @@ protected function applyFilterDate(FilterDate $filter): void $to = Criteria::expr()->lte($filter->getColumn(), $date->format('Y-m-d 23:59:59')); $this->criteria->andWhere($from)->andWhere($to); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -161,34 +134,33 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $valueFrom = $values['from']; - if ((bool) $valueFrom) { + if ($valueFrom) { try { $dateFrom = DateTimeHelper::tryConvertToDateTime($valueFrom, [$filter->getPhpFormat()]); $dateFrom->setTime(0, 0, 0); $expr = Criteria::expr()->gte($filter->getColumn(), $dateFrom->format('Y-m-d H:i:s')); $this->criteria->andWhere($expr); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } $valueTo = $values['to']; - if ((bool) $valueTo) { + if ($valueTo) { try { $dateTo = DateTimeHelper::tryConvertToDateTime($valueTo, [$filter->getPhpFormat()]); $dateTo->setTime(23, 59, 59); $expr = Criteria::expr()->lte($filter->getColumn(), $dateTo->format('Y-m-d H:i:s')); $this->criteria->andWhere($expr); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterRange(FilterRange $filter): void { $conditions = $filter->getCondition(); @@ -207,7 +179,6 @@ protected function applyFilterRange(FilterRange $filter): void } } - protected function applyFilterText(FilterText $filter): void { $exprs = []; @@ -230,7 +201,6 @@ protected function applyFilterText(FilterText $filter): void $this->criteria->andWhere($expr); } - protected function applyFilterMultiSelect(FilterMultiSelect $filter): void { $values = $filter->getCondition()[$filter->getColumn()]; @@ -239,7 +209,6 @@ protected function applyFilterMultiSelect(FilterMultiSelect $filter): void $this->criteria->andWhere($expr); } - protected function applyFilterSelect(FilterSelect $filter): void { foreach ($filter->getCondition() as $column => $value) { diff --git a/src/DataSource/DoctrineDataSource.php b/src/DataSource/DoctrineDataSource.php index 7d01d222e..8cd1a40a4 100755 --- a/src/DataSource/DoctrineDataSource.php +++ b/src/DataSource/DoctrineDataSource.php @@ -1,6 +1,4 @@ - - */ - protected $hints = []; + protected int $placeholder = 0; + /** @var array */ + protected array $hints = []; - public function __construct(QueryBuilder $dataSource, string $primaryKey) + public function __construct(QueryBuilder $dataSource, protected string $primaryKey) { $this->placeholder = count($dataSource->getParameters()); $this->dataSource = $dataSource; - $this->primaryKey = $primaryKey; } - - /** - * @param mixed $value - */ - public function setQueryHint(string $name, $value): IDataSource + public function setQueryHint(string $name, mixed $value): IDataSource { $this->hints[$name] = $value; return $this; } - public function getQuery(): Query { $query = $this->dataSource->getQuery(); @@ -93,12 +68,6 @@ public function getQuery(): Query return $query; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { if ($this->usePaginator()) { @@ -112,7 +81,6 @@ public function getCount(): int return (int) $dataSource->getQuery()->getSingleScalarResult(); } - /** * {@inheritDoc} */ @@ -131,7 +99,6 @@ public function getData(): array return $data; } - /** * {@inheritDoc} */ @@ -142,14 +109,13 @@ public function filterOne(array $condition): IDataSource foreach ($condition as $column => $value) { $c = $this->checkAliases($column); - $this->dataSource->andWhere("$c = :$p") + $this->dataSource->andWhere(sprintf('%s = :%s', $c, $p)) ->setParameter($p, $value); } return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->dataSource->setFirstResult($offset)->setMaxResults($limit); @@ -157,7 +123,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -188,26 +153,23 @@ public function sort(Sorting $sorting): IDataSource return $this; } - /** * Get unique int value for each instance class (self) */ public function getPlaceholder(): string { - $return = 'param' . (string) ($this->placeholder + 1); + $return = 'param' . ($this->placeholder + 1); $this->placeholder++; return $return; } - public function processAggregation(IAggregationFunction $function): void { $function->processDataSource(clone $this->dataSource); } - protected function applyFilterDate(FilterDate $filter): void { $p1 = $this->getPlaceholder(); @@ -218,16 +180,15 @@ protected function applyFilterDate(FilterDate $filter): void $date = DateTimeHelper::tryConvertToDateTime($value, [$filter->getPhpFormat()]); $c = $this->checkAliases($column); - $this->dataSource->andWhere("$c >= :$p1 AND $c <= :$p2") + $this->dataSource->andWhere(sprintf('%s >= :%s AND %s <= :%s', $c, $p1, $c, $p2)) ->setParameter($p1, $date->format('Y-m-d 00:00:00')) ->setParameter($p2, $date->format('Y-m-d 23:59:59')); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -243,11 +204,11 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $p = $this->getPlaceholder(); - $this->dataSource->andWhere("$c >= :$p")->setParameter( + $this->dataSource->andWhere(sprintf('%s >= :%s', $c, $p))->setParameter( $p, $dateFrom->format('Y-m-d H:i:s') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -259,17 +220,16 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $p = $this->getPlaceholder(); - $this->dataSource->andWhere("$c <= :$p")->setParameter( + $this->dataSource->andWhere(sprintf('%s <= :%s', $c, $p))->setParameter( $p, $dateTo->format('Y-m-d H:i:s') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterRange(FilterRange $filter): void { $conditions = $filter->getCondition(); @@ -280,16 +240,15 @@ protected function applyFilterRange(FilterRange $filter): void if (is_numeric($valueFrom)) { $p = $this->getPlaceholder(); - $this->dataSource->andWhere("$c >= :$p")->setParameter($p, $valueFrom); + $this->dataSource->andWhere(sprintf('%s >= :%s', $c, $p))->setParameter($p, $valueFrom); } if (is_numeric($valueTo)) { $p = $this->getPlaceholder(); - $this->dataSource->andWhere("$c <= :$p")->setParameter($p, $valueTo); + $this->dataSource->andWhere(sprintf('%s <= :%s', $c, $p))->setParameter($p, $valueTo); } } - protected function applyFilterText(FilterText $filter): void { $condition = $filter->getCondition(); @@ -313,7 +272,7 @@ protected function applyFilterText(FilterText $filter): void $exprs[] = $this->dataSource->expr()->like( $this->dataSource->expr()->lower($c), $this->dataSource->expr()->lower( - $this->dataSource->expr()->literal("%$word%") + $this->dataSource->expr()->literal('%' . $word . '%') ) ); } @@ -324,7 +283,6 @@ protected function applyFilterText(FilterText $filter): void $this->dataSource->andWhere($or); } - protected function applyFilterMultiSelect(FilterMultiSelect $filter): void { $c = $this->checkAliases($filter->getColumn()); @@ -336,7 +294,6 @@ protected function applyFilterMultiSelect(FilterMultiSelect $filter): void $this->dataSource->andWhere($expr)->setParameter($p, $values); } - protected function applyFilterSelect(FilterSelect $filter): void { $p = $this->getPlaceholder(); @@ -344,24 +301,19 @@ protected function applyFilterSelect(FilterSelect $filter): void foreach ($filter->getCondition() as $column => $value) { $c = $this->checkAliases($column); - $this->dataSource->andWhere("$c = :$p") + $this->dataSource->andWhere(sprintf('%s = :%s', $c, $p)) ->setParameter($p, $value); } } - - /** - * {@inheritDoc} - */ - protected function getDataSource() + protected function getDataSource(): QueryBuilder { return $this->dataSource; } - private function checkAliases(string $column): string { - if (Strings::contains($column, '.')) { + if (str_contains($column, '.')) { return $column; } @@ -378,7 +330,6 @@ private function checkAliases(string $column): string return $this->rootAlias . '.' . $column; } - private function usePaginator(): bool { $hasJoin = (bool) $this->dataSource->getDQLPart('join'); @@ -386,4 +337,5 @@ private function usePaginator(): bool return $hasJoin || $hasGroupBy; } + } diff --git a/src/DataSource/ElasticsearchDataSource.php b/src/DataSource/ElasticsearchDataSource.php index 50a409da0..a57d012ec 100644 --- a/src/DataSource/ElasticsearchDataSource.php +++ b/src/DataSource/ElasticsearchDataSource.php @@ -1,10 +1,9 @@ -client = $client; $this->searchParamsBuilder = new SearchParamsBuilder($indexName); if ($rowFactory === null) { - $rowFactory = static function (array $hit): array { - return $hit['_source']; - }; + $rowFactory = static fn (array $hit): array => $hit['_source']; } $this->rowFactory = $rowFactory; } - public function getCount(): int { $searchResult = $this->client->search($this->searchParamsBuilder->buildParams()); if (!isset($searchResult['hits'])) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } return is_array($searchResult['hits']['total']) @@ -60,7 +46,6 @@ public function getCount(): int : $searchResult['hits']['total']; } - /** * {@inheritDoc} */ @@ -69,13 +54,12 @@ public function getData(): array $searchResult = $this->client->search($this->searchParamsBuilder->buildParams()); if (!isset($searchResult['hits'])) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } return array_map($this->rowFactory, $searchResult['hits']['hits']); } - /** * {@inheritDoc} */ @@ -88,7 +72,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->searchParamsBuilder->setFrom($offset); @@ -97,7 +80,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function applyFilterDate(FilterDate $filter): void { foreach ($filter->getCondition() as $column => $value) { @@ -120,7 +102,6 @@ public function applyFilterDate(FilterDate $filter): void } } - public function applyFilterDateRange(FilterDateRange $filter): void { foreach ($filter->getCondition() as $column => $values) { @@ -147,7 +128,6 @@ public function applyFilterDateRange(FilterDateRange $filter): void } } - public function applyFilterRange(FilterRange $filter): void { foreach ($filter->getCondition() as $column => $value) { @@ -155,7 +135,6 @@ public function applyFilterRange(FilterRange $filter): void } } - public function applyFilterText(FilterText $filter): void { foreach ($filter->getCondition() as $column => $value) { @@ -167,7 +146,6 @@ public function applyFilterText(FilterText $filter): void } } - public function applyFilterMultiSelect(FilterMultiSelect $filter): void { foreach ($filter->getCondition() as $column => $values) { @@ -175,7 +153,6 @@ public function applyFilterMultiSelect(FilterMultiSelect $filter): void } } - public function applyFilterSelect(FilterSelect $filter): void { foreach ($filter->getCondition() as $column => $value) { @@ -183,15 +160,15 @@ public function applyFilterSelect(FilterSelect $filter): void } } - /** * {@inheritDoc} - * @throws \RuntimeException + * + * @throws RuntimeException */ public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { - throw new \RuntimeException('No can do - not implemented yet'); + throw new RuntimeException('No can do - not implemented yet'); } foreach ($sorting->getSort() as $column => $order) { @@ -203,11 +180,7 @@ public function sort(Sorting $sorting): IDataSource return $this; } - - /** - * {@inheritDoc} - */ - protected function getDataSource() + protected function getDataSource(): Client { return $this->client; } diff --git a/src/DataSource/FilterableDataSource.php b/src/DataSource/FilterableDataSource.php index 26caf414d..ea17f0919 100644 --- a/src/DataSource/FilterableDataSource.php +++ b/src/DataSource/FilterableDataSource.php @@ -1,6 +1,4 @@ -dataSource = $dataSource; - $this->primaryKey = $primaryKey; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { $dataSourceSqlBuilder = $this->dataSource->getSqlBuilder(); @@ -56,7 +33,7 @@ public function getCount(): int try { $primary = $this->dataSource->getPrimary(); - } catch (LogicException $e) { + } catch (LogicException) { if ($dataSourceSqlBuilder->getGroup() !== '') { return $this->dataSource->count( 'DISTINCT ' . Strings::replace($dataSourceSqlBuilder->getGroup(), '~ (DESC|ASC)~') @@ -77,7 +54,6 @@ public function getCount(): int ); } - /** * {@inheritDoc} */ @@ -88,7 +64,6 @@ public function getData(): array : $this->dataSource->fetchAll(); } - /** * {@inheritDoc} */ @@ -99,7 +74,6 @@ public function filterOne(array $condition): IDataSource return $this; } - /** * @phpstan-param positive-int|0 $offset * @phpstan-param positive-int|0 $limit @@ -111,7 +85,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -130,7 +103,7 @@ public function sort(Sorting $sorting): IDataSource $this->dataSource->getSqlBuilder()->setOrder([], []); foreach ($sort as $column => $order) { - $this->dataSource->order("$column $order"); + $this->dataSource->order(sprintf('%s %s', $column, $order)); } } else { /** @@ -144,13 +117,11 @@ public function sort(Sorting $sorting): IDataSource return $this; } - public function processAggregation(IAggregationFunction $function): void { $function->processDataSource(clone $this->dataSource); } - protected function applyFilterDate(FilterDate $filter): void { $conditions = $filter->getCondition(); @@ -158,13 +129,12 @@ protected function applyFilterDate(FilterDate $filter): void try { $date = DateTimeHelper::tryConvertToDateTime($conditions[$filter->getColumn()], [$filter->getPhpFormat()]); - $this->dataSource->where("DATE({$filter->getColumn()}) = ?", $date->format('Y-m-d')); - } catch (DataGridDateTimeHelperException $ex) { + $this->dataSource->where(sprintf('DATE(%s) = ?', $filter->getColumn()), $date->format('Y-m-d')); + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -178,10 +148,10 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateFrom->setTime(0, 0, 0); $this->dataSource->where( - "DATE({$filter->getColumn()}) >= ?", + sprintf('DATE(%s) >= ?', $filter->getColumn()), $dateFrom->format('Y-m-d') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -191,14 +161,16 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateTo = DateTimeHelper::tryConvertToDateTime($valueTo, [$filter->getPhpFormat()]); $dateTo->setTime(23, 59, 59); - $this->dataSource->where("DATE({$filter->getColumn()}) <= ?", $dateTo->format('Y-m-d')); - } catch (DataGridDateTimeHelperException $ex) { + $this->dataSource->where( + sprintf('DATE(%s) <= ?', $filter->getColumn()), + $dateTo->format('Y-m-d') + ); + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterRange(FilterRange $filter): void { $conditions = $filter->getCondition(); @@ -207,15 +179,14 @@ protected function applyFilterRange(FilterRange $filter): void $valueTo = $conditions[$filter->getColumn()]['to']; if ($valueFrom) { - $this->dataSource->where("{$filter->getColumn()} >= ?", $valueFrom); + $this->dataSource->where(sprintf('%s >= ?', $filter->getColumn()), $valueFrom); } if ($valueTo) { - $this->dataSource->where("{$filter->getColumn()} <= ?", $valueTo); + $this->dataSource->where(sprintf('%s <= ?', $filter->getColumn()), $valueTo); } } - protected function applyFilterText(FilterText $filter): void { $or = []; @@ -229,49 +200,48 @@ protected function applyFilterText(FilterText $filter): void $args = []; if ($filter->isExactSearch()) { - $like .= "$column = ? OR "; - $args[] = "$value"; + $like .= sprintf('%s = ? OR ', $column); + $args[] = sprintf('%s', $value); } else { $words = $filter->hasSplitWordsSearch() === false ? [$value] : explode(' ', $value); foreach ($words as $word) { - $like .= "$column LIKE ? OR "; - $args[] = "%$word%"; + $like .= sprintf('%s LIKE ? OR ', $column); + $args[] = sprintf('%%%s%%', $word); } } $like = substr($like, 0, strlen($like) - 4) . ')'; $or[] = $like; - $bigOr .= "$like OR "; - $bigOrArgs = array_merge($bigOrArgs, $args); + $bigOr .= sprintf('%s OR ', $like); + $bigOrArgs = [...$bigOrArgs, ...$args]; } - if (sizeof($or) > 1) { + if (count($or) > 1) { $bigOr = substr($bigOr, 0, strlen($bigOr) - 4) . ')'; - $query = array_merge([$bigOr], $bigOrArgs); + $query = [...[$bigOr], ...$bigOrArgs]; call_user_func_array([$this->dataSource, 'where'], $query); } else { - $query = array_merge($or, $args); + $query = [...$or, ...$args]; call_user_func_array([$this->dataSource, 'where'], $query); } } - protected function applyFilterMultiSelect(FilterMultiSelect $filter): void { $condition = $filter->getCondition(); $values = $condition[$filter->getColumn()]; $or = '('; - if (sizeof($values) > 1) { - $length = sizeof($values); + if ((is_countable($values) ? count($values) : 0) > 1) { + $length = is_countable($values) ? count($values) : 0; $i = 1; - for ($iterator = 0; $iterator < count($values); $iterator++) { + for ($iterator = 0; $iterator < (is_countable($values) ? count($values) : 0); $iterator++) { if ($i === $length) { $or .= $filter->getColumn() . ' = ?)'; } else { @@ -289,18 +259,14 @@ protected function applyFilterMultiSelect(FilterMultiSelect $filter): void } } - protected function applyFilterSelect(FilterSelect $filter): void { $this->dataSource->where($filter->getCondition()); } - - /** - * {@inheritDoc} - */ - protected function getDataSource() + protected function getDataSource(): Selection { return $this->dataSource; } + } diff --git a/src/DataSource/NetteDatabaseTableMssqlDataSource.php b/src/DataSource/NetteDatabaseTableMssqlDataSource.php index 20249f83a..05e890f38 100755 --- a/src/DataSource/NetteDatabaseTableMssqlDataSource.php +++ b/src/DataSource/NetteDatabaseTableMssqlDataSource.php @@ -1,6 +1,4 @@ -getColumn()], [$filter->getPhpFormat()]); $this->dataSource->where( - "CONVERT(varchar(10), {$filter->getColumn()}, 112) = ?", + sprintf('CONVERT(varchar(10), %s, 112) = ?', $filter->getColumn()), $date->format('Ymd') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -42,10 +39,10 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateFrom->setTime(0, 0, 0); $this->dataSource->where( - "CONVERT(varchar(10), {$filter->getColumn()}, 112) >= ?", + sprintf('CONVERT(varchar(10), %s, 112) >= ?', $filter->getColumn()), $dateFrom->format('Ymd') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -56,12 +53,13 @@ protected function applyFilterDateRange(FilterDateRange $filter): void $dateTo->setTime(23, 59, 59); $this->dataSource->where( - "CONVERT(varchar(10), {$filter->getColumn()}, 112) <= ?", + sprintf('CONVERT(varchar(10), %s, 112) <= ?', $filter->getColumn()), $dateTo->format('Ymd') ); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } + } diff --git a/src/DataSource/NextrasDataSource.php b/src/DataSource/NextrasDataSource.php index c78127c7a..729e50961 100755 --- a/src/DataSource/NextrasDataSource.php +++ b/src/DataSource/NextrasDataSource.php @@ -1,10 +1,8 @@ -dataSource = $dataSource; - $this->primaryKey = $primaryKey; // Support version 4.0 with 3.1 backward compatibility - $this->dbalCollectionClass = class_exists('Nextras\Orm\Collection\DbalCollection') - ? 'Nextras\Orm\Collection\DbalCollection' + $this->dbalCollectionClass = class_exists(DbalCollection::class) + ? DbalCollection::class : 'Nextras\Orm\Mapper\Dbal\DbalCollection'; } - - // ******************************************************************************* - // * IDataSource implementation * - // ******************************************************************************* - - public function getCount(): int { return $this->dataSource->countStored(); } - /** * {@inheritDoc} */ @@ -79,7 +54,6 @@ public function getData(): array : $this->dataSource->fetchAll(); } - /** * {@inheritDoc} */ @@ -96,7 +70,6 @@ public function filterOne(array $condition): IDataSource return $this; } - public function limit(int $offset, int $limit): IDataSource { $this->dataSource = $this->dataSource->limitBy($limit, $offset); @@ -104,7 +77,6 @@ public function limit(int $offset, int $limit): IDataSource return $this; } - public function sort(Sorting $sorting): IDataSource { if (is_callable($sorting->getSortCallback())) { @@ -132,7 +104,7 @@ public function sort(Sorting $sorting): IDataSource sprintf( 'Expeting %s, got %s', $this->dbalCollectionClass, - get_class($this->dataSource) + $this->dataSource::class ) ); } @@ -154,10 +126,9 @@ public function sort(Sorting $sorting): IDataSource public function processAggregation(IAggregationFunction $function): void { - $function->processDataSource( clone $this->dataSource ); + $function->processDataSource(clone $this->dataSource); } - protected function applyFilterDate(FilterDate $filter): void { foreach ($filter->getCondition() as $column => $value) { @@ -169,13 +140,12 @@ protected function applyFilterDate(FilterDate $filter): void $this->prepareColumn($column) . '>=' => $date->setTime(0, 0, 0), $this->prepareColumn($column) . '<=' => $date_end->setTime(23, 59, 59), ]); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } } - protected function applyFilterDateRange(FilterDateRange $filter): void { $conditions = $filter->getCondition(); @@ -192,7 +162,7 @@ protected function applyFilterDateRange(FilterDateRange $filter): void [$filter->getPhpFormat()] ); $dataCondition[$this->prepareColumn($filter->getColumn()) . '>='] = $dateFrom->setTime(0, 0, 0); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -204,7 +174,7 @@ protected function applyFilterDateRange(FilterDateRange $filter): void [$filter->getPhpFormat()] ); $dataCondition[$this->prepareColumn($filter->getColumn()) . '<='] = $dateTo->setTime(23, 59, 59); - } catch (DataGridDateTimeHelperException $ex) { + } catch (DataGridDateTimeHelperException) { // ignore the invalid filter value } } @@ -214,7 +184,6 @@ protected function applyFilterDateRange(FilterDateRange $filter): void } } - protected function applyFilterRange(FilterRange $filter): void { $conditions = $filter->getCondition(); @@ -237,7 +206,6 @@ protected function applyFilterRange(FilterRange $filter): void } } - protected function applyFilterText(FilterText $filter): void { // native handling with LikeFunction in v4 @@ -277,7 +245,7 @@ protected function applyFilterText(FilterText $filter): void if ($filter->isExactSearch()) { $expr .= '%column = %s OR '; $params[] = $column; - $params[] = "$value"; + $params[] = sprintf('%s', $value); continue; } @@ -287,7 +255,7 @@ protected function applyFilterText(FilterText $filter): void foreach ($words as $word) { $expr .= '%column LIKE %s OR '; $params[] = $column; - $params[] = "%$word%"; + $params[] = sprintf('%%%s%%', $word); } } @@ -300,7 +268,7 @@ protected function applyFilterText(FilterText $filter): void sprintf( 'Expeting %s, got %s', $this->dbalCollectionClass, - get_class($this->dataSource) + $this->dataSource::class ) ); } @@ -308,13 +276,11 @@ protected function applyFilterText(FilterText $filter): void $this->dataSource->getQueryBuilder()->andWhere(...$params); } - protected function applyFilterMultiSelect(FilterMultiSelect $filter): void { $this->applyFilterSelect($filter); } - protected function applyFilterSelect(FilterSelect $filter): void { $this->dataSource = $this->dataSource->findBy( @@ -322,24 +288,19 @@ protected function applyFilterSelect(FilterSelect $filter): void ); } - - /** - * {@inheritDoc} - */ - protected function getDataSource() + protected function getDataSource(): ICollection { return $this->dataSource; } - /** * Adjust column from DataGrid 'foreignKey.column' to Nextras 'this->foreignKey->column' */ private function prepareColumn(string $column): string { - if (Strings::contains($column, '.')) { + if (str_contains($column, '.')) { // 'this->' is deprecated in v4 - $prefix = $this->dbalCollectionClass === 'Nextras\Orm\Collection\DbalCollection' + $prefix = $this->dbalCollectionClass === DbalCollection::class ? '' : 'this->'; @@ -348,4 +309,5 @@ private function prepareColumn(string $column): string return $column; } + } diff --git a/src/DataSource/SearchParamsBuilder.php b/src/DataSource/SearchParamsBuilder.php index 642f85661..f1c4adee6 100644 --- a/src/DataSource/SearchParamsBuilder.php +++ b/src/DataSource/SearchParamsBuilder.php @@ -1,115 +1,70 @@ -indexName = $indexName; } - public function addPhrasePrefixQuery(string $field, string $query): void { $this->phrasePrefixQueries[] = [$field => $query]; } - - /** - * @param mixed $query - */ - public function addMatchQuery(string $field, $query): void + public function addMatchQuery(string $field, mixed $query): void { $this->matchQueries[] = [$field => $query]; } - public function addBooleanMatchQuery(string $field, array $queries): void { $this->booleanMatchQueries[] = [$field => $queries]; } - public function addRangeQuery(string $field, ?int $from, ?int $to): void { $this->rangeQueries[] = [$field => ['from' => $from, 'to' => $to]]; } - public function addIdsQuery(array $ids): void { $this->idsQueries[] = $ids; } - public function setSort(array $sort): void { $this->sort = $sort; } - public function setFrom(int $from): void { $this->from = $from; } - public function setSize(int $size): void { $this->size = $size; } - public function buildParams(): array { $return = [ @@ -226,4 +181,5 @@ public function buildParams(): array return $return; } + } diff --git a/src/Exception/DataGridActionCallbackException.php b/src/Exception/DataGridActionCallbackException.php index cbc66b25a..eaca2762a 100644 --- a/src/Exception/DataGridActionCallbackException.php +++ b/src/Exception/DataGridActionCallbackException.php @@ -1,6 +1,4 @@ -grid = $grid; $this->text = $text; $this->callback = $callback; - $this->filtered = $filtered; $this->title = $text; } - public function render(): Html { $a = Html::el('a', [ @@ -106,7 +74,6 @@ public function render(): Html return $a; } - /** * @return static */ @@ -117,7 +84,6 @@ public function setConfirmDialog(string $confirmDialog): self return $this; } - /** * Tell export which columns to use when exporting data * @@ -130,7 +96,6 @@ public function setColumns(array $columns): self return $this; } - /** * Get columns for export */ @@ -139,7 +104,6 @@ public function getColumns(): array return $this->columns; } - /** * Export signal url * @@ -152,7 +116,6 @@ public function setLink(Link $link): self return $this; } - /** * Tell export whether to be called via ajax or not * @@ -165,13 +128,11 @@ public function setAjax(bool $ajax = true): self return $this; } - public function isAjax(): bool { return $this->ajax; } - /** * Is export filtered? */ @@ -180,7 +141,6 @@ public function isFiltered(): bool return $this->filtered; } - /** * Call export callback */ @@ -189,15 +149,14 @@ public function invoke(iterable $data): void ($this->callback)($data, $this->grid); } - /** * Adds target to html:a [_blank, _self, _parent, _top] - * @param string|null $target */ - public function setTarget($target = null): void + public function setTarget(?string $target = null): void { if (in_array($target, ['_blank', '_self', '_parent', '_top'], true)) { $this->target = $target; } } + } diff --git a/src/Export/ExportCsv.php b/src/Export/ExportCsv.php index 9e219fac2..892b385ee 100644 --- a/src/Export/ExportCsv.php +++ b/src/Export/ExportCsv.php @@ -1,6 +1,4 @@ -getColumns(); if ($columns === []) { @@ -62,4 +64,5 @@ private function getExportCallback( )); }; } + } diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 18e13813b..0757f196f 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -1,87 +1,41 @@ - ['form-control', 'input-sm', 'form-control-sm'], ]; - /** - * @var string|null - */ - private $placeholder; - + private ?string $placeholder = null; abstract public function getCondition(): array; - - public function __construct( - DataGrid $grid, - string $key, - string $name - ) + public function __construct(protected DataGrid $grid, protected string $key, protected string $name) { - $this->grid = $grid; - $this->key = $key; - $this->name = $name; } - /** * Get filter key */ @@ -90,7 +44,6 @@ public function getKey(): string return $this->key; } - /** * Get filter name */ @@ -99,7 +52,6 @@ public function getName(): string return $this->name; } - /** * Tell whether value has been set in this fitler */ @@ -108,12 +60,10 @@ public function isValueSet(): bool return $this->valueSet; } - /** - * @param mixed $value * @return static */ - public function setValue($value): self + public function setValue(mixed $value): self { $this->value = $value; $this->valueSet = true; @@ -121,16 +71,11 @@ public function setValue($value): self return $this; } - - /** - * @return mixed - */ - public function getValue() + public function getValue(): mixed { return $this->value; } - /** * Set HTML attribute "placeholder" * @@ -143,13 +88,11 @@ public function setPlaceholder(string $placeholder): self return $this; } - public function getPlaceholder(): ?string { return $this->placeholder; } - /** * Set custom condition on filter * @@ -162,13 +105,11 @@ public function setCondition(callable $conditionCallback): self return $this; } - public function getConditionCallback(): ?callable { return $this->conditionCallback; } - /** * @return static */ @@ -179,49 +120,41 @@ public function setTemplate(string $template): self return $this; } - public function getTemplate(): ?string { return $this->template; } - public function getType(): ?string { return $this->type; } - /** - * @param mixed $value * @return static */ - public function addAttribute(string $name, $value): self + public function addAttribute(string $name, mixed $value): self { $this->attributes[$name][] = $value; return $this; } - /** - * @param mixed $value * @return static */ - public function setAttribute(string $name, $value): self + public function setAttribute(string $name, mixed $value): self { $this->attributes[$name] = (array) $value; return $this; } - public function getAttributes(): array { return $this->attributes; } - protected function addAttributes(BaseControl $input): BaseControl { if ($this->grid->hasAutoSubmit()) { diff --git a/src/Filter/FilterDate.php b/src/Filter/FilterDate.php index d000d4f0e..b793de94d 100644 --- a/src/Filter/FilterDate.php +++ b/src/Filter/FilterDate.php @@ -1,6 +1,4 @@ -format[0]; } - /** * Get js format for datepicker */ diff --git a/src/Filter/FilterDateRange.php b/src/Filter/FilterDateRange.php index 83ef35186..58c546ff9 100644 --- a/src/Filter/FilterDateRange.php +++ b/src/Filter/FilterDateRange.php @@ -1,6 +1,4 @@ -format[0]; } - /** * Get js format for datepicker */ diff --git a/src/Filter/FilterMultiSelect.php b/src/Filter/FilterMultiSelect.php index 0707aca0c..5585e8cb9 100644 --- a/src/Filter/FilterMultiSelect.php +++ b/src/Filter/FilterMultiSelect.php @@ -1,6 +1,4 @@ - ['form-control', 'input-sm', 'selectpicker', 'form-control-sm'], 'data-selected-text-format' => ['count'], ]; - public function __construct( DataGrid $grid, string $key, @@ -40,7 +32,6 @@ public function __construct( $this->addAttribute('data-selected-icon-check', DataGrid::$iconPrefix . 'check'); } - /** * Get filter condition */ @@ -55,7 +46,6 @@ public function getCondition(): array return $return; } - protected function addControl( Container $container, string $key, @@ -66,7 +56,7 @@ protected function addControl( /** * Set some translated texts */ - $form = $container->lookup('Nette\Application\UI\Form'); + $form = $container->lookup(Form::class); if (!$form instanceof Form) { throw new UnexpectedValueException(); @@ -96,4 +86,5 @@ protected function addControl( return $input; } + } diff --git a/src/Filter/FilterRange.php b/src/Filter/FilterRange.php index 48c91d80a..d0bbdaa0e 100644 --- a/src/Filter/FilterRange.php +++ b/src/Filter/FilterRange.php @@ -1,6 +1,4 @@ -nameSecond = $nameSecond; } - public function addToFormContainer(Container $container): void { $container = $container->addContainer($this->key); @@ -72,7 +53,6 @@ public function addToFormContainer(Container $container): void } } - /** * Set html attr placeholder of both inputs * @@ -85,7 +65,6 @@ public function setPlaceholders(array $placeholders): self return $this; } - /** * Get html attr placeholders */ @@ -94,7 +73,6 @@ public function getPlaceholders(): array return $this->placeholders; } - /** * Get filter condition */ @@ -109,4 +87,5 @@ public function getCondition(): array ], ]; } + } diff --git a/src/Filter/FilterSelect.php b/src/Filter/FilterSelect.php index 56ade6aa6..9b916e7fc 100644 --- a/src/Filter/FilterSelect.php +++ b/src/Filter/FilterSelect.php @@ -1,6 +1,4 @@ -options = $options; } - public function addToFormContainer(Container $container): void { $form = $container->lookup(Form::class); @@ -74,7 +51,6 @@ public function addToFormContainer(Container $container): void } } - /** * @return static */ @@ -85,31 +61,26 @@ public function setTranslateOptions(bool $translateOptions = true): self return $this; } - public function getOptions(): array { return $this->options; } - public function getTranslateOptions(): bool { return $this->translateOptions; } - public function getCondition(): array { return [$this->column => $this->getValue()]; } - public function getPrompt(): ?string { return $this->prompt; } - /** * @return static */ @@ -120,7 +91,6 @@ public function setPrompt(?string $prompt): self return $this; } - protected function addControl( Container $container, string $key, @@ -138,4 +108,5 @@ protected function addControl( return $input; } + } diff --git a/src/Filter/FilterText.php b/src/Filter/FilterText.php index 3860d7984..9f968402c 100644 --- a/src/Filter/FilterText.php +++ b/src/Filter/FilterText.php @@ -1,6 +1,4 @@ -columns = $columns; } - /** * Adds text field to filter form */ @@ -65,7 +43,6 @@ public function addToFormContainer(Container $container): void } } - /** * Return array of conditions to put in result [column1 => value, column2 => value] * If more than one column exists in fitler text, @@ -77,13 +54,11 @@ public function getCondition(): array return array_fill_keys($this->columns, $this->getValue()); } - public function isExactSearch(): bool { return $this->exact; } - /** * @return static */ @@ -94,7 +69,6 @@ public function setExactSearch(bool $exact = true): self return $this; } - /** * @return static */ @@ -105,9 +79,9 @@ public function setSplitWordsSearch(bool $splitWordsSearch): self return $this; } - public function hasSplitWordsSearch(): bool { return $this->splitWordsSearch; } + } diff --git a/src/Filter/IFilterDate.php b/src/Filter/IFilterDate.php index cfe8b9f17..bc20d1418 100644 --- a/src/Filter/IFilterDate.php +++ b/src/Filter/IFilterDate.php @@ -1,6 +1,4 @@ -column = $column; } - /** * Get filter column */ @@ -36,9 +25,9 @@ public function getColumn(): string return $this->column; } - public function getCondition(): array { return [$this->column => $this->getValue()]; } + } diff --git a/src/Filter/SubmitButton.php b/src/Filter/SubmitButton.php index 72dce15fa..cf5213611 100644 --- a/src/Filter/SubmitButton.php +++ b/src/Filter/SubmitButton.php @@ -1,6 +1,4 @@ -text); - $this->grid = $grid; - $this->text = 'ublaboo_datagrid.filter_submit_button'; $this->class = 'btn btn-sm btn-primary'; $this->icon = 'search'; @@ -41,11 +31,7 @@ public function __construct(DataGrid $grid) $this->control = Html::el('button', ['type' => 'submit', 'name' => 'submit']); } - - /** - * @param string|object $caption - */ - public function getControl($caption = null): Html + public function getControl(string|object|null $caption = null): Html { $el = parent::getControl($caption); @@ -69,4 +55,5 @@ public function getControl($caption = null): Html return $el; } + } diff --git a/src/GroupAction/GroupAction.php b/src/GroupAction/GroupAction.php index cd343fb88..40d073851 100644 --- a/src/GroupAction/GroupAction.php +++ b/src/GroupAction/GroupAction.php @@ -1,6 +1,4 @@ -title = $title; } - public function getTitle(): string { return $this->title; } - /** * @return static */ @@ -57,27 +39,24 @@ public function setClass(string $class): self return $this; } - public function getClass(): string { return $this->class; } - /** - * @param mixed $value * @return static */ - public function setAttribute(string $key, $value): self + public function setAttribute(string $key, mixed $value): self { $this->attributes[$key] = $value; return $this; } - public function getAttributes(): array { return $this->attributes; } + } diff --git a/src/GroupAction/GroupActionCollection.php b/src/GroupAction/GroupActionCollection.php index 488ef61e1..c1421db5a 100644 --- a/src/GroupAction/GroupActionCollection.php +++ b/src/GroupAction/GroupActionCollection.php @@ -1,6 +1,4 @@ - - */ - protected $groupActions = []; - - /** - * @var DataGrid - */ - protected $datagrid; + /** @var array */ + protected array $groupActions = []; - - public function __construct(DataGrid $datagrid) + public function __construct(protected DataGrid $datagrid) { - $this->datagrid = $datagrid; } - public function addToFormContainer(Container $container): void { /** @var Form $form */ @@ -43,7 +32,7 @@ public function addToFormContainer(Container $container): void $main_options = []; if ($translator === null) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } /** @@ -155,7 +144,6 @@ public function addToFormContainer(Container $container): void }; } - /** * Pass "sub"-form submission forward to custom submit function */ @@ -176,9 +164,6 @@ public function submitted(NetteForm $form): void return; } - /** - * @todo Define items IDs - */ $httpIds = $form->getHttpData( Form::DATA_LINE | Form::DATA_KEYS, strtolower($this->datagrid->getFullName()) . '_group_action_item[]' @@ -191,12 +176,12 @@ public function submitted(NetteForm $form): void $this->groupActions[$id]->onSelect($ids, $values[$id] ?? null); if (!$form['group_action'] instanceof Container) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } if (isset($form['group_action']['group_action'])) { if (!$form['group_action']['group_action'] instanceof SelectBox) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } $form['group_action']['group_action']->setValue(null); @@ -205,89 +190,63 @@ public function submitted(NetteForm $form): void $groupButtonAction = $this->groupActions[$submitter->getName()]; if (!$groupButtonAction instanceof GroupButtonAction) { - throw new \UnexpectedValueException('This action is supposed to be a GroupButtonAction'); + throw new UnexpectedValueException('This action is supposed to be a GroupButtonAction'); } $groupButtonAction->onClick($ids); } } - /** * Add one group button action to collection of actions */ public function addGroupButtonAction(string $title, ?string $class = null): GroupButtonAction { - if (count($this->groupActions) > 0) { - $id = count($this->groupActions) + 1; - } else { - $id = 1; - } + $id = count($this->groupActions) > 0 ? count($this->groupActions) + 1 : 1; return $this->groupActions[$id] = new GroupButtonAction($title, $class); } - /** * Add one group action (select box) to collection of actions */ public function addGroupSelectAction(string $title, array $options): GroupAction { - if (count($this->groupActions) > 0) { - $id = count($this->groupActions) + 1; - } else { - $id = 1; - } + $id = count($this->groupActions) > 0 ? count($this->groupActions) + 1 : 1; return $this->groupActions[$id] = new GroupSelectAction($title, $options); } - /** * Add one group action (multiselect box) to collection of actions */ public function addGroupMultiSelectAction(string $title, array $options): GroupAction { - if (count($this->groupActions) > 0) { - $id = count($this->groupActions) + 1; - } else { - $id = 1; - } + $id = count($this->groupActions) > 0 ? count($this->groupActions) + 1 : 1; return $this->groupActions[$id] = new GroupMultiSelectAction($title, $options); } - /** * Add one group action (text input) to collection of actions */ public function addGroupTextAction(string $title): GroupAction { - if (count($this->groupActions) > 0) { - $id = count($this->groupActions) + 1; - } else { - $id = 1; - } + $id = count($this->groupActions) > 0 ? count($this->groupActions) + 1 : 1; return $this->groupActions[$id] = new GroupTextAction($title); } - /** * Add one group action (textarea) to collection of actions */ public function addGroupTextareaAction(string $title): GroupAction { - if (count($this->groupActions) > 0) { - $id = count($this->groupActions) + 1; - } else { - $id = 1; - } + $id = count($this->groupActions) > 0 ? count($this->groupActions) + 1 : 1; return $this->groupActions[$id] = new GroupTextareaAction($title); } - public function getGroupAction(string $title): GroupAction { foreach ($this->groupActions as $action) { @@ -296,21 +255,20 @@ public function getGroupAction(string $title): GroupAction } } - throw new DataGridGroupActionException("Group action $title does not exist."); + throw new DataGridGroupActionException(sprintf('Group action %s does not exist.', $title)); } - private function getFormSubmitter(NetteForm $form): ?SubmitButton { $container = $form['group_action']; if (!$container instanceof Container) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } if (isset($container['submit'])) { if (!$container['submit'] instanceof SubmitButton) { - throw new \UnexpectedValueException; + throw new UnexpectedValueException(); } if ($container['submit']->isSubmittedBy()) { @@ -326,4 +284,5 @@ private function getFormSubmitter(NetteForm $form): ?SubmitButton return null; } + } diff --git a/src/GroupAction/GroupButtonAction.php b/src/GroupAction/GroupButtonAction.php index ea9bd0e1c..2739a95b5 100644 --- a/src/GroupAction/GroupButtonAction.php +++ b/src/GroupAction/GroupButtonAction.php @@ -1,6 +1,4 @@ -class = $class; } } diff --git a/src/GroupAction/GroupMultiSelectAction.php b/src/GroupAction/GroupMultiSelectAction.php index 52102b9ce..596bc6aa2 100644 --- a/src/GroupAction/GroupMultiSelectAction.php +++ b/src/GroupAction/GroupMultiSelectAction.php @@ -1,6 +1,4 @@ -options = $options; } - public function getOptions(): array { return $this->options; } - /** * Has the action some options? */ @@ -34,4 +22,5 @@ public function hasOptions(): bool { return $this->options !== []; } + } diff --git a/src/GroupAction/GroupTextAction.php b/src/GroupAction/GroupTextAction.php index c09b50f80..eb63761ab 100644 --- a/src/GroupAction/GroupTextAction.php +++ b/src/GroupAction/GroupTextAction.php @@ -1,6 +1,4 @@ -shouldBeRendered; } - - + public function setShouldBeRendered(bool $shouldBeRendered): void { $this->shouldBeRendered = $shouldBeRendered; } + } diff --git a/src/InlineEdit/InlineEdit.php b/src/InlineEdit/InlineEdit.php index 087b5c7ee..741d6e867 100644 --- a/src/InlineEdit/InlineEdit.php +++ b/src/InlineEdit/InlineEdit.php @@ -1,12 +1,10 @@ -grid = $grid; - $this->primaryWhereColumn = $primaryWhereColumn; - $this->title = 'ublaboo_datagrid.edit'; $this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass); $this->icon = 'pencil pencil-alt'; @@ -100,34 +67,26 @@ public function __construct(DataGrid $grid, ?string $primaryWhereColumn = null) $this->onControlAfterAdd[] = [$this, 'addControlsClasses']; } - /** - * @param mixed $id * @return static */ - public function setItemId($id): self + public function setItemId(mixed $id): self { $this->itemID = $id; return $this; } - - /** - * @return mixed - */ - public function getItemId() + public function getItemId(): mixed { return $this->itemID; } - public function getPrimaryWhereColumn(): ?string { return $this->primaryWhereColumn; } - public function renderButton(Row $row): Html { $a = Html::el('a') @@ -144,7 +103,7 @@ public function renderButton(Row $row): Html ); } - if ($this->class !== null) { + if ($this->class !== '') { $a->appendAttribute('class', $this->class); } @@ -153,7 +112,6 @@ public function renderButton(Row $row): Html return $a; } - /** * Render row item detail button */ @@ -173,14 +131,13 @@ public function renderButtonAdd(): Html ); } - if ($this->class !== null) { + if ($this->class !== '') { $a->appendAttribute('class', $this->class); } return $a; } - /** * @return static */ @@ -191,19 +148,16 @@ public function setPositionTop(bool $positionTop = true): self return $this; } - public function isPositionTop(): bool { return $this->positionTop; } - public function isPositionBottom(): bool { return !$this->positionTop; } - public function addControlsClasses(Container $container): void { foreach ($container->getControls() as $key => $control) { @@ -213,11 +167,13 @@ public function addControlsClasses(Container $container): void $control->setAttribute('class', 'btn btn-xs btn-primary'); break; + case 'cancel': $control->setValidationScope([]); $control->setAttribute('class', 'btn btn-xs btn-danger'); break; + default: if ($control->getControl()->getAttribute('class') === null) { $control->setAttribute('class', 'form-control input-sm form-control-sm'); @@ -228,7 +184,6 @@ public function addControlsClasses(Container $container): void } } - /** * @return static */ @@ -239,9 +194,9 @@ public function setShowNonEditingColumns(bool $show = true): self return $this; } - public function showNonEditingColumns(): bool { return $this->showNonEditingColumns; } + } diff --git a/src/Localization/SimpleTranslator.php b/src/Localization/SimpleTranslator.php index 1ff11bafd..395bf2399 100644 --- a/src/Localization/SimpleTranslator.php +++ b/src/Localization/SimpleTranslator.php @@ -1,6 +1,4 @@ - 'No items found. You can reset the filter', 'ublaboo_datagrid.no_item_found' => 'No items found.', 'ublaboo_datagrid.here' => 'here', @@ -42,25 +37,19 @@ class SimpleTranslator implements ITranslator 'ublaboo_datagrid.per_page_submit' => 'Change', ]; - public function __construct(array $dictionary = []) { $this->dictionary = array_merge($this->dictionary, $dictionary); } - - /** - * @param mixed $message - * @param mixed ...$parameters - */ - public function translate($message, ...$parameters): string + public function translate(mixed $message, mixed ...$parameters): string { return $this->dictionary[$message] ?? $message; } - public function setDictionary(array $dictionary): void { $this->dictionary = $dictionary; } + } diff --git a/src/Row.php b/src/Row.php index b109e9314..060860e6d 100644 --- a/src/Row.php +++ b/src/Row.php @@ -1,6 +1,4 @@ -control = Html::el('tr'); - $this->datagrid = $datagrid; - $this->item = $item; - $this->primaryKey = $primaryKey; $this->id = $this->getValue($primaryKey); if ($datagrid->getColumnsSummary() instanceof ColumnsSummary) { @@ -59,11 +30,7 @@ public function __construct(DataGrid $datagrid, $item, string $primaryKey) } } - - /** - * @return mixed - */ - public function getId() + public function getId(): mixed { if (is_object($this->id) && method_exists($this->id, '__toString')) { return (string) $this->id; @@ -72,12 +39,7 @@ public function getId() return $this->id; } - - /** - * @param mixed $key - * @return mixed - */ - public function getValue($key) + public function getValue(mixed $key): mixed { if ($this->item instanceof Entity) { return $this->getLeanMapperEntityProperty($this->item, $key); @@ -112,13 +74,11 @@ public function getValue($key) return $this->getDoctrineEntityProperty($this->item, $key); } - public function getControl(): Html { return $this->control; } - public function getControlClass(): string { $class = $this->control->getAttribute('class'); @@ -130,11 +90,7 @@ public function getControlClass(): string return implode(' ', array_keys($class)); } - - /** - * @return mixed - */ - public function getActiveRowProperty(ActiveRow $item, string $key) + public function getActiveRowProperty(ActiveRow $item, string $key): mixed { if (preg_match('/^:([a-zA-Z0-9_$]+)\.([a-zA-Z0-9_$]+)(:([a-zA-Z0-9_$]+))?$/', $key, $matches) === 1) { $relatedTable = $matches[1]; @@ -143,7 +99,7 @@ public function getActiveRowProperty(ActiveRow $item, string $key) try { $relatedRow = $item->related($relatedTable, $throughColumn)->fetch(); - } catch (MemberAccessException $e) { + } catch (MemberAccessException) { return null; } @@ -159,7 +115,7 @@ public function getActiveRowProperty(ActiveRow $item, string $key) try { $referencedRow = $item->ref($referencedTable, $throughColumn); - } catch (MemberAccessException $e) { + } catch (MemberAccessException) { return null; } @@ -171,13 +127,10 @@ public function getActiveRowProperty(ActiveRow $item, string $key) return $item[$key]; } - /** * LeanMapper: Access object properties to get a item value - * - * @return mixed */ - public function getLeanMapperEntityProperty(Entity $item, string $key) + public function getLeanMapperEntityProperty(Entity $item, string $key): mixed { $properties = explode('.', $key); $value = $item; @@ -207,13 +160,10 @@ public function getLeanMapperEntityProperty(Entity $item, string $key) return $value; } - /** * Nextras: Access object properties to get a item value - * - * @return mixed */ - public function getNextrasEntityProperty(NextrasEntity $item, string $key) + public function getNextrasEntityProperty(NextrasEntity $item, string $key): mixed { $properties = explode('.', $key); $value = $item; @@ -237,15 +187,10 @@ public function getNextrasEntityProperty(NextrasEntity $item, string $key) return $value; } - /** * Doctrine: Access object properties to get a item value - * - * @param mixed $item - * @param mixed $key - * @return mixed */ - public function getDoctrineEntityProperty($item, $key) + public function getDoctrineEntityProperty(mixed $item, mixed $key): mixed { $properties = explode('.', $key); $value = $item; @@ -274,18 +219,14 @@ public function getDoctrineEntityProperty($item, $key) return $value; } - /** * Get original item - * - * @return mixed */ - public function getItem() + public function getItem(): mixed { return $this->item; } - /** * Has particular row group actions allowed? */ @@ -300,13 +241,10 @@ public function hasGroupAction(): bool return true; } - /** * Has particular row a action allowed? - * - * @param mixed $key */ - public function hasAction($key): bool + public function hasAction(mixed $key): bool { $condition = $this->datagrid->getRowCondition('action', $key); @@ -317,7 +255,6 @@ public function hasAction($key): bool return true; } - /** * Has particular row inlie edit allowed? */ @@ -332,7 +269,6 @@ public function hasInlineEdit(): bool return true; } - public function applyColumnCallback(string $key, Column $column): Column { $callback = $this->datagrid->getColumnCallback($key); @@ -344,7 +280,6 @@ public function applyColumnCallback(string $key, Column $column): Column return $column; } - /** * Key may contain ".", get rid of it (+ the table alias) */ @@ -358,4 +293,5 @@ private function formatDibiRowKey(string $key): string return $key; } + } diff --git a/src/Status/Option.php b/src/Status/Option.php index ee6d6f17c..56ec84826 100644 --- a/src/Status/Option.php +++ b/src/Status/Option.php @@ -1,6 +1,4 @@ -grid = $grid; - $this->columnStatus = $columnStatus; - $this->value = $value; - $this->text = $text; } - - /** - * @return mixed - */ - public function getValue() + public function getValue(): mixed { return $this->value; } - public function endOption(): ColumnStatus { return $this->columnStatus; } - /** * @return static */ @@ -107,13 +51,11 @@ public function setTitle(string $title): self return $this; } - public function getTitle(): ?string { return $this->title; } - /** * @return static */ @@ -128,13 +70,11 @@ public function setClass(string $class, ?string $classSecondary = null): self return $this; } - public function getClass(): ?string { return $this->class; } - /** * @return static */ @@ -145,13 +85,11 @@ public function setClassSecondary(string $classSecondary): self return $this; } - public function getClassSecondary(): string { return $this->classSecondary; } - /** * @return static */ @@ -162,13 +100,11 @@ public function setClassInDropdown(string $classInDropdown): self return $this; } - public function getClassInDropdown(): string { return $this->classInDropdown; } - /** * @return static */ @@ -179,13 +115,11 @@ public function setIcon(string $icon): self return $this; } - public function getIcon(): ?string { return $this->icon; } - /** * @return static */ @@ -196,19 +130,16 @@ public function setIconSecondary(string $iconSecondary): self return $this; } - public function getIconSecondary(): ?string { return $this->iconSecondary; } - public function getText(): string { return $this->text; } - /** * @return static */ @@ -219,7 +150,6 @@ public function setConfirmation(IConfirmation $confirmation): self return $this; } - public function getConfirmationDialog(Row $row): ?string { if ($this->confirmation === null) { @@ -246,4 +176,5 @@ public function getConfirmationDialog(Row $row): ?string throw new DataGridException('Unsupported confirmation'); } + } diff --git a/src/Toolbar/ToolbarButton.php b/src/Toolbar/ToolbarButton.php index 8e1db6106..60c8860c6 100644 --- a/src/Toolbar/ToolbarButton.php +++ b/src/Toolbar/ToolbarButton.php @@ -1,6 +1,4 @@ -grid = $grid; - $this->href = $href; $this->text = $text; - $this->params = $params; } - /** * Render toolbar button */ @@ -71,7 +45,7 @@ public function renderButton(): Html try { // Renderer function may be used return $this->useRenderer(); - } catch (DataGridColumnRendererException $e) { + } catch (DataGridColumnRendererException) { // Do not use renderer } @@ -103,12 +77,10 @@ public function renderButton(): Html return $a; } - /** - * @param array $attrs * @return static */ - public function addAttributes(array $attrs) + public function addAttributes(array $attrs): static { $this->attributes += $attrs; @@ -124,4 +96,5 @@ public function setConfirmDialog(string $confirmDialog): self return $this; } + } diff --git a/src/Traits/TButtonCaret.php b/src/Traits/TButtonCaret.php index 9d7d8309a..898c24f77 100644 --- a/src/Traits/TButtonCaret.php +++ b/src/Traits/TButtonCaret.php @@ -1,16 +1,11 @@ -caret; diff --git a/src/Traits/TButtonClass.php b/src/Traits/TButtonClass.php index 4762237e0..f8759ffbb 100644 --- a/src/Traits/TButtonClass.php +++ b/src/Traits/TButtonClass.php @@ -1,16 +1,11 @@ -class; diff --git a/src/Traits/TButtonIcon.php b/src/Traits/TButtonIcon.php index a32f33748..124dbad96 100644 --- a/src/Traits/TButtonIcon.php +++ b/src/Traits/TButtonIcon.php @@ -1,16 +1,11 @@ -icon; diff --git a/src/Traits/TButtonRenderer.php b/src/Traits/TButtonRenderer.php index 344b81f1d..a51520ae7 100644 --- a/src/Traits/TButtonRenderer.php +++ b/src/Traits/TButtonRenderer.php @@ -1,6 +1,4 @@ -getRenderer(); $args = $row instanceof Row ? [$row->getItem()] : []; if ($renderer === null) { - throw new DataGridColumnRendererException; + throw new DataGridColumnRendererException(); } if ($renderer->getConditionCallback() !== null) { if (call_user_func_array($renderer->getConditionCallback(), $args) === false) { - throw new DataGridColumnRendererException; + throw new DataGridColumnRendererException(); } return call_user_func_array($renderer->getCallback(), $args); @@ -47,7 +39,6 @@ public function useRenderer(?Row $row = null) return call_user_func_array($renderer->getCallback(), $args); } - /** * Set renderer callback and (it may be optional - the condition callback will decide) * @@ -68,7 +59,6 @@ public function setRenderer( return $this; } - /** * @return static */ @@ -80,19 +70,16 @@ public function setRendererOnCondition( return $this->setRenderer($renderer, $conditionCallback); } - public function getRenderer(): ?Renderer { return $this->renderer; } - public function hasReplacements(): bool { return $this->replacements !== []; } - public function applyReplacements(Row $row, string $column): array { $value = $row->getValue($column); diff --git a/src/Traits/TButtonText.php b/src/Traits/TButtonText.php index 8d9d5ed4d..01d5e4892 100644 --- a/src/Traits/TButtonText.php +++ b/src/Traits/TButtonText.php @@ -1,16 +1,11 @@ -text; diff --git a/src/Traits/TButtonTitle.php b/src/Traits/TButtonTitle.php index 1479c5681..032ed9be5 100644 --- a/src/Traits/TButtonTitle.php +++ b/src/Traits/TButtonTitle.php @@ -1,17 +1,11 @@ -title; } + } diff --git a/src/Traits/TButtonTryAddIcon.php b/src/Traits/TButtonTryAddIcon.php index a06e2db7e..654c08bad 100644 --- a/src/Traits/TButtonTryAddIcon.php +++ b/src/Traits/TButtonTryAddIcon.php @@ -1,6 +1,4 @@ -getPresenter(); - if (strpos($href, ':') !== false) { + if (str_contains($href, ':')) { return $presenter->link($href, $params); } @@ -45,15 +43,15 @@ protected function createLink( try { $link = $targetComponent->link($href, $params); - } catch (InvalidLinkException $e) { + } catch (InvalidLinkException) { $link = false; } if (is_string($link)) { if ( - strpos($link, '#error') === 0 || - (strrpos($href, '!') !== false && strpos($link, '#') === 0) || - (in_array($presenter->invalidLinkMode, [Presenter::INVALID_LINK_WARNING, Presenter::INVALID_LINK_SILENT], true) && strpos($link, '#') === 0) + str_starts_with($link, '#error') || + (strrpos($href, '!') !== false && str_starts_with($link, '#')) || + (in_array($presenter->invalidLinkMode, [Presenter::INVALID_LINK_WARNING, Presenter::INVALID_LINK_SILENT], true) && str_starts_with($link, '#')) ) { continue; // Did not find signal handler } @@ -68,7 +66,6 @@ protected function createLink( throw $this->createHierarchyLookupException($grid, $href, $params); } - private function createHierarchyLookupException( DataGrid $grid, string $href, @@ -84,13 +81,13 @@ private function createHierarchyLookupException( ); } - $desiredHandler = get_class($parent) . '::handle' . ucfirst($href) . '()'; + $desiredHandler = $parent::class . '::handle' . ucfirst($href) . '()'; return new DataGridLinkCreationException( 'DataGrid could not create link "' . $href . '" - did not find any signal handler in componenet hierarchy from ' - . get_class($parent) . ' up to the ' - . get_class($presenter) . '. ' + . $parent::class . ' up to the ' + . $presenter::class . '. ' . 'Try adding handler ' . $desiredHandler ); } diff --git a/src/Traits/TRenderCondition.php b/src/Traits/TRenderCondition.php index 7d0560bb9..71feeae0f 100644 --- a/src/Traits/TRenderCondition.php +++ b/src/Traits/TRenderCondition.php @@ -1,6 +1,4 @@ -renderConditionCallback; @@ -33,4 +28,5 @@ public function shouldBeRendered(Row $row): bool ? ($condition)($row->getItem()) : true; } + } diff --git a/src/Utils/ArraysHelper.php b/src/Utils/ArraysHelper.php index 8a4bb76d5..a3002461d 100644 --- a/src/Utils/ArraysHelper.php +++ b/src/Utils/ArraysHelper.php @@ -1,11 +1,7 @@ -getTimezone(); - $date = new \DateTime('now', $tz !== false ? $tz : null); + $date = new DateTime('now', $tz !== false ? $tz : null); $date->setTimestamp($value->getTimestamp()); return $date; } foreach ($formats as $format) { - $date = \DateTime::createFromFormat($format, (string) $value); + $date = DateTime::createFromFormat($format, (string) $value); if ($date === false) { continue; @@ -81,7 +76,7 @@ public static function fromString($value, array $formats = []): \DateTime $timestamp = strtotime((string) $value); if ($timestamp !== false) { - $date = new \DateTime; + $date = new DateTime(); $date->setTimestamp($timestamp); return $date; diff --git a/src/Utils/ItemDetailForm.php b/src/Utils/ItemDetailForm.php index f88eef584..72c1be0ea 100644 --- a/src/Utils/ItemDetailForm.php +++ b/src/Utils/ItemDetailForm.php @@ -1,40 +1,31 @@ - - */ - private $containerSetByName = []; + /** @var ?array */ + private ?array $httpPost; + /** @var array */ + private array $containerSetByName = []; public function __construct(callable $callableSetContainer) { $this->monitor( Presenter::class, - function(Presenter $presenter): void { + function (Presenter $presenter): void { $this->loadHttpData(); } ); @@ -42,20 +33,12 @@ function(Presenter $presenter): void { $this->callableSetContainer = $callableSetContainer; } - - /** - * @param mixed $name - */ - public function offsetGet($name): IComponent + public function offsetGet(mixed $name): IComponent { return $this->getComponentAndSetContainer($name); } - - /** - * @param mixed $name - */ - public function getComponentAndSetContainer($name): IComponent + public function getComponentAndSetContainer(mixed $name): IComponent { $container = $this->addContainer($name); @@ -68,19 +51,17 @@ public function getComponentAndSetContainer($name): IComponent return $container; } - /** - * @return mixed|null * @throws UnexpectedValueException */ - private function getHttpData() + private function getHttpData(): mixed { if ($this->httpPost === null) { - $lookupPath = $this->lookupPath('Nette\Forms\Form'); + $lookupPath = $this->lookupPath(Form::class); $form = $this->getForm(); if ($lookupPath === null || $form === null) { - throw new UnexpectedValueException; + throw new UnexpectedValueException(); } $path = explode(self::NAME_SEPARATOR, $lookupPath); @@ -91,7 +72,6 @@ private function getHttpData() return $this->httpPost; } - /** * @throws UnexpectedValueException */ @@ -100,7 +80,7 @@ private function loadHttpData(): void $form = $this->getForm(); if ($form === null) { - throw new UnexpectedValueException; + throw new UnexpectedValueException(); } if ($form->isSubmitted() === false) { @@ -108,9 +88,10 @@ private function loadHttpData(): void } foreach ((array) $this->getHttpData() as $name => $value) { - if ((is_array($value) || $value instanceof Traversable)) { + if ((is_iterable($value))) { $this->getComponentAndSetContainer($name); } } } + } diff --git a/src/Utils/NetteDatabaseSelectionHelper.php b/src/Utils/NetteDatabaseSelectionHelper.php index 5b9861054..9094283fe 100644 --- a/src/Utils/NetteDatabaseSelectionHelper.php +++ b/src/Utils/NetteDatabaseSelectionHelper.php @@ -1,6 +1,4 @@ -getSupplementalDriver(); } - - /** - * @return mixed - */ - public static function getContext(Selection $selection) + public static function getContext(Selection $selection): mixed { $reflection = new ReflectionClass($selection); diff --git a/src/Utils/PropertyAccessHelper.php b/src/Utils/PropertyAccessHelper.php index 08d7876e2..2ccccfb03 100644 --- a/src/Utils/PropertyAccessHelper.php +++ b/src/Utils/PropertyAccessHelper.php @@ -1,6 +1,4 @@ -getValue($class, $property); } diff --git a/src/Utils/Sorting.php b/src/Utils/Sorting.php index eef6e6d0b..47186850e 100644 --- a/src/Utils/Sorting.php +++ b/src/Utils/Sorting.php @@ -1,30 +1,21 @@ -sort = $sort; $this->sortCallback = $sortCallback; } - /** * @return array|string[] */ @@ -33,7 +24,6 @@ public function getSort(): array return $this->sort; } - public function getSortCallback(): ?callable { return $this->sortCallback; diff --git a/src/templates/datagrid.latte b/src/templates/datagrid.latte index c5eceeddd..917a92a1e 100644 --- a/src/templates/datagrid.latte +++ b/src/templates/datagrid.latte @@ -386,7 +386,7 @@ {if $control->getPerPage() === 'all'} {='ublaboo_datagrid.items'|translate}: {='ublaboo_datagrid.all'|translate} {else} - {='ublaboo_datagrid.items'|translate}: {$paginator->getOffset() > 0 ? $paginator->getOffset() + 1 : ($paginator->getItemCount() > 0 ? 1 : 0)} - {sizeof($rows) + $paginator->getOffset()} + {='ublaboo_datagrid.items'|translate}: {$paginator->getOffset() > 0 ? $paginator->getOffset() + 1 : ($paginator->getItemCount() > 0 ? 1 : 0)} - {count($rows) + $paginator->getOffset()} {='ublaboo_datagrid.from'|translate} {$paginator->getItemCount()} {/if}) diff --git a/tests/Cases/ColumnActionTest.phpt b/tests/Cases/ColumnActionTest.phpt index 7833e95bb..c99f89706 100644 --- a/tests/Cases/ColumnActionTest.phpt +++ b/tests/Cases/ColumnActionTest.phpt @@ -1,14 +1,14 @@ -grid = $factory->createTestingDataGrid(); } - - public function render($column) + public function render(Action $column): string { - $item = new Ublaboo\DataGrid\Row($this->grid, ['id' => 1, 'name' => 'John'], 'id'); + $item = new Row($this->grid, ['id' => 1, 'name' => 'John'], 'id'); return (string) $column->render($item); } - - public function testActionDuplcitColumn(): void + public function testActionDuplicityColumn(): void { $this->grid->addAction('action', 'Do', 'doStuff!'); @@ -48,7 +43,6 @@ final class ColumnActionTest extends TestCase Assert::exception($add_action, 'Ublaboo\DataGrid\Exception\DataGridException', 'There is already action at key [action] defined.'); } - public function testActionLink(): void { $action = $this->grid->addAction('action', 'Do', 'doStuff!'); @@ -81,7 +75,6 @@ final class ColumnActionTest extends TestCase ); } - public function testActionIcon(): void { $action = $this->grid->addAction('action', 'Do', 'doStuff!'); @@ -95,7 +88,6 @@ final class ColumnActionTest extends TestCase ); } - public function testActionClass(): void { $action = $this->grid->addAction('action', 'Do', 'doStuff!')->setClass('btn'); @@ -107,7 +99,6 @@ final class ColumnActionTest extends TestCase Assert::same('Do', $this->render($action)); } - public function testActionTitle(): void { $action = $this->grid->addAction('action', 'Do', 'doStuff!')->setTitle('hello'); @@ -118,7 +109,6 @@ final class ColumnActionTest extends TestCase ); } - public function testActionConfirm(): void { $action = $this->grid->addAction('action', 'Do', 'doStuff!') @@ -130,18 +120,13 @@ final class ColumnActionTest extends TestCase ); } - public function testActionRenderCondition(): void { - $action = $this->grid->addAction('action1', 'Do', 'doStuff!')->setRenderCondition(function () { - return true; - }); + $action = $this->grid->addAction('action1', 'Do', 'doStuff!')->setRenderCondition(fn () => true); Assert::same('Do', $this->render($action)); - $action = $this->grid->addAction('action2', 'Do', 'doStuff!')->setRenderCondition(function () { - return false; - }); + $action = $this->grid->addAction('action2', 'Do', 'doStuff!')->setRenderCondition(fn () => false); Assert::same('', $this->render($action)); } diff --git a/tests/Cases/ColumnDateTimeTest.phpt b/tests/Cases/ColumnDateTimeTest.phpt index 9f620fe51..ebedf89c6 100644 --- a/tests/Cases/ColumnDateTimeTest.phpt +++ b/tests/Cases/ColumnDateTimeTest.phpt @@ -1,13 +1,14 @@ -grid = $factory->createTestingDataGrid(); } - - public function render($column) + public function render(ColumnDateTime $column): string { $datetime = DateTime::createFromFormat('Y-m-d H:i:s', '2015-12-15 22:58:42'); - $item = new Ublaboo\DataGrid\Row($this->grid, ['id' => 1, 'name' => 'John', 'date' => $datetime], 'id'); + $item = new Row($this->grid, ['id' => 1, 'name' => 'John', 'date' => $datetime], 'id'); - return (string) $column->render($item); + return $column->render($item); } - public function testFormat(): void { /** diff --git a/tests/Cases/ColumnLinkTest.phpt b/tests/Cases/ColumnLinkTest.phpt index f787f63a7..3100d60a1 100644 --- a/tests/Cases/ColumnLinkTest.phpt +++ b/tests/Cases/ColumnLinkTest.phpt @@ -1,12 +1,13 @@ -grid = $factory->createTestingDataGrid(); } - - public function render($column) + public function render(ColumnLink $column): string { - $item = new Ublaboo\DataGrid\Row($this->grid, ['id' => 1, 'name' => 'John'], 'id'); + $item = new Row($this->grid, ['id' => 1, 'name' => 'John'], 'id'); return (string) $column->render($item); } - public function testLink(): void { $link = $this->grid->addColumnLink('name', 'Href'); @@ -58,7 +54,6 @@ final class ColumnLinkTest extends TestCase Assert::same('1', $this->render($link)); } - public function testLinkClass(): void { $link = $this->grid->addColumnLink('name', 'Href')->setClass('btn'); @@ -68,7 +63,6 @@ final class ColumnLinkTest extends TestCase Assert::same('John', $this->render($link)); } - public function testLinkTitle(): void { $link = $this->grid->addColumnLink('name', 'Href')->setTitle('Hello'); diff --git a/tests/Cases/ColumnNumberTest.phpt b/tests/Cases/ColumnNumberTest.phpt index 176c3bd7b..7be8b7c28 100644 --- a/tests/Cases/ColumnNumberTest.phpt +++ b/tests/Cases/ColumnNumberTest.phpt @@ -1,12 +1,13 @@ -grid = $factory->createTestingDataGrid(); } - - public function render($column) + public function render(ColumnNumber $column): string { - $item = new Ublaboo\DataGrid\Row($this->grid, ['id' => 1, 'name' => 'John', 'amount' => 345678.567], 'id'); + $item = new Row($this->grid, ['id' => 1, 'name' => 'John', 'amount' => 345678.567], 'id'); - return (string) $column->render($item); + return $column->render($item); } - public function testFormat(): void { $number = $this->grid->addColumnNumber('amount', 'Amount'); @@ -45,4 +41,4 @@ final class ColumnNumberTest extends TestCase } -(new ColumnNumberTest)->run(); +(new ColumnNumberTest())->run(); diff --git a/tests/Cases/ColumnStatusTest.phpt b/tests/Cases/ColumnStatusTest.phpt index 430366fa1..3e0e0cd2d 100644 --- a/tests/Cases/ColumnStatusTest.phpt +++ b/tests/Cases/ColumnStatusTest.phpt @@ -1,6 +1,4 @@ -grid = $factory->createTestingDataGrid(); } - public function testStatus(): void { $grid = $this->grid; @@ -60,7 +54,6 @@ final class ColumnStatusTest extends TestCase Assert::same(2, $current_option->getValue()); } - public function testRemoveColumn(): void { $grid = $this->grid; diff --git a/tests/Cases/ColumnTranslatableTest.phpt b/tests/Cases/ColumnTranslatableTest.phpt index df3f28055..92cf70bc5 100644 --- a/tests/Cases/ColumnTranslatableTest.phpt +++ b/tests/Cases/ColumnTranslatableTest.phpt @@ -1,12 +1,11 @@ -grid = $factory->createTestingDataGrid(); } - public function testTranslatable(): void { $grid = $this->grid; diff --git a/tests/Cases/CreateLinkTest.phpt b/tests/Cases/CreateLinkTest.phpt index d60e08eb7..67fb032d9 100644 --- a/tests/Cases/CreateLinkTest.phpt +++ b/tests/Cases/CreateLinkTest.phpt @@ -1,6 +1,4 @@ -grid = $factory->createTestingDataGrid()->getComponent('grid'); } - public function testActionLink(): void { $this->grid->getPresenter()->invalidLinkMode = Presenter::INVALID_LINK_EXCEPTION; @@ -49,7 +43,7 @@ final class CreateLinkTest extends TestCase Assert::same('/index.php?id=1&action=edit&presenter=Test', $link); } - } +} (new CreateLinkTest())->run(); diff --git a/tests/Cases/DataGridTest.phpt b/tests/Cases/DataGridTest.phpt index 1d4e7f15d..8ac35784b 100644 --- a/tests/Cases/DataGridTest.phpt +++ b/tests/Cases/DataGridTest.phpt @@ -1,6 +1,4 @@ -createTestingDataGrid()->getComponent('grid'); $grid->setRememberState(true); - Assert::exception(function() use ($grid): void { + Assert::exception(function () use ($grid): void { $grid->handleResetFilter(); }, AbortException::class); } @@ -34,11 +32,11 @@ final class DataGridTest extends TestCase $grid = $factory->createTestingDataGrid()->getComponent('grid'); $grid->setRememberState(false); - Assert::exception(function() use ($grid): void { + Assert::exception(function () use ($grid): void { $grid->handleResetFilter(); }, AbortException::class); } } -(new DataGridTest)->run(); +(new DataGridTest())->run(); diff --git a/tests/Cases/DataSources/ArrayDataSourceTest.phpt b/tests/Cases/DataSources/ArrayDataSourceTest.phpt index 4c7842e29..d5153928e 100644 --- a/tests/Cases/DataSources/ArrayDataSourceTest.phpt +++ b/tests/Cases/DataSources/ArrayDataSourceTest.phpt @@ -1,6 +1,4 @@ -ds = new ArrayDataSource($this->data); - $factory = new TestingDataGridFactory; + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } + } (new ArrayDataSourceTest())->run(); diff --git a/tests/Cases/DataSources/BaseDataSourceTest.phpt b/tests/Cases/DataSources/BaseDataSourceTest.phpt index d3adbe79c..ba5fcb655 100644 --- a/tests/Cases/DataSources/BaseDataSourceTest.phpt +++ b/tests/Cases/DataSources/BaseDataSourceTest.phpt @@ -1,12 +1,13 @@ - 1, 'name' => 'John Doe', 'age' => 30, 'address' => 'Blue Village 1'], ['id' => 2, 'name' => 'Frank Frank', 'age' => 60, 'address' => 'Yellow Garded 126'], ['id' => 3, 'name' => 'Santa Claus', 'age' => 12, 'address' => 'New York'], @@ -25,15 +26,9 @@ abstract class BaseDataSourceTest extends TestCase ['id' => 40, 'name' => 'John Red', 'age' => 40, 'address' => 'Porto 53'], ]; - /** - * @var Ublaboo\DataGrid\DataSource\IDataSource - */ - protected $ds; + protected IDataSource $ds; - /** - * @var Ublaboo\DataGrid\DataGrid - */ - protected $grid; + protected DataGrid $grid; public function testGetCount(): void { @@ -54,7 +49,6 @@ abstract class BaseDataSourceTest extends TestCase Assert::equal($this->data, $this->getActualResultAsArray()); } - public function testFilterSingleColumn(): void { $filter = new FilterText($this->grid, 'a', 'b', ['name']); @@ -96,7 +90,7 @@ abstract class BaseDataSourceTest extends TestCase public function testFilterRangeMin(): void { - $filter = new Ublaboo\DataGrid\Filter\FilterRange($this->grid, 'a', 'b', 'age', '-'); + $filter = new FilterRange($this->grid, 'a', 'b', 'age', '-'); $filter->setValue(['from' => 40]); $this->ds->filter([$filter]); @@ -109,7 +103,7 @@ abstract class BaseDataSourceTest extends TestCase public function testFilterRangeMax(): void { - $filter = new Ublaboo\DataGrid\Filter\FilterRange($this->grid, 'a', 'b', 'age', '-'); + $filter = new FilterRange($this->grid, 'a', 'b', 'age', '-'); $filter->setValue(['to' => 30]); $this->ds->filter([$filter]); @@ -122,7 +116,7 @@ abstract class BaseDataSourceTest extends TestCase public function testFilterRangeMinMax(): void { - $filter = new Ublaboo\DataGrid\Filter\FilterRange($this->grid, 'a', 'b', 'age', '-'); + $filter = new FilterRange($this->grid, 'a', 'b', 'age', '-'); $filter->setValue(['from' => 12, 'to' => 30]); $this->ds->filter([$filter]); @@ -171,7 +165,6 @@ abstract class BaseDataSourceTest extends TestCase ], $result); } - public function testSort(): void { $this->ds->sort(new Sorting(['name' => 'DESC'])); @@ -190,7 +183,7 @@ abstract class BaseDataSourceTest extends TestCase public function testFilterSelect(): void { - $filter = new Ublaboo\DataGrid\Filter\FilterSelect($this->grid, 'a', 'b', ['John Red' => 'John Red'], 'name'); + $filter = new FilterSelect($this->grid, 'a', 'b', ['John Red' => 'John Red'], 'name'); $filter->setValue('John Red'); $this->ds->filter([$filter]); @@ -198,8 +191,7 @@ abstract class BaseDataSourceTest extends TestCase Assert::equal([$this->data[5]], $this->getActualResultAsArray()); } - - protected function getActualResultAsArray() + protected function getActualResultAsArray(): array { return array_values( json_decode( diff --git a/tests/Cases/DataSources/DibiFluentDataSourceTest.phpt b/tests/Cases/DataSources/DibiFluentDataSourceTest.phpt index ada3af2b2..2b3c0422b 100644 --- a/tests/Cases/DataSources/DibiFluentDataSourceTest.phpt +++ b/tests/Cases/DataSources/DibiFluentDataSourceTest.phpt @@ -1,12 +1,11 @@ -setUpDatabase(); - $this->ds = new Ublaboo\DataGrid\DataSource\DibiFluentDataSource($this->db->select('*')->from('users'), 'id'); - $factory = new Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory(); + $this->ds = new DibiFluentDataSource($this->db->select('*')->from('users'), 'id'); + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } diff --git a/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php b/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php index 367ac3d95..13feb489d 100644 --- a/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php +++ b/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php @@ -1,6 +1,4 @@ -ds = new DoctrineCollectionDataSource(new ArrayCollection($this->data), 'id'); - $factory = new TestingDataGridFactory; + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } - public function testFilterMultipleColumns(): void { $filter = new FilterText($this->grid, 'a', 'b', ['name', 'address']); @@ -34,6 +31,7 @@ public function testFilterMultipleColumns(): void $this->data[4], ], $this->getActualResultAsArray()); } + } -(new DoctrineCollectionDataSourceTest)->run(); +(new DoctrineCollectionDataSourceTest())->run(); diff --git a/tests/Cases/DataSources/DoctrineDataSourceTest.phpt b/tests/Cases/DataSources/DoctrineDataSourceTest.phpt index 9ae7151f0..5f310cb64 100644 --- a/tests/Cases/DataSources/DoctrineDataSourceTest.phpt +++ b/tests/Cases/DataSources/DoctrineDataSourceTest.phpt @@ -1,6 +1,4 @@ - SortableNullsWalker::NULLS_LAST, ]); - $factory = new Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory(); + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } @@ -72,59 +67,51 @@ final class DoctrineDataSourceTest extends BaseDataSourceTest class User { - /** - * @Id @Column(type="integer") @GeneratedValue - **/ - public $id; + /** @Id @Column(type="integer") @GeneratedValue **/ + public int $id; - /** - * @Column(type="string") - **/ - public $name; + /** @Column(type="string") **/ + public string $name; - /** - * @Column(type="integer") - **/ - public $age; + /** @Column(type="integer") **/ + public int $age; - /** - * @Column(type="string") - **/ - public $address; + /** @Column(type="string") **/ + public string $address; - public function getId() + public function getId(): int { return $this->id; } - public function getName() + public function getName(): string { return $this->name; } - public function setName($name): void + public function setName(string $name): void { $this->name = $name; } - public function getAge() + public function getAge(): int { - return $this->name; + return $this->age; } - public function setAge($name): void + public function setAge(int $age): void { - $this->name = $name; + $this->age = $age; } - public function getAddress() + public function getAddress(): string { - return $this->name; + return $this->address; } - public function setAddress($name): void + public function setAddress(string $address): void { - $this->name = $name; + $this->address = $address; } } @@ -138,7 +125,6 @@ class SortableNullsWalker extends SqlWalker public const NULLS_FIRST = 'NULLS FIRST'; public const NULLS_LAST = 'NULLS LAST'; - /** * {@inheritDoc} */ @@ -157,17 +143,18 @@ class SortableNullsWalker extends SqlWalker return $sql; } - $index = $expr->identificationVariable.'.'.$expr->field; + $index = $expr->identificationVariable . '.' . $expr->field; if (!isset($hint[$index])) { return $sql; } - $search = $this->walkPathExpression($expr).' '.$type; - $sql = str_replace($search, $search.' '.$hint[$index], $sql); + $search = $this->walkPathExpression($expr) . ' ' . $type; + $sql = str_replace($search, $search . ' ' . $hint[$index], $sql); return $sql; } + } $test_case = new DoctrineDataSourceTest(); diff --git a/tests/Cases/DataSources/NetteDatabaseTableDataSourceTest.phpt b/tests/Cases/DataSources/NetteDatabaseTableDataSourceTest.phpt index 6445898d2..56f212e7b 100644 --- a/tests/Cases/DataSources/NetteDatabaseTableDataSourceTest.phpt +++ b/tests/Cases/DataSources/NetteDatabaseTableDataSourceTest.phpt @@ -1,33 +1,29 @@ -setUpDatabase(); - $this->ds = new Ublaboo\DataGrid\DataSource\NetteDatabaseTableDataSource($this->db->table('users'), 'id'); + $this->ds = new NetteDatabaseTableDataSource($this->db->table('users'), 'id'); - $factory = new Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory(); + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } @@ -37,13 +33,13 @@ final class NetteDatabaseTableDataSourceTest extends BaseDataSourceTest $storage = new DevNullStorage(); $structure = new Structure($connection, $storage); $conventions = new DiscoveredConventions($structure); - $this->db = new Context($connection, $structure, $conventions, $storage); + $this->db = new Explorer($connection, $structure, $conventions, $storage); $this->db->query('CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR (50), age INTEGER (3), - address VARCHAR (50) + address VARCHAR (50) ); '); @@ -52,7 +48,7 @@ final class NetteDatabaseTableDataSourceTest extends BaseDataSourceTest } } - protected function getActualResultAsArray() + protected function getActualResultAsArray(): array { /** @var Selection $data */ $data = $this->ds->getData(); diff --git a/tests/Cases/DataSources/NextrasDataSourceTest.phpt b/tests/Cases/DataSources/NextrasDataSourceTest.phpt index fd143fbdd..1db5934d6 100644 --- a/tests/Cases/DataSources/NextrasDataSourceTest.phpt +++ b/tests/Cases/DataSources/NextrasDataSourceTest.phpt @@ -1,6 +1,4 @@ -model = $simpleModelFactory->create(); $connection->query('INSERT INTO [users] %values[]', $this->data); - $connection->query('INSERT INTO [books] %values[]', Arrays::map($this->data, function (array $data): array { - return ['id' => $data['id'], 'author_id' => $data['id']]; - })); + $connection->query('INSERT INTO [books] %values[]', Arrays::map($this->data, fn (array $data): array => ['id' => $data['id'], 'author_id' => $data['id']])); } - protected function getActualResultAsArray() + protected function getActualResultAsArray(): array { $result = []; diff --git a/tests/Cases/DataSources/SearchParamsBuilderTest.phpt b/tests/Cases/DataSources/SearchParamsBuilderTest.phpt index 3415716e3..4f6353e0a 100644 --- a/tests/Cases/DataSources/SearchParamsBuilderTest.phpt +++ b/tests/Cases/DataSources/SearchParamsBuilderTest.phpt @@ -1,6 +1,4 @@ -searchParamsBuilder = new SearchParamsBuilder('users', 'user'); } - public function testEmptyQuery(): void { Assert::same( @@ -35,7 +28,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testSort(): void { $this->searchParamsBuilder->setSort(['name' => ['order' => 'desc']]); @@ -51,7 +43,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testPagination(): void { $this->searchParamsBuilder->setFrom(0); @@ -69,7 +60,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testPhrasePrefixQuery(): void { $this->searchParamsBuilder->addPhrasePrefixQuery('name', 'john'); @@ -97,7 +87,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testMatchQuery(): void { $this->searchParamsBuilder->addMatchQuery('name', 'john'); @@ -125,7 +114,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testBooleanMatchQuery(): void { $this->searchParamsBuilder->addBooleanMatchQuery('status', ['active', 'disabled']); @@ -134,24 +122,24 @@ final class SearchParamsBuilderTest extends TestCase [ 'index' => 'users', 'body' => [ - "query" => [ - "bool" => [ - "must" => [ + 'query' => [ + 'bool' => [ + 'must' => [ [ - "bool" => [ - "should" => [ + 'bool' => [ + 'should' => [ [ [ - "match" => [ - "status" => [ - "query" => "active", + 'match' => [ + 'status' => [ + 'query' => 'active', ], ], ], [ - "match" => [ - "status" => [ - "query" => "disabled", + 'match' => [ + 'status' => [ + 'query' => 'disabled', ], ], ], @@ -168,7 +156,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testRangeQuery(): void { $this->searchParamsBuilder->addRangeQuery('score', 8, 64); @@ -177,8 +164,8 @@ final class SearchParamsBuilderTest extends TestCase [ 'index' => 'users', 'body' => [ - "query" => [ - "bool" => [ + 'query' => [ + 'bool' => [ 'must' => [ [ 'range' => [ @@ -197,7 +184,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testIdsQuery(): void { $this->searchParamsBuilder->addIdsQuery([0, 1, 1, 2, 3, 5, 8]); @@ -206,13 +192,19 @@ final class SearchParamsBuilderTest extends TestCase [ 'index' => 'users', 'body' => [ - "query" => [ - "bool" => [ + 'query' => [ + 'bool' => [ 'must' => [ [ 'ids' => [ 'values' => [ - 0, 1, 1, 2, 3, 5, 8, + 0, + 1, + 1, + 2, + 3, + 5, + 8, ], ], ], @@ -225,7 +217,6 @@ final class SearchParamsBuilderTest extends TestCase ); } - public function testAllTogether(): void { $this->searchParamsBuilder->setSort(['name' => ['order' => 'desc']]); @@ -287,8 +278,9 @@ final class SearchParamsBuilderTest extends TestCase $this->searchParamsBuilder->buildParams() ); } + } -$test_case = new SearchParamsBuilderTest; +$test_case = new SearchParamsBuilderTest(); $test_case->run(); diff --git a/tests/Cases/ExportLinkTest.phpt b/tests/Cases/ExportLinkTest.phpt index 584f901a8..cc641e376 100644 --- a/tests/Cases/ExportLinkTest.phpt +++ b/tests/Cases/ExportLinkTest.phpt @@ -1,6 +1,4 @@ -createTestingDataGrid('ExportTesting'); $grid->setDataSource([]); - Assert::exception(function() use ($grid): void { + Assert::exception(function () use ($grid): void { $grid->handleExport(1); }, AbortException::class); } } -(new ExportLinkTest)->run(); +(new ExportLinkTest())->run(); diff --git a/tests/Cases/ExportTest.phpt b/tests/Cases/ExportTest.phpt index 1b0a0a9b8..3be872fbb 100644 --- a/tests/Cases/ExportTest.phpt +++ b/tests/Cases/ExportTest.phpt @@ -1,13 +1,12 @@ - 1, 'name' => 'John Doe', @@ -48,11 +41,10 @@ final class ExportTest extends TestCase public function setUp(): void { - $factory = new Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory(); + $factory = new TestingDataGridFactory(); $this->grid = $factory->createTestingDataGrid(); } - public function testExportNotFiltered(): void { $data = $this->data; @@ -62,7 +54,6 @@ final class ExportTest extends TestCase $this->grid->addExportCallback('Export', $callback); - $this->grid; $trigger = function (): void { $this->grid->handleExport(1); }; @@ -74,8 +65,6 @@ final class ExportTest extends TestCase $this->grid->handleExport(1); } - - public function testExportFiltered(): void { $data = $this->data; diff --git a/tests/Cases/FilterTest.phpt b/tests/Cases/FilterTest.phpt index 2734f997a..9f682ee5e 100644 --- a/tests/Cases/FilterTest.phpt +++ b/tests/Cases/FilterTest.phpt @@ -1,6 +1,4 @@ -createTestingDataGrid()->getComponent('grid'); $filterForm = $grid->createComponentFilter(); - Assert::exception(function() use ($grid, $filterForm): void { + Assert::exception(function () use ($grid, $filterForm): void { $grid->filterSucceeded($filterForm); }, AbortException::class); } } -(new FilterTest)->run(); +(new FilterTest())->run(); diff --git a/tests/Cases/ItemsPerPageTest.phpt b/tests/Cases/ItemsPerPageTest.phpt index d3f6bfc56..9d6ab93ce 100644 --- a/tests/Cases/ItemsPerPageTest.phpt +++ b/tests/Cases/ItemsPerPageTest.phpt @@ -1,46 +1,43 @@ -grid = $factory->createTestingDataGrid(); } - public function testGetPerPage(): void { $this->grid->setItemsPerPageList([10, 20, 50], false); $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + Assert::same(20, $this->grid->getPerPage()); $this->grid->perPage = 'all'; - Tester\Assert::same(10, $this->grid->getPerPage()); + Assert::same(10, $this->grid->getPerPage()); } public function testGetPerPageAll(): void @@ -48,15 +45,15 @@ class ItemsPerPageTest extends Tester\TestCase $this->grid->setItemsPerPageList([10, 20, 50], true); $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + Assert::same(20, $this->grid->getPerPage()); $this->grid->perPage = 'all'; - Tester\Assert::same('all', $this->grid->getPerPage()); + Assert::same('all', $this->grid->getPerPage()); } public function testGetPerPageAllTranslated(): void { - $translator = new Ublaboo\DataGrid\Localization\SimpleTranslator([ + $translator = new SimpleTranslator([ 'ublaboo_datagrid.all' => 'všechny', ]); $this->grid->setTranslator($translator); @@ -64,11 +61,12 @@ class ItemsPerPageTest extends Tester\TestCase $this->grid->setItemsPerPageList([10, 20, 50], true); $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + Assert::same(20, $this->grid->getPerPage()); $this->grid->perPage = 'all'; - Tester\Assert::same('all', $this->grid->getPerPage()); + Assert::same('all', $this->grid->getPerPage()); } + } $test = new ItemsPerPageTest(); diff --git a/tests/Cases/OnColumnAddCallbackTest.phpt b/tests/Cases/OnColumnAddCallbackTest.phpt index 0a32ee8f0..51809baf9 100644 --- a/tests/Cases/OnColumnAddCallbackTest.phpt +++ b/tests/Cases/OnColumnAddCallbackTest.phpt @@ -1,6 +1,4 @@ -grid = $factory->createTestingDataGrid(); } - public function testSetSortable(): void { - $this->grid->onColumnAdd[] = function ($key, Ublaboo\DataGrid\Column\Column $column): void { + $this->grid->onColumnAdd[] = function ($key, Column $column): void { $column->setSortable(); }; @@ -45,11 +42,11 @@ class OnColumnAddCallbackTest extends Tester\TestCase $columnTextNotSortable = $this->grid->addColumnText('textNotSortable', 'textName') ->setSortable(false); - Tester\Assert::true($columnText->isSortable()); - Tester\Assert::true($columnNumber->isSortable()); - Tester\Assert::true($columnDateTime->isSortable()); + Assert::true($columnText->isSortable()); + Assert::true($columnNumber->isSortable()); + Assert::true($columnDateTime->isSortable()); - Tester\Assert::false($columnTextNotSortable->isSortable()); + Assert::false($columnTextNotSortable->isSortable()); } } diff --git a/tests/Cases/RowTest.phpt b/tests/Cases/RowTest.phpt index 9b797a08b..2772c952f 100644 --- a/tests/Cases/RowTest.phpt +++ b/tests/Cases/RowTest.phpt @@ -1,6 +1,4 @@ -grid = $factory->createTestingDataGrid(); } - public function testControl(): void { $item = ['id' => 20, 'name' => 'John Doe']; @@ -44,7 +39,6 @@ final class RowTest extends TestCase Assert::same('bg-warning', $row->getControlClass()); } - public function testArray(): void { $item = ['id' => 20, 'name' => 'John Doe']; @@ -55,7 +49,6 @@ final class RowTest extends TestCase Assert::same('John Doe', $row->getValue('name')); } - public function testObject(): void { $item = (object) ['id' => 20, 'name' => 'John Doe']; @@ -65,7 +58,6 @@ final class RowTest extends TestCase Assert::same(20, $row->getId()); } - public function testDoctrineEntity(): void { $entity = new TestingDDataGridEntity(['id' => 20, 'name' => 'John Doe', 'age' => 23]); @@ -83,7 +75,7 @@ final class RowTest extends TestCase public function testLeanMapperEntity(): void { - $entity = new Utils\LeanBookEntity(); + $entity = new LeanBookEntity(); $entity->id = '978-80-257-1309-9'; $entity->pageCount = 42; diff --git a/tests/Cases/Utils/LeanBookEntity.php b/tests/Cases/Utils/LeanBookEntity.php index 14c0c8b66..079d36f67 100644 --- a/tests/Cases/Utils/LeanBookEntity.php +++ b/tests/Cases/Utils/LeanBookEntity.php @@ -1,6 +1,4 @@ -id; + } - public function __construct($args) + public function __construct(array $args) { $this->id = $args['id']; $this->age = $args['age']; $this->name = $args['name']; } - public function getName(): string { return $this->name; } - - final public function getId(): int - { - return $this->id; - } - - public function getAge(): int { return $this->age; } - public function setPartner(TestingDDataGridEntity $partner): void { $this->partner = $partner; } - public function getPartner(): ?TestingDDataGridEntity { return $this->partner; diff --git a/tests/Files/ExportTestingPresenter.php b/tests/Files/ExportTestingPresenter.php index 0c1f8f9f3..616693442 100644 --- a/tests/Files/ExportTestingPresenter.php +++ b/tests/Files/ExportTestingPresenter.php @@ -1,6 +1,4 @@ -andReturn(__DIR__ . '/template.latte') ->getMock(); } + } diff --git a/tests/Files/TestingDataGridFactory.php b/tests/Files/TestingDataGridFactory.php index e1c0bafdb..56e2edd02 100644 --- a/tests/Files/TestingDataGridFactory.php +++ b/tests/Files/TestingDataGridFactory.php @@ -1,20 +1,18 @@ -setMapping(['*' => 'Ublaboo\DataGrid\Tests\Files\*Presenter']); @@ -23,11 +21,12 @@ public function createTestingDataGrid(string $presenterName = 'Testing'): ?IComp $url = new UrlScript('http://localhost'); $request = new Request($url); - $response = new Response; + $response = new Response(); $session = new Session($request, $response); $presenter->injectPrimary(null, null, null, $request, $response, $session); return $presenter->getComponent('grid'); } + } diff --git a/tests/Files/TestingDataGridFactoryRouter.php b/tests/Files/TestingDataGridFactoryRouter.php index 2bdb8d6c9..0b41c59d2 100644 --- a/tests/Files/TestingDataGridFactoryRouter.php +++ b/tests/Files/TestingDataGridFactoryRouter.php @@ -1,6 +1,4 @@ -autoCanonicalize = false; - $presenter->injectPrimary(null, $presenterFactory, new SimpleRouter, $request, $response, $session); + $presenter->injectPrimary(null, $presenterFactory, new SimpleRouter(), $request, $response, $session); $presenter->run(new Request('Test', 'GET', [])); return $presenter->getComponent('grid'); } + } diff --git a/tests/Files/TestingPresenter.php b/tests/Files/TestingPresenter.php index 1e04925a5..53f574f37 100644 --- a/tests/Files/TestingPresenter.php +++ b/tests/Files/TestingPresenter.php @@ -1,6 +1,4 @@ -actionHandeled = true; } - /** * {@inheritDoc} */ @@ -29,19 +23,9 @@ public function link(string $destination, $args = []): string return $destination . '?' . http_build_query($args); } - - /*protected function createRequest( - Component $component, - string $destination, - array $args, - string $mode - ): ?string - { - return ucfirst($component->getName()) . $this->link($destination, $args); - }*/ - protected function createComponentGrid(string $name): DataGrid { return new DataGrid($this, $name); } + } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9ff84e048..fc7f27664 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,8 +1,8 @@ -