Skip to content

Commit 3620f31

Browse files
f3l1xPavel Janda
authored and
Pavel Janda
committed
Codesniffer & phpstan upgrades
1 parent 7da1a7e commit 3620f31

File tree

14 files changed

+87
-59
lines changed

14 files changed

+87
-59
lines changed

.github/workflows/codesniffer.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ jobs:
1313
codesniffer:
1414
name: "Codesniffer"
1515
uses: contributte/.github/.github/workflows/codesniffer.yml@v1
16+
with:
17+
php: "8.0"

.github/workflows/coverage.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
jobs:
1313
test80:
1414
name: "Nette Tester"
15-
uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1
15+
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
1616
with:
17-
php: "8.0"
17+
php: "8.0"
18+
database: tests
19+
coverage: true
20+
makefile: coverage

.github/workflows/tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ on:
1010
- cron: "0 8 * * 1"
1111

1212
jobs:
13-
test81:
14-
name: "Nette Tester"
15-
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
16-
with:
17-
php: "8.1"
18-
database: tests
13+
# test81:
14+
# name: "Nette Tester"
15+
# uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
16+
# with:
17+
# php: "8.1"
18+
# database: tests
1919

2020
test80:
2121
name: "Nette Tester"

Makefile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
.PHONY: install qa cs csf phpstan tests coverage-clover coverage-html
1+
.PHONY: install qa cs csf phpstan tests coverage
22

33
install:
44
composer update
55

66
qa: phpstan cs
77

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

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

1418
phpstan:
15-
vendor/bin/phpstan analyse -l max -c phpstan.neon --memory-limit=512M src
19+
vendor/bin/phpstan analyse -c phpstan.neon
1620

1721
tests:
18-
vendor/bin/tester -s -p php --colors 1 -C tests
19-
20-
coverage-clover:
21-
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src ./tests
22-
23-
coverage-html:
24-
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src ./tests
22+
vendor/bin/tester -s -p php --colors 1 -C tests/Cases
23+
24+
coverage:
25+
ifdef GITHUB_ACTION
26+
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/Cases
27+
else
28+
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.html --coverage-src src tests/Cases
29+
endif

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646
"doctrine/cache": "^1.11",
4747
"doctrine/orm": "^2.6.12",
4848
"elasticsearch/elasticsearch": "^7.1",
49-
"gamee/php-code-checker-rules": "^2.0.21",
49+
"contributte/code-rules": "^1.1.0",
5050
"mockery/mockery": "^1.3.3",
5151
"nette/database": "^3.0.2",
5252
"nette/tester": "^2.3.4",
5353
"nextras/dbal": "^3.0.1 || ^4.0",
5454
"nextras/orm": "^3.1.0 || ^4.0",
55-
"ninjify/coding-standard": "^0.12.0",
56-
"phpstan/phpstan-nette": "^0.12.14",
55+
"ninjify/coding-standard": "^0.12.1",
56+
"phpstan/phpstan-nette": "^1.0.0",
5757
"tharos/leanmapper": "^3.4.2 || ^4.0.0",
5858
"tracy/tracy": "^2.6.3"
5959
},

phpstan.neon

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
includes:
2-
- ./vendor/gamee/php-code-checker-rules/phpstan.neon
2+
- ./vendor/contributte/code-rules/paveljanda/phpstan.neon
33
- ./vendor/phpstan/phpstan-nette/extension.neon
44
- ./vendor/phpstan/phpstan-nette/rules.neon
55

66
parameters:
7+
level: 8
8+
phpVersion: 70200
9+
10+
paths:
11+
- src
12+
13+
reportMaybesInPropertyPhpDocTypes: false
14+
715
ignoreErrors:
8-
-
9-
message: '/^Cannot call method filter(Data|Row)\(\) on Ublaboo\\DataGrid\\DataModel\|null\.$/'
10-
count: 2
11-
path: src/DataGrid.php
1216
-
1317
message: '/^Call to an undefined method Nette\\Bridges\\ApplicationLatte\\Template::add\(\)\.$/'
1418
count: 2
@@ -37,3 +41,11 @@ parameters:
3741
message: '/^Instanceof between Dibi\\Result and Dibi\\Result will always evaluate to true\.$/'
3842
count: 1
3943
path: src/DataSource/DibiFluentMssqlDataSource.php
44+
-
45+
message: "#^Cannot call method filterData\\(\\) on Ublaboo\\\\DataGrid\\\\DataModel\\|null\\.$#"
46+
count: 1
47+
path: src/DataGrid.php
48+
-
49+
message: "#^Cannot call method filterRow\\(\\) on Ublaboo\\\\DataGrid\\\\DataModel\\|null\\.$#"
50+
count: 1
51+
path: src/DataGrid.php

