Skip to content

Commit

Permalink
Codesniffer & phpstan upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x authored and Pavel Janda committed Feb 11, 2022
1 parent 7da1a7e commit 3620f31
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
codesniffer:
name: "Codesniffer"
uses: contributte/.github/.github/workflows/codesniffer.yml@v1
with:
php: "8.0"
7 changes: 5 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
jobs:
test80:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
with:
php: "8.0"
php: "8.0"
database: tests
coverage: true
makefile: coverage
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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
# test81:
# name: "Nette Tester"
# uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
# with:
# php: "8.1"
# database: tests

test80:
name: "Nette Tester"
Expand Down
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
.PHONY: install qa cs csf phpstan tests coverage-clover coverage-html
.PHONY: install qa cs csf phpstan tests coverage

install:
composer update

qa: phpstan cs

cs:
vendor/bin/phpcs --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src tests
ifdef GITHUB_ACTION
vendor/bin/phpcs --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=tests/tmp -q --report=checkstyle src tests | cs2pr
else
vendor/bin/phpcs --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=tests/tmp --colors -nsp src tests
endif

csf:
vendor/bin/phpcbf --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src tests
vendor/bin/phpcbf --standard=ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=tests/tmp --colors -nsp src tests

phpstan:
vendor/bin/phpstan analyse -l max -c phpstan.neon --memory-limit=512M src
vendor/bin/phpstan analyse -c phpstan.neon

tests:
vendor/bin/tester -s -p php --colors 1 -C tests

coverage-clover:
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src ./tests

coverage-html:
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src ./tests
vendor/bin/tester -s -p php --colors 1 -C tests/Cases

coverage:
ifdef GITHUB_ACTION
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/Cases
else
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.html --coverage-src src tests/Cases
endif
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"doctrine/cache": "^1.11",
"doctrine/orm": "^2.6.12",
"elasticsearch/elasticsearch": "^7.1",
"gamee/php-code-checker-rules": "^2.0.21",
"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.0",
"phpstan/phpstan-nette": "^0.12.14",
"ninjify/coding-standard": "^0.12.1",
"phpstan/phpstan-nette": "^1.0.0",
"tharos/leanmapper": "^3.4.2 || ^4.0.0",
"tracy/tracy": "^2.6.3"
},
Expand Down
22 changes: 17 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
includes:
- ./vendor/gamee/php-code-checker-rules/phpstan.neon
- ./vendor/contributte/code-rules/paveljanda/phpstan.neon
- ./vendor/phpstan/phpstan-nette/extension.neon
- ./vendor/phpstan/phpstan-nette/rules.neon

parameters:
level: 8
phpVersion: 70200

paths:
- src

reportMaybesInPropertyPhpDocTypes: false

ignoreErrors:
-
message: '/^Cannot call method filter(Data|Row)\(\) on Ublaboo\\DataGrid\\DataModel\|null\.$/'
count: 2
path: src/DataGrid.php
-
message: '/^Call to an undefined method Nette\\Bridges\\ApplicationLatte\\Template::add\(\)\.$/'
count: 2
Expand Down Expand Up @@ -37,3 +41,11 @@ parameters:
message: '/^Instanceof between Dibi\\Result and Dibi\\Result will always evaluate to true\.$/'
count: 1
path: src/DataSource/DibiFluentMssqlDataSource.php
-
message: "#^Cannot call method filterData\\(\\) on Ublaboo\\\\DataGrid\\\\DataModel\\|null\\.$#"
count: 1
path: src/DataGrid.php
-
message: "#^Cannot call method filterRow\\(\\) on Ublaboo\\\\DataGrid\\\\DataModel\\|null\\.$#"
count: 1
path: src/DataGrid.php
29 changes: 15 additions & 14 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?xml version="1.0"?>
<ruleset>
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/ruleset-gamee.xml">
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment" />
<exclude name="SlevomatCodingStandard.Classes.MethodSpacing.IncorrectLinesCountBetweenMethods" />
<exclude name="SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers" />
<exclude name="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode.DisallowedCommentAfterCode" />
<exclude name="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature.RequiredSingleLineSignature" />
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator" />
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong" />
<exclude name="SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall" />
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed" />
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment"/>
<exclude name="SlevomatCodingStandard.Classes.MethodSpacing.IncorrectLinesCountBetweenMethods"/>
<exclude name="SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers"/>
<exclude name="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode.DisallowedCommentAfterCode"/>
<exclude name="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature.RequiredSingleLineSignature"/>
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator"/>
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong"/>
<exclude name="SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall"/>
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed"/>
</rule>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src=>Ublaboo\DataGrid,
tests/Cases=>Ublaboo\DataGrid\Tests\Cases,
tests/Files=>Ublaboo\DataGrid\Tests\Files,
"/>
<property name="rootNamespaces" type="array">
<element key="src" value="Ublaboo\DataGrid"/>
<element key="tests/Cases" value="Ublaboo\DataGrid\Tests\Cases"/>
<element key="tests/Files" value="Ublaboo\DataGrid\Tests\Files"/>
</property>
<property name="extensions" type="array" value="php,phpt"/>
</properties>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion src/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class Column extends FilterableColumn
protected $headerEscaping = false;

