Skip to content

Commit bd74622

Browse files
Merge pull request #276 from uuf6429/chore/phpstan-setup
PHPStan setup & level1 fixes
2 parents 70cf6bf + 6bbb4d3 commit bd74622

24 files changed

+212
-232
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/phpunit.dist.xml export-ignore
99
/.php-cs-fixer.dist.php export-ignore
1010
/.git-blame-ignore-revs export-ignore
11+
/phpstan.dist.neon export-ignore

.github/workflows/build.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,28 @@ on:
88
types: [ created ]
99

1010
jobs:
11-
check_code_style:
12-
name: Check code style
11+
check_composer:
12+
name: Check composer.json
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
1716
- uses: shivammathur/setup-php@v2
1817
with:
1918
coverage: none
2019
php-version: '8.3'
20+
- run: composer validate --strict --no-check-lock
2121

22-
- name: Install dependencies
23-
run: composer update
24-
25-
- run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots
22+
check_code:
23+
name: Check code style
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: shivammathur/setup-php@v2
28+
with:
29+
coverage: none
30+
php-version: '8.3'
31+
- run: composer update
32+
- run: composer lint
2633

2734
tests:
2835
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ composer.lock
66
phpunit.xml
77
.php-cs-fixer.php
88
.php-cs-fixer.cache
9+
phpstan.neon

bin/update_cucumber

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ foreach (json_decode($composerConfig, true, 512, JSON_THROW_ON_ERROR)['repositor
2121
}
2222
}
2323

24-
if (!isset($oldHash)) {
24+
if (!isset($oldHash, $oldTag)) {
2525
echo "ERROR: Could not parse the composer configuration\n";
2626
exit(1);
2727
}

composer.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
2424
"phpunit/phpunit": "^10.5",
2525
"cucumber/cucumber": "dev-gherkin-24.1.0",
26-
"friendsofphp/php-cs-fixer": "^3.65"
26+
"friendsofphp/php-cs-fixer": "^3.65",
27+
"phpstan/phpstan": "^2",
28+
"phpstan/extension-installer": "^1",
29+
"phpstan/phpstan-phpunit": "^2"
2730
},
2831

2932
"suggest": {
@@ -71,20 +74,25 @@
7174
"scripts": {
7275
"lint": [
7376
"Composer\\Config::disableProcessTimeout",
74-
"vendor/bin/php-cs-fixer check --diff --show-progress=dots --verbose"
77+
"vendor/bin/phpstan analyze --ansi --no-progress --memory-limit 512M",
78+
"vendor/bin/phpstan analyze bin/cucumber_changelog --ansi --no-progress --memory-limit 512M",
79+
"vendor/bin/phpstan analyze bin/update_cucumber --ansi --no-progress --memory-limit 512M",
80+
"vendor/bin/phpstan analyze bin/update_i18n --ansi --no-progress --memory-limit 512M",
81+
"vendor/bin/php-cs-fixer check --diff --ansi --show-progress=dots --verbose"
7582
],
7683
"test": [
7784
"Composer\\Config::disableProcessTimeout",
78-
"vendor/bin/phpunit ./tests"
85+
"vendor/bin/phpunit --colors"
7986
],
8087
"fix": [
8188
"Composer\\Config::disableProcessTimeout",
82-
"vendor/bin/php-cs-fixer fix --diff --show-progress=dots"
89+
"vendor/bin/php-cs-fixer fix --diff --ansi --show-progress=dots"
8390
]
8491
},
92+
8593
"config": {
8694
"allow-plugins": {
87-
"phpstan/extension-installer": false
95+
"phpstan/extension-installer": true
8896
}
8997
}
9098
}

phpstan.dist.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 1
3+
paths:
4+
- src
5+
- tests

