Skip to content

Commit bb760b6

Browse files
authored
Merge pull request #31 from fey/bump-phpstan
Bump phpstan
2 parents bb33471 + 588925f commit bb760b6

23 files changed

+195
-87
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
php-versions: ['8.1', '8.2', '8.3']
12+
php-versions: ['8.2', '8.3']
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: ${{ matrix.php-versions }}
19+
php-version: ${{ matrix.version }}
20+
coverage: xdebug
21+
22+
- name: Install
23+
run: make install
24+
25+
- name: Run linter
26+
run: make lint analyse
2027

21-
- run: make install
22-
- run: make lint
2328
- run: make test
29+
30+
# - name: Run test & publish code coverage
31+
# uses: paambaati/[email protected]
32+
# env:
33+
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
34+
# with:
35+
# coverageCommand: make test-coverage
36+
# coverageLocations: ${{github.workplace}}/build/logs/clover.xml:clover
37+
# debug: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor/
22
composer.lock
33
*.cache
4+
build
5+
html-coverage

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ test:
55
composer exec -v phpunit tests
66

77
lint:
8-
composer exec -v phpcs src tests
8+
composer exec -v phpcs
9+
10+
analyse:
911
composer exec -v phpstan -- analyse -c phpstan.neon
1012

1113
lint-fix:
12-
composer exec phpcbf -- --standard=PSR12 -v src tests
14+
composer exec -v phpcbf
1315

1416
test-coverage:
15-
composer exec --verbose phpunit tests -- --coverage-clover build/logs/clover.xml
17+
XDEBUG_MODE=coverage composer exec --verbose phpunit tests -- --coverage-clover=build/logs/clover.xml
18+
19+
test-coverage-text:
20+
XDEBUG_MODE=coverage composer exec --verbose phpunit tests -- --coverage-text
21+
22+
test-coverage-html:
23+
XDEBUG_MODE=coverage composer exec --verbose phpunit tests -- --coverage-html=html-coverage

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "hexlet/phpstan-fp",
33
"description": "PHPStan rules for functional programming",
4+
"version": "3.0.0",
45
"type": "library",
56
"require": {
6-
"php": ">=8.1",
7-
"phpstan/phpstan": "^1.10.24",
8-
"illuminate/collections": "^10.14.1"
7+
"php": ">=8.2",
8+
"phpstan/phpstan": "^2.1",
9+
"illuminate/collections": "^12"
910
},
1011
"license": "MIT",
1112
"autoload": {
1213
"psr-4": {
13-
"Hexlet\\PHPStanFp\\": "src/",
14-
"Hexlet\\PHPStanFp\\Tests\\": "tests/"
14+
"Hexlet\\PHPStanFp\\": "src/",
15+
"Hexlet\\PHPStanFp\\Tests\\": "tests/"
1516
}
1617
},
1718
"extra": {
@@ -22,7 +23,7 @@
2223
}
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "^9.5.18",
26-
"squizlabs/php_codesniffer": "^3.6.2"
26+
"phpunit/phpunit": "^11.5 | ^12.0",
27+
"squizlabs/php_codesniffer": "^3.9"
2728
}
2829
}

phpcs.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?xml version="1.0"?>
22
<ruleset name="ruleset">
33
<description>PSR12</description>
4-
54
<arg name="basepath" value="."/>
65
<arg name="colors"/>
76
<arg name="parallel" value="100"/>
8-
<arg value="np"/>
7+
<arg value="n"/>
8+
<arg value="p"/>
9+
10+
<file>src</file>
11+
<file>tests</file>
912