/**
* @var string
* @var string|null
*/
protected $align;

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 @@ -40,7 +40,7 @@ class DataGridPaginator extends Control
private $paginator;

/**
* @var string
* @var string|null
*/
private $templateFile;

Expand Down
14 changes: 9 additions & 5 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,15 @@ public function render(): void
*/
$rows = [];

$items = $this->redrawItem !== [] ? $this->dataModel->filterRow($this->redrawItem) : $this->dataModel->filterData(
$this->getPaginator(),
$this->createSorting($this->sort, $this->sortCallback),
$this->assembleFilters()
);
if ($this->redrawItem !== []) {
$items = $this->dataModel->filterRow($this->redrawItem);
} else {
$items = $this->dataModel->filterData(
$this->getPaginator(),
$this->createSorting($this->sort, $this->sortCallback),
$this->assembleFilters()
);
}

$hasGroupActionOnRows = false;

Expand Down
11 changes: 7 additions & 4 deletions src/DataSource/DoctrineDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ublaboo\DataGrid\AggregationFunction\IAggregatable;
use Ublaboo\DataGrid\AggregationFunction\IAggregationFunction;
use Ublaboo\DataGrid\Exception\DataGridDateTimeHelperException;
use Ublaboo\DataGrid\Exception\DataGridException;
use Ublaboo\DataGrid\Filter\FilterDate;
use Ublaboo\DataGrid\Filter\FilterDateRange;
use Ublaboo\DataGrid\Filter\FilterMultiSelect;
Expand Down Expand Up @@ -47,7 +48,7 @@ class DoctrineDataSource extends FilterableDataSource implements IDataSource, IA
protected $primaryKey;

/**
* @var string
* @var string|null
*/
protected $rootAlias;

Expand Down Expand Up @@ -341,11 +342,13 @@ private function checkAliases(string $column): string
}

if (!isset($this->rootAlias)) {
$rootAlias = current($this->dataSource->getRootAliases());
$rootAlias = $this->dataSource->getRootAliases();

if ($rootAlias !== false) {
$this->rootAlias = $rootAlias;
if ($rootAlias === []) {
throw new DataGridException('No root alias given from datasource');
}

$this->rootAlias = current($rootAlias);
}

return $this->rootAlias . '.' . $column;
Expand Down
4 changes: 0 additions & 4 deletions src/Traits/TLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Ublaboo\DataGrid\Traits;

use InvalidArgumentException;
use Nette;
use Nette\Application\UI\Component;
use Nette\Application\UI\InvalidLinkException;
use Nette\Application\UI\Presenter;
Expand Down Expand Up @@ -46,11 +45,8 @@ protected function createLink(

try {
$link = $targetComponent->link($href, $params);

} catch (InvalidLinkException $e) {
$link = false;
} catch (Nette\InvalidArgumentException $e) {
$link = false;
}

if (is_string($link)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Utils/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public static function fromString($value, array $formats = []): \DateTime
}

if ($value instanceof DateTimeImmutable) {
$date = new \DateTime('now', $value->getTimezone() ?? null);
/** @var \DateTimeZone|false $tz */
$tz = $value->getTimezone();
$date = new \DateTime('now', $tz !== false ? $tz : null);
$date->setTimestamp($value->getTimestamp());

return $date;
Expand Down
4 changes: 2 additions & 2 deletions tests/Files/TestingPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function handleDoStuff(int $id): void
/**
* {@inheritDoc}
*/
public function link(string $destination, ...$args): string
public function link(string $destination, $args = []): string
{
return $destination . '?' . http_build_query($args[0]);
return $destination . '?' . http_build_query($args);
}


Expand Down

0 comments on commit 3620f31

Please sign in to comment.