Skip to content

Commit f3f6fb0

Browse files
Fix PHP 7 parse error in the Escaper stub
1 parent b9125ee commit f3f6fb0

6 files changed

Lines changed: 100 additions & 1 deletion

File tree

‎.github/workflows/ci.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ on:
66
- "master"
77

88
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
# Both ends of the composer.json "php" constraint: the lowest version
15+
# of each supported range, plus the newest release.
16+
php-versions: ['7.2', '8.1', '8.5']
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v2
20+
21+
- name: Configure PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php-versions }}
25+
coverage: none
26+
27+
- name: Lint sources
28+
run: ./bin/ci_php_lint
29+
930
run:
1031
runs-on: ${{ matrix.operating-system }}
1132
strategy:
@@ -56,6 +77,9 @@ jobs:
5677
- name: Static code analysis
5778
run: composer analyze
5879

80+
- name: Static code analysis of the Magento stubs
81+
run: composer analyze-stubs
82+
5983
- name: Unittests
6084
if: matrix.coveralls == false
6185
run: composer test

‎CHANGELOG.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## Unreleased
6+
7+
### Added
8+
9+
- [#359](https://github.com/bitExpert/phpstan-magento/pull/359) Lint `src/` on the lowest supported PHP version in CI and analyse the `src/Magento` stubs against the PHP version range declared in composer.json.
10+
11+
### Deprecated
12+
13+
- Nothing.
14+
15+
### Removed
16+
17+
- Nothing.
18+
19+
### Fixed
20+
21+
- [#359](https://github.com/bitExpert/phpstan-magento/pull/359) Drop the PHP 8 union type from the `Escaper` stub. It is `require()`d by the MockAutoloader, so it made every analysis run on PHP 7 fail with an internal error.
22+
523
## 0.43.0
624

725
### Added

‎bin/ci_php_lint‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# This file is part of the phpstan-magento package.
5+
#
6+
# (c) bitExpert AG
7+
#
8+
# For the full copyright and license information, please view the LICENSE
9+
# file that was distributed with this source code.
10+
#
11+
12+
# Lints every shipped source file with the PHP binary found on the PATH. Run it
13+
# on the lowest PHP version composer.json supports: the stubs below src/Magento
14+
# are require()d by the MockAutoloader inside the process running PHPStan, so a
15+
# parse error there aborts the analysis of any project using this package.
16+
17+
set -uo pipefail
18+
19+
cd "$(dirname "$0")/.."
20+
21+
status=0
22+
while IFS= read -r -d '' file; do
23+
if ! output="$(php -l "$file" 2>&1)"; then
24+
echo "$output"
25+
status=1
26+
fi
27+
done < <(find src -name '*.php' -print0)
28+
29+
if [ "$status" -eq 0 ]; then
30+
echo "No syntax errors detected in src/ on PHP $(php -r 'echo PHP_VERSION;')."
31+
fi
32+
33+
exit $status

‎composer.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"cs-fix": "vendor/bin/phpcbf",
6464
"check-license": "vendor/bin/license-checker check",
6565
"analyze": "vendor/bin/phpstan analyze",
66+
"analyze-stubs": "vendor/bin/phpstan analyze -c phpstan-stubs.neon",
67+
"lint": "./bin/ci_php_lint",
6668
"test": "vendor/bin/phpunit",
6769
"coverage": "vendor/bin/phpunit --coverage-clover clover.xml"
6870
},

‎phpstan-stubs.neon‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
level: 0
3+
# The stubs below src/Magento shadow real Magento classes and are require()d
4+
# by the MockAutoloader inside the process running PHPStan. They therefore
5+
# have to be valid on every PHP version composer.json claims to support.
6+
phpVersion:
7+
min: 70200
8+
max: 80500
9+
fileExtensions:
10+
- php
11+
paths:
12+
- src/Magento
13+
ignoreErrors:
14+
# The stubs deliberately declare signatures without a body.
15+
-
16+
identifier: return.missing
17+
-
18+
identifier: constructor.missingParentCall
19+
# The stubs reference classes from Magento modules that are not pulled
20+
# in by require-dev; only magento/framework is.
21+
-
22+
identifier: class.notFound

‎src/Magento/Framework/Escaper.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Escaper
1414
* @param string[]|null $allowedTags
1515
* @return ($data is array ? string[] : string)
1616
*/
17-
public function escapeHtml($data, array|null $allowedTags = null) {}
17+
public function escapeHtml($data, ?array $allowedTags = null) {}
1818

1919
/**
2020
* @param CastableToString $string

0 commit comments

Comments
 (0)