1013
<exclude-pattern>vendor/*</exclude-pattern>
1114
<exclude-pattern>tests/*/data/*</exclude-pattern>

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@ parameters:
33
paths:
44
- src
55
- tests
6-
76
excludePaths:
87
- tests/*/data/*
9-
10-
checkGenericClassInNonGenericObjectType: false
11-
reportUnmatchedIgnoredErrors: false

phpunit.xml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
bootstrap="vendor/autoload.php"
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticProperties="false"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
bootstrap="vendor/autoload.php"
11+
displayDetailsOnTestsThatTriggerDeprecations="true"
12+
displayDetailsOnTestsThatTriggerErrors="true"
13+
displayDetailsOnTestsThatTriggerNotices="true"
14+
displayDetailsOnTestsThatTriggerWarnings="true"
15+
displayDetailsOnPhpunitDeprecations="true"
1116
>
1217
<testsuites>
1318
<testsuite name="Test Suite">
1419
<directory>./tests/</directory>
1520
</testsuite>
1621
</testsuites>
22+
23+
<source>
24+
<include>
25+
<directory suffix=".php">src</directory>
26+
</include>
27+
</source>
1728
</phpunit>

src/Rules/Classes/DisallowClassesRule.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Hexlet\PHPStanFp\Rules\Classes;
44

5-
use PHPStan\Rules\Rule;
65
use PhpParser\Node;
7-
use PHPStan\Analyser\Scope;
86
use PhpParser\Node\Stmt\Class_;
7+
use PHPStan\Analyser\Scope;
8+
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleErrorBuilder;
10+
use PHPStan\Rules\IdentifierRuleError;
911

1012
class DisallowClassesRule implements Rule
1113
{
@@ -22,15 +24,22 @@ public function getNodeType(): string
2224
}
2325

2426
/**
25-
* @param \PhpParser\Node\Stmt\Class_ $node
26-
* @param \PHPStan\Analyser\Scope $scope
27-
* @return string[]
27+
* @param Class_ $node
28+
* @param Scope $scope
29+
* @return IdentifierRuleError[]
2830
*/
2931
public function processNode(Node $node, Scope $scope): array
3032
{
3133
if (!$this->disallowClasses) {
3234
return [];
3335
}
34-
return ['Should not use classes'];
36+
37+
$errorMessage = 'Should not use classes';
38+
39+
return [
40+
RuleErrorBuilder::message($errorMessage)
41+
->identifier('phpstanFunctionalProgramming.disallowClasses')
42+
->build()
43+
];
3544
}
3645
}

src/Rules/Exceptions/DisallowThrowRule.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Hexlet\PHPStanFp\Rules\Exceptions;
44

5-
use PHPStan\Rules\Rule;
65
use PhpParser\Node;
6+
use PhpParser\Node\Expr\Throw_;
77
use PHPStan\Analyser\Scope;
8-
use PhpParser\Node\Stmt\Throw_;
8+
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleErrorBuilder;
10+
use PHPStan\Rules\IdentifierRuleError;
911

1012
class DisallowThrowRule implements Rule
1113
{
@@ -22,15 +24,22 @@ public function getNodeType(): string
2224
}
2325

2426
/**
25-
* @param \PhpParser\Node\Stmt\Throw_ $node
26-
* @param \PHPStan\Analyser\Scope $scope
27-
* @return string[]
27+
* @param Throw_ $node
28+
* @param Scope $scope
29+
* @return IdentifierRuleError[]
2830
*/
2931
public function processNode(Node $node, Scope $scope): array
3032
{
3133
if (!$this->disallowThrow) {
3234
return [];
3335
}
34-
return ['Should not use throw'];
36+
37+
$errorMessage = 'Should not use throw';
38+
39+
return [
40+
RuleErrorBuilder::message($errorMessage)
41+
->identifier('phpstanFunctionalProgramming.disallowThrow')
42+
->build()
43+
];
3544
}
3645
}

src/Rules/Expression/DisallowUnusedExpressionRule.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Hexlet\PHPStanFp\Rules\Expression;
44

5-
use PHPStan\Rules\Rule;
65
use PhpParser\Node;
7-
use PHPStan\Analyser\Scope;
86
use PhpParser\Node\Stmt\Expression;
7+
use PHPStan\Analyser\Scope;
8+
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleErrorBuilder;
10+
use PHPStan\Rules\IdentifierRuleError;
911

1012
class DisallowUnusedExpressionRule implements Rule
1113
{
@@ -22,9 +24,9 @@ public function getNodeType(): string
2224
}
2325

2426
/**
25-
* @param \PhpParser\Node\Stmt\Expression $node
26-
* @param \PHPStan\Analyser\Scope $scope
27-
* @return string[]
27+
* @param Expression $node
28+
* @param Scope $scope
29+
* @return IdentifierRuleError[]
2830
*/
2931
public function processNode(Node $node, Scope $scope): array
3032
{
@@ -36,6 +38,10 @@ public function processNode(Node $node, Scope $scope): array
3638
return [];
3739
}
3840

39-
return ['Enforce that an expression gets used'];
41+
return [
42+
RuleErrorBuilder::message('Enforce that an expression gets used')
43+
->identifier('phpstanFunctionalProgramming.disallowUnusedExpression')
44+
->build()
45+
];
4046
}
4147
}

0 commit comments

Comments
 (0)