Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ on:
- "master"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Both ends of the composer.json "php" constraint: the lowest version
# of each supported range, plus the newest release.
php-versions: ['7.4', '8.1', '8.5']
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none

- name: Lint sources
run: ./bin/ci_php_lint

run:
runs-on: ${{ matrix.operating-system }}
strategy:
Expand Down Expand Up @@ -56,6 +77,9 @@ jobs:
- name: Static code analysis
run: composer analyze

- name: Static code analysis of the Magento stubs
run: composer analyze-stubs

- name: Unittests
if: matrix.coveralls == false
run: composer test
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

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

## Unreleased

### Added

- [#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.

### Deprecated

- Nothing.

### Removed

- [#359](https://github.com/bitExpert/phpstan-magento/pull/359) Drop PHP 7.2 and 7.3 from the composer.json constraint. They could not install the package anyway since 0.43.0 requires phpstan/phpstan ^2.0, which needs PHP 7.4.

### Fixed

- [#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.

## 0.43.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can use this PHPStan extension for both Magento module projects and Magento

## Requirements

PHP: PHP 7.2 or higher
PHP: PHP 7.4 or higher

Magento: Magento 2.3.0 or higher

Expand Down
33 changes: 33 additions & 0 deletions bin/ci_php_lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

#
# This file is part of the phpstan-magento package.
#
# (c) bitExpert AG
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#

# Lints every shipped source file with the PHP binary found on the PATH. Run it
# on the lowest PHP version composer.json supports: the stubs below src/Magento
# are require()d by the MockAutoloader inside the process running PHPStan, so a
# parse error there aborts the analysis of any project using this package.

set -uo pipefail

cd "$(dirname "$0")/.."

status=0
while IFS= read -r -d '' file; do
if ! output="$(php -l "$file" 2>&1)"; then
echo "$output"
status=1
fi
done < <(find src -name '*.php' -print0)

if [ "$status" -eq 0 ]; then
echo "No syntax errors detected in src/ on PHP $(php -r 'echo PHP_VERSION;')."
fi

exit $status
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": "^7.2.0 || ^8.1.0",
"php": "^7.4.0 || ^8.1.0",
"ext-dom": "*",
"laminas/laminas-code": "~3.3.0 || ~3.4.1 || ~3.5.1 || ^4.5 || ^4.10",
"phpstan/phpstan": "^2.0",
Expand Down Expand Up @@ -63,6 +63,8 @@
"cs-fix": "vendor/bin/phpcbf",
"check-license": "vendor/bin/license-checker check",
"analyze": "vendor/bin/phpstan analyze",
"analyze-stubs": "vendor/bin/phpstan analyze -c phpstan-stubs.neon",
"lint": "./bin/ci_php_lint",
"test": "vendor/bin/phpunit",
"coverage": "vendor/bin/phpunit --coverage-clover clover.xml"
},
Expand Down
22 changes: 22 additions & 0 deletions phpstan-stubs.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
parameters:
level: 0
# The stubs below src/Magento shadow real Magento classes and are require()d
# by the MockAutoloader inside the process running PHPStan. They therefore
# have to be valid on every PHP version composer.json claims to support.
phpVersion:
min: 70400
max: 80500
fileExtensions:
- php
paths:
- src/Magento
ignoreErrors:
# The stubs deliberately declare signatures without a body.
-
identifier: return.missing
-
identifier: constructor.missingParentCall
# The stubs reference classes from Magento modules that are not pulled
# in by require-dev; only magento/framework is.
-
identifier: class.notFound
2 changes: 1 addition & 1 deletion src/Magento/Framework/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Escaper
* @param string[]|null $allowedTags
* @return ($data is array ? string[] : string)
*/
public function escapeHtml($data, array|null $allowedTags = null) {}
public function escapeHtml($data, ?array $allowedTags = null) {}

/**
* @param CastableToString $string
Expand Down
Loading