src/Behat/Gherkin/Filter/PathsFilter.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@ class PathsFilter extends SimpleFilter
2525
/**
2626
* Initializes filter.
2727
*
28-
* @param string[] $paths List of approved paths
28+
* @param array<array-key, string> $paths List of approved paths
2929
*/
3030
public function __construct(array $paths)
3131
{
32-
$this->filterPaths = array_map(
33-
function ($realpath) {
34-
return rtrim($realpath, DIRECTORY_SEPARATOR) .
35-
(is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
36-
},
37-
array_filter(
38-
array_map('realpath', $paths)
39-
)
40-
);
32+
foreach ($paths as $path) {
33+
if (($realpath = realpath($path)) === false) {
34+
continue;
35+
}
36+
$this->filterPaths[] = rtrim($realpath, DIRECTORY_SEPARATOR)
37+
. (is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
38+
}
4139
}
4240

4341
/**
@@ -50,7 +48,7 @@ function ($realpath) {
5048
public function isFeatureMatch(FeatureNode $feature)
5149
{
5250
foreach ($this->filterPaths as $path) {
53-
if (strpos(realpath($feature->getFile()), $path) === 0) {
51+
if (str_starts_with(realpath($feature->getFile()), $path)) {
5452
return true;
5553
}
5654
}

src/Behat/Gherkin/Filter/TagFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function isScenarioMatch(FeatureNode $feature, ScenarioInterface $scenari
128128
/**
129129
* Checks that node matches condition.
130130
*
131-
* @param string[] $tags
131+
* @param array<array-key, string> $tags
132132
*
133133
* @return bool
134134
*/

src/Behat/Gherkin/Gherkin.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class Gherkin
3131
public const VERSION = '4.8.0';
3232

3333
/**
34-
* @var LoaderInterface[]
34+
* @var list<LoaderInterface>
3535
*/
3636
protected $loaders = [];
3737
/**
38-
* @var FeatureFilterInterface[]
38+
* @var list<FeatureFilterInterface>
3939
*/
4040
protected $filters = [];
4141

@@ -62,12 +62,12 @@ public function addFilter(FeatureFilterInterface $filter)
6262
/**
6363
* Sets filters to the parser.
6464
*
65-
* @param FeatureFilterInterface[] $filters
65+
* @param array<array-key, FeatureFilterInterface> $filters
6666
*/
6767
public function setFilters(array $filters)
6868
{
6969
$this->filters = [];
70-
array_map([$this, 'addFilter'], $filters);
70+
array_map($this->addFilter(...), $filters);
7171
}
7272

7373
/**
@@ -88,7 +88,7 @@ public function setBasePath($path)
8888
* Loads & filters resource with added loaders.
8989
*
9090
* @param mixed $resource Resource to load
91-
* @param FeatureFilterInterface[] $filters Additional filters
91+
* @param array<array-key, FeatureFilterInterface> $filters Additional filters
9292
*
9393
* @return array
9494
*/
@@ -97,10 +97,10 @@ public function load($resource, array $filters = [])
9797
$filters = array_merge($this->filters, $filters);
9898

9999
$matches = [];
100-
if (preg_match('/^(.*)\:(\d+)-(\d+|\*)$/', $resource, $matches)) {
100+
if (preg_match('/^(.*):(\d+)-(\d+|\*)$/', $resource, $matches)) {
101101
$resource = $matches[1];
102102
$filters[] = new LineRangeFilter($matches[2], $matches[3]);
103-
} elseif (preg_match('/^(.*)\:(\d+)$/', $resource, $matches)) {
103+
} elseif (preg_match('/^(.*):(\d+)$/', $resource, $matches)) {
104104
$resource = $matches[1];
105105
$filters[] = new LineFilter($matches[2]);
106106
}
@@ -132,7 +132,7 @@ public function load($resource, array $filters = [])
132132
*
133133
* @param mixed $resource Resource to load
134134
*
135-
* @return LoaderInterface
135+
* @return LoaderInterface|null
136136
*/
137137
public function resolveLoader($resource)
138138
{

src/Behat/Gherkin/Keywords/ArrayKeywords.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function setLanguage($language)
7373
}
7474

7575
/**
76-
* Returns Feature keywords (splitted by "|").
76+
* Returns Feature keywords (separated by "|").
7777
*
7878
* @return string
7979
*/
@@ -83,7 +83,7 @@ public function getFeatureKeywords()
8383
}
8484

8585
/**
86-
* Returns Background keywords (splitted by "|").
86+
* Returns Background keywords (separated by "|").
8787
*
8888
* @return string
8989
*/
@@ -93,7 +93,7 @@ public function getBackgroundKeywords()
9393
}
9494

9595
/**
96-
* Returns Scenario keywords (splitted by "|").
96+
* Returns Scenario keywords (separated by "|").
9797
*
9898
* @return string
9999
*/
@@ -103,7 +103,7 @@ public function getScenarioKeywords()
103103
}
104104

105105
/**
106-
* Returns Scenario Outline keywords (splitted by "|").
106+
* Returns Scenario Outline keywords (separated by "|").
107107
*
108108
* @return string
109109
*/
@@ -113,7 +113,7 @@ public function getOutlineKeywords()
113113
}
114114

115115
/**
116-
* Returns Examples keywords (splitted by "|").
116+
* Returns Examples keywords (separated by "|").
117117
*
118118
* @return string
119119
*/
@@ -123,7 +123,7 @@ public function getExamplesKeywords()
123123
}
124124

125125
/**
126-
* Returns Given keywords (splitted by "|").
126+
* Returns Given keywords (separated by "|").
127127
*
128128
* @return string
129129
*/
@@ -133,7 +133,7 @@ public function getGivenKeywords()
133133
}
134134

135135
/**
136-
* Returns When keywords (splitted by "|").
136+
* Returns When keywords (separated by "|").
137137
*
138138
* @return string
139139
*/
@@ -143,7 +143,7 @@ public function getWhenKeywords()
143143
}
144144

145145
/**
146-
* Returns Then keywords (splitted by "|").
146+
* Returns Then keywords (separated by "|").
147147
*
148148
* @return string
149149
*/
@@ -153,7 +153,7 @@ public function getThenKeywords()
153153
}
154154

155155
/**
156-
* Returns And keywords (splitted by "|").
156+
* Returns And keywords (separated by "|").
157157
*
158158
* @return string
159159
*/
@@ -163,7 +163,7 @@ public function getAndKeywords()
163163
}
164164

165165
/**
166-
* Returns But keywords (splitted by "|").
166+
* Returns But keywords (separated by "|").
167167
*
168168
* @return string
169169
*/

0 commit comments

Comments
 (0)