diff --git a/.travis.yml b/.travis.yml index 6d2a3fa4..3cf5faba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,8 @@ before_script: - mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql script: + - composer phpstan + - composer phpcs - vendor/bin/tester tests/ -c tests/php.ini jobs: diff --git a/src/Column/Column.php b/src/Column/Column.php index 8a9f1cc5..e29da1c9 100644 --- a/src/Column/Column.php +++ b/src/Column/Column.php @@ -180,11 +180,7 @@ public function isSortable(): bool return $this->sortable; } - if ($this->sortable !== '') { - return true; - } - - return false; + return $this->sortable !== ''; } diff --git a/src/DataGrid.php b/src/DataGrid.php index 8f7ec325..680e855d 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -418,7 +418,7 @@ class DataGrid extends Control private $customPaginatorTemplate = null; /** - * @var string + * @var string|null */ private $componentFullName; @@ -2047,7 +2047,7 @@ public function handleResetFilter(): void $this->deleteSessionData('_grid_has_sorted'); } - foreach ($this->getSessionData() as $key => $val) { + foreach (array_keys($this->getSessionData()) as $key) { if (!in_array($key, [ '_grid_perPage', '_grid_sort', @@ -2501,7 +2501,9 @@ public function getPerPage() $perPage = reset($itemsPerPageList); } - return $perPage === 'all' ? 'all' : (int) $perPage; + return $perPage === 'all' + ? 'all' + : (int) $perPage; } @@ -2998,10 +3000,9 @@ public function getColumnsSummary(): ?ColumnsSummary /** * Gets component's full name in component tree - * @return string * @throws DataGridHasToBeAttachedToPresenterComponentException */ - public function getFullName() : string + public function getFullName(): string { if ($this->componentFullName === null) { throw new DataGridHasToBeAttachedToPresenterComponentException( diff --git a/src/GroupAction/GroupActionCollection.php b/src/GroupAction/GroupActionCollection.php index aed796fb..3b30eb32 100644 --- a/src/GroupAction/GroupActionCollection.php +++ b/src/GroupAction/GroupActionCollection.php @@ -111,14 +111,14 @@ public function addToFormContainer(Container $container): void $groupActionSelect->addCondition(Form::FILLED) ->toggle( - strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit' + strtolower($this->datagrid->getFullName()) . 'group_action_submit' ); $container->addSubmit('submit', 'ublaboo_datagrid.execute') ->setValidationScope([$container]) ->setAttribute( 'id', - strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit' + strtolower($this->datagrid->getFullName()) . 'group_action_submit' ); $form->onSubmit[] = [$this, 'submitted']; @@ -146,7 +146,7 @@ public function submitted(Form $form): void */ $http_ids = $form->getHttpData( Form::DATA_LINE | Form::DATA_KEYS, - strtolower((string) $this->datagrid->getFullName()) . '_group_action_item[]' + strtolower($this->datagrid->getFullName()) . '_group_action_item[]' ); $ids = array_keys($http_ids); diff --git a/tests/Cases/CreateLinkTest.phpt b/tests/Cases/CreateLinkTest.phpt index a5f18b21..d60e08eb 100644 --- a/tests/Cases/CreateLinkTest.phpt +++ b/tests/Cases/CreateLinkTest.phpt @@ -4,8 +4,6 @@ declare(strict_types=1); namespace Ublaboo\DataGrid\Tests\Cases; -use InvalidArgumentException; -use Nette\Application\UI\InvalidLinkException; use Nette\Application\UI\Presenter; use Tester\Assert; use Tester\TestCase; diff --git a/tests/Cases/DataSources/ArrayDataSourceTest.phpt b/tests/Cases/DataSources/ArrayDataSourceTest.phpt index cae460de..4c7842e2 100644 --- a/tests/Cases/DataSources/ArrayDataSourceTest.phpt +++ b/tests/Cases/DataSources/ArrayDataSourceTest.phpt @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Ublaboo\DataGrid\Tests\Cases\DataSources; -use Ublaboo; use Ublaboo\DataGrid\DataSource\ArrayDataSource; use Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory; diff --git a/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php b/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php index b27bfa4f..367ac3d9 100644 --- a/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php +++ b/tests/Cases/DataSources/DoctrineCollectionDataSourceTest.php @@ -6,7 +6,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Tester\Assert; -use Ublaboo; use Ublaboo\DataGrid\DataSource\DoctrineCollectionDataSource; use Ublaboo\DataGrid\Filter\FilterText; use Ublaboo\DataGrid\Tests\Files\TestingDataGridFactory; diff --git a/tests/Cases/ItemsPerPageTest.phpt b/tests/Cases/ItemsPerPageTest.phpt index 4bce87c6..45c2f423 100644 --- a/tests/Cases/ItemsPerPageTest.phpt +++ b/tests/Cases/ItemsPerPageTest.phpt @@ -1,5 +1,7 @@ grid->setItemsPerPageList([10, 20, 50], false); + $this->grid->setItemsPerPageList([10, 20, 50], false); - $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + $this->grid->perPage = 20; + Tester\Assert::same(20, $this->grid->getPerPage()); - $this->grid->perPage = 'all'; - Tester\Assert::same(10, $this->grid->getPerPage()); + $this->grid->perPage = 'all'; + Tester\Assert::same(10, $this->grid->getPerPage()); } - public function testGetPerPageAll() - { - $this->grid->setItemsPerPageList([10, 20, 50], true); + public function testGetPerPageAll() + { + $this->grid->setItemsPerPageList([10, 20, 50], true); - $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + $this->grid->perPage = 20; + Tester\Assert::same(20, $this->grid->getPerPage()); - $this->grid->perPage = 'all'; - Tester\Assert::same('all', $this->grid->getPerPage()); - } + $this->grid->perPage = 'all'; + Tester\Assert::same('all', $this->grid->getPerPage()); + } public function testGetPerPageAllTranslated() - { - $translator = new Ublaboo\DataGrid\Localization\SimpleTranslator([ - 'ublaboo_datagrid.all' => 'všechny' - ]); - $this->grid->setTranslator($translator); + { + $translator = new Ublaboo\DataGrid\Localization\SimpleTranslator([ + 'ublaboo_datagrid.all' => 'všechny', + ]); + $this->grid->setTranslator($translator); - $this->grid->setItemsPerPageList([10, 20, 50], true); + $this->grid->setItemsPerPageList([10, 20, 50], true); - $this->grid->perPage = 20; - Tester\Assert::same(20, $this->grid->getPerPage()); + $this->grid->perPage = 20; + Tester\Assert::same(20, $this->grid->getPerPage()); - $this->grid->perPage = 'all'; - Tester\Assert::same('all', $this->grid->getPerPage()); - } + $this->grid->perPage = 'all'; + Tester\Assert::same('all', $this->grid->getPerPage()); + } } $test = new ItemsPerPageTest(); diff --git a/tests/Files/TestingPresenter.php b/tests/Files/TestingPresenter.php index f2ce13a3..1e04925a 100644 --- a/tests/Files/TestingPresenter.php +++ b/tests/Files/TestingPresenter.php @@ -4,7 +4,6 @@ namespace Ublaboo\DataGrid\Tests\Files; -use Nette\Application\UI\Component; use Nette\Application\UI\Presenter; use Ublaboo\DataGrid\DataGrid; @@ -31,9 +30,6 @@ public function link(string $destination, $args = []): string } - /** - * {@inheritDoc} - */ /*protected function createRequest( Component $component, string $destination,