From 15066ae61c701e13cf855f93b56a9bbe974025c2 Mon Sep 17 00:00:00 2001 From: Martin Brettschneider Date: Mon, 15 Feb 2021 12:06:22 +0100 Subject: [PATCH] Make PHPstan green --- composer.json | 5 +- phpstan.neon | 117 +----------------- .../DataGridPaginator/DataGridPaginator.php | 2 +- src/DataGrid.php | 29 +---- src/Export/ExportCsv.php | 21 ++-- src/Traits/TLink.php | 10 +- 6 files changed, 23 insertions(+), 161 deletions(-) diff --git a/composer.json b/composer.json index ee48a5f4..b8f989d7 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "require-dev": { "dibi/dibi": "^3.0.0 || ^4.0.0", "doctrine/orm": "^2.6.12", + "elasticsearch/elasticsearch": "^7.1", "gamee/php-code-checker-rules": "^2.0.21", "mockery/mockery": "^1.3.3", "nette/database": "^3.0.2", @@ -42,9 +43,9 @@ "nextras/dbal": "^3.0.1 || ^4.0", "nextras/orm": "^3.1.0 || ^4.0", "ninjify/coding-standard": "^0.12.0", + "phpstan/phpstan-nette": "^0.12.14", "tharos/leanmapper": "^3.4.2 || ^4.0.0", - "tracy/tracy": "^2.6.3", - "elasticsearch/elasticsearch": "^7.1" + "tracy/tracy": "^2.6.3" }, "prefer-stable": true, "minimum-stability": "dev", diff --git a/phpstan.neon b/phpstan.neon index b010dbd2..dd4f4e1a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,123 +1,18 @@ includes: - ./vendor/gamee/php-code-checker-rules/phpstan.neon + - ./vendor/phpstan/phpstan-nette/extension.neon + - ./vendor/phpstan/phpstan-nette/rules.neon parameters: ignoreErrors: - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$steps\\.$#" - count: 1 - path: src/Components/DataGridPaginator/DataGridPaginator.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$paginator\\.$#" - count: 1 - path: src/Components/DataGridPaginator/DataGridPaginator.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$iconPrefix\\.$#" - count: 1 - path: src/Components/DataGridPaginator/DataGridPaginator.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$originalTemplate\\.$#" - count: 1 - path: src/Components/DataGridPaginator/DataGridPaginator.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$rows\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$columns\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$actions\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$exports\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$filters\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$toolbarButtons\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$aggregationFunctions\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$multipleAggregationFunction\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$filter_active\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$originalTemplate\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$iconPrefix\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$itemsDetail\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$columnsVisibility\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$columnsSummary\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$inlineEdit\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$inlineAdd\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$hasGroupActions\\.$#" - count: 1 - path: src/DataGrid.php - - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$hasGroupActionOnRows\\.$#" - count: 1 + message: "#^Cannot call method filterData\\(\\) on Ublaboo\\\\DataGrid\\\\DataModel|null\\.$#" + count: 2 path: src/DataGrid.php - - - message: "#^Access to an undefined property Nette\\\\Bridges\\\\ApplicationLatte\\\\Template\\:\\:\\$filter\\.$#" - count: 1 + message: "#^Call to an undefined method Nette\\\\Bridges\\\\ApplicationLatte\\\\Template::add\\(\\)\\.$#" + count: 2 path: src/DataGrid.php - - message: "#^Instanceof between Ublaboo\\\\DataGrid\\\\Filter\\\\Filter and Ublaboo\\\\DataGrid\\\\Filter\\\\FilterDateRange will always evaluate to false\\.$#" count: 1 diff --git a/src/Components/DataGridPaginator/DataGridPaginator.php b/src/Components/DataGridPaginator/DataGridPaginator.php index 3084a697..739d0cf1 100644 --- a/src/Components/DataGridPaginator/DataGridPaginator.php +++ b/src/Components/DataGridPaginator/DataGridPaginator.php @@ -102,7 +102,7 @@ public function render(): void */ $count = 1; - $perPage = (int) $paginator->pageCount; + $perPage = $paginator->pageCount; $quotient = ($perPage - 1) / $count; diff --git a/src/DataGrid.php b/src/DataGrid.php index 87887f91..d1ef056f 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -478,13 +478,7 @@ function (Presenter $presenter): void { * Get session */ if ($this->rememberState || $this->canHideColumns()) { - $sessionSection = $presenter->getSession($this->getSessionSectionName()); - - if (!$sessionSection instanceof SessionSection) { - throw new \UnexpectedValueException; - } - - $this->gridSession = $sessionSection; + $this->gridSession = $presenter->getSession($this->getSessionSectionName()); } $this->componentFullName = $this->lookupPath(); @@ -2526,13 +2520,7 @@ public function isPaginated(): bool public function getPaginator(): ?DataGridPaginator { if ($this->isPaginated() && $this->perPage !== 'all') { - $paginator = $this['paginator']; - - if (!$paginator instanceof DataGridPaginator) { - throw new \UnexpectedValueException; - } - - return $paginator; + return $this['paginator']; } return null; @@ -2891,11 +2879,6 @@ public function handleInlineEdit($id): void $primaryWhereColumn = $this->inlineEdit->getPrimaryWhereColumn(); $filterContainer = $this['filter']; - - if (!$filterContainer instanceof Container) { - throw new \UnexpectedValueException; - } - $inlineEditContainer = $filterContainer['inline_edit']; if (!$inlineEditContainer instanceof Container) { @@ -3330,13 +3313,7 @@ protected function addToExports(Export $export): Export private function getPresenterInstance(): Presenter { - $presenter = $this->getPresenter(); - - if (!$presenter instanceof Presenter) { - throw new \UnexpectedValueException; - } - - return $presenter; + return $this->getPresenter(); } } diff --git a/src/Export/ExportCsv.php b/src/Export/ExportCsv.php index 945a13ba..9e219fac 100644 --- a/src/Export/ExportCsv.php +++ b/src/Export/ExportCsv.php @@ -5,7 +5,6 @@ namespace Ublaboo\DataGrid\Export; use Contributte\Application\Response\CSVResponse; -use Nette\Application\UI\Presenter; use Ublaboo\DataGrid\CsvDataModel; use Ublaboo\DataGrid\DataGrid; @@ -47,24 +46,20 @@ private function getExportCallback( DataGrid $grid ) use ($name, $outputEncoding, $delimiter, $includeBom): void { $columns = $this->getColumns(); - + if ($columns === []) { $columns = $this->grid->getColumns(); } $csvDataModel = new CsvDataModel($data, $columns, $this->grid->getTranslator()); - if ($this->grid->getPresenter() instanceof Presenter) { - $this->grid->getPresenter()->sendResponse(new CSVResponse( - $csvDataModel->getSimpleData(), - $name, - $outputEncoding, - $delimiter, - $includeBom - )); - - exit(0); - } + $this->grid->getPresenter()->sendResponse(new CSVResponse( + $csvDataModel->getSimpleData(), + $name, + $outputEncoding, + $delimiter, + $includeBom + )); }; } } diff --git a/src/Traits/TLink.php b/src/Traits/TLink.php index 1734d36f..b397b5ae 100644 --- a/src/Traits/TLink.php +++ b/src/Traits/TLink.php @@ -33,12 +33,6 @@ protected function createLink( $presenter = $grid->getPresenter(); - if (!$presenter instanceof Presenter) { - throw new UnexpectedValueException( - sprintf('%s needs instanceof %s', self::class, Presenter::class) - ); - } - if (strpos($href, ':') !== false) { return $presenter->link($href, $params); } @@ -88,9 +82,9 @@ private function createHierarchyLookupException( $parent = $grid->getParent(); $presenter = $grid->getPresenter(); - if ($parent === null || $presenter === null) { + if ($parent === null) { throw new UnexpectedValueException( - sprintf('%s can not live withnout a parent component or presenter', self::class) + sprintf('%s can not live withnout a parent component', self::class) ); }