Skip to content

Commit

Permalink
Make PHPstan green
Browse files Browse the repository at this point in the history
  • Loading branch information
martenb authored and paveljanda committed Feb 15, 2021
1 parent 0be46de commit 15066ae
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 161 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
"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",
"nette/tester": "^2.3.4",
"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",
Expand Down
117 changes: 6 additions & 111 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Components/DataGridPaginator/DataGridPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function render(): void
*/
$count = 1;

$perPage = (int) $paginator->pageCount;
$perPage = $paginator->pageCount;

$quotient = ($perPage - 1) / $count;

Expand Down
29 changes: 3 additions & 26 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

}
21 changes: 8 additions & 13 deletions src/Export/ExportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
));
};
}
}
10 changes: 2 additions & 8 deletions src/Traits/TLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
);
}

Expand Down

0 comments on commit 15066ae

Please sign in to comment.