ruleset.xml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<?xml version="1.0"?>
22
<ruleset>
3+
<!-- Contributte Coding Standard -->
34
<rule ref="./vendor/ninjify/coding-standard/ruleset-gamee.xml">
4-
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment" />
5-
<exclude name="SlevomatCodingStandard.Classes.MethodSpacing.IncorrectLinesCountBetweenMethods" />
6-
<exclude name="SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers" />
7-
<exclude name="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode.DisallowedCommentAfterCode" />
8-
<exclude name="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature.RequiredSingleLineSignature" />
9-
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator" />
10-
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong" />
11-
<exclude name="SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall" />
12-
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed" />
5+
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment"/>
6+
<exclude name="SlevomatCodingStandard.Classes.MethodSpacing.IncorrectLinesCountBetweenMethods"/>
7+
<exclude name="SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers"/>
8+
<exclude name="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode.DisallowedCommentAfterCode"/>
9+
<exclude name="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature.RequiredSingleLineSignature"/>
10+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator"/>
11+
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong"/>
12+
<exclude name="SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall"/>
13+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed"/>
1314
</rule>
1415

1516
<!-- Specific rules -->
1617
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
1718
<properties>
18-
<property name="rootNamespaces" type="array" value="
19-
src=>Ublaboo\DataGrid,
20-
tests/Cases=>Ublaboo\DataGrid\Tests\Cases,
21-
tests/Files=>Ublaboo\DataGrid\Tests\Files,
22-
"/>
19+
<property name="rootNamespaces" type="array">
20+
<element key="src" value="Ublaboo\DataGrid"/>
21+
<element key="tests/Cases" value="Ublaboo\DataGrid\Tests\Cases"/>
22+
<element key="tests/Files" value="Ublaboo\DataGrid\Tests\Files"/>
23+
</property>
2324
<property name="extensions" type="array" value="php,phpt"/>
2425
</properties>
2526
</rule>

src/Column/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class Column extends FilterableColumn
5757
protected $headerEscaping = false;
5858

5959
/**
60-
* @var string
60+
* @var string|null
6161
*/
6262
protected $align;
6363

src/Components/DataGridPaginator/DataGridPaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DataGridPaginator extends Control
4040
private $paginator;
4141

4242
/**
43-
* @var string
43+
* @var string|null
4444
*/
4545
private $templateFile;
4646

src/DataGrid.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,15 @@ public function render(): void
520520
*/
521521
$rows = [];
522522

523-
$items = $this->redrawItem !== [] ? $this->dataModel->filterRow($this->redrawItem) : $this->dataModel->filterData(
524-
$this->getPaginator(),
525-
$this->createSorting($this->sort, $this->sortCallback),
526-
$this->assembleFilters()
527-
);
523+
if ($this->redrawItem !== []) {
524+
$items = $this->dataModel->filterRow($this->redrawItem);
525+
} else {
526+
$items = $this->dataModel->filterData(
527+
$this->getPaginator(),
528+
$this->createSorting($this->sort, $this->sortCallback),
529+
$this->assembleFilters()
530+
);
531+
}
528532

529533
$hasGroupActionOnRows = false;
530534

src/DataSource/DoctrineDataSource.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ublaboo\DataGrid\AggregationFunction\IAggregatable;
1313
use Ublaboo\DataGrid\AggregationFunction\IAggregationFunction;
1414
use Ublaboo\DataGrid\Exception\DataGridDateTimeHelperException;
15+
use Ublaboo\DataGrid\Exception\DataGridException;
1516
use Ublaboo\DataGrid\Filter\FilterDate;
1617
use Ublaboo\DataGrid\Filter\FilterDateRange;
1718
use Ublaboo\DataGrid\Filter\FilterMultiSelect;
@@ -47,7 +48,7 @@ class DoctrineDataSource extends FilterableDataSource implements IDataSource, IA
4748
protected $primaryKey;
4849

4950
/**
50-
* @var string
51+
* @var string|null
5152
*/
5253
protected $rootAlias;
5354

@@ -341,11 +342,13 @@ private function checkAliases(string $column): string
341342
}
342343

343344
if (!isset($this->rootAlias)) {
344-
$rootAlias = current($this->dataSource->getRootAliases());
345+
$rootAlias = $this->dataSource->getRootAliases();
345346

346-
if ($rootAlias !== false) {
347-
$this->rootAlias = $rootAlias;
347+
if ($rootAlias === []) {
348+
throw new DataGridException('No root alias given from datasource');
348349
}
350+
351+
$this->rootAlias = current($rootAlias);
349352
}
350353

351354
return $this->rootAlias . '.' . $column;

src/Traits/TLink.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Ublaboo\DataGrid\Traits;
66

77
use InvalidArgumentException;
8-
use Nette;
98
use Nette\Application\UI\Component;
109
use Nette\Application\UI\InvalidLinkException;
1110
use Nette\Application\UI\Presenter;
@@ -46,11 +45,8 @@ protected function createLink(
4645

4746
try {
4847
$link = $targetComponent->link($href, $params);
49-
5048
} catch (InvalidLinkException $e) {
5149
$link = false;
52-
} catch (Nette\InvalidArgumentException $e) {
53-
$link = false;
5450
}
5551

5652
if (is_string($link)) {

src/Utils/DateTimeHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public static function fromString($value, array $formats = []): \DateTime
6060
}
6161

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

6668
return $date;

tests/Files/TestingPresenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function handleDoStuff(int $id): void
2424
/**
2525
* {@inheritDoc}
2626
*/
27-
public function link(string $destination, ...$args): string
27+
public function link(string $destination, $args = []): string
2828
{
29-
return $destination . '?' . http_build_query($args[0]);
29+
return $destination . '?' . http_build_query($args);
3030
}
3131

3232

0 commit comments

Comments
 (0)