Skip to content

Commit 9905581

Browse files
committed
merge PR #7: GitHub workflow for PHPStan
2 parents 635d95d + ddb4226 commit 9905581

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: composer
5+
directory: /
6+
schedule:
7+
interval: daily
8+
open-pull-requests-limit: 0

.github/workflows/phpstan.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Run a PHPStan check using the configuration in "/etc/phpstan/".
3+
# If the most recent commit message contains "[skip phpstan]" this workflow is skipped.
4+
#
5+
name: PHPStan
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
12+
pull_request:
13+
branches:
14+
- master
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
phpstan:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # fetch all branches and history (to access the source branch of PRs)
28+
29+
# ------------------------------------------------------------------------------------------------------------------------------------
30+
- name: Validate "composer.json"
31+
run: |
32+
composer validate --strict
33+
34+
# ------------------------------------------------------------------------------------------------------------------------------------
35+
- name: Check commit message for "[skip phpstan]"
36+
run: |
37+
SKIP_PHPSTAN=false
38+
REF_NAME=
39+
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then REF_NAME="$GITHUB_REF_NAME"
40+
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then REF_NAME="$GITHUB_HEAD_REF"
41+
else
42+
echo "unsupported event: $GITHUB_EVENT_NAME"
43+
exit 1
44+
fi
45+
COMMIT_MSG=$(git log -1 --format="%B" "origin/$REF_NAME")
46+
MAGIC_KEY=$(echo "$COMMIT_MSG" | (grep -io "\[skip phpstan\]" || true) | tail -1)
47+
48+
if [[ -n "$MAGIC_KEY" ]]; then
49+
echo "Magic commit message found: $MAGIC_KEY"
50+
SKIP_PHPSTAN=true
51+
fi
52+
echo "SKIP_PHPSTAN: $SKIP_PHPSTAN"
53+
echo "SKIP_PHPSTAN=$SKIP_PHPSTAN" >> "$GITHUB_ENV"
54+
55+
# ------------------------------------------------------------------------------------------------------------------------------------
56+
- name: Run PHPStan
57+
if: env.SKIP_PHPSTAN != 'true'
58+
run: |
59+
echo "Installing Composer dependencies..."
60+
composer install --no-progress
61+
62+
echo "Generating PHPStan report..."
63+
bin/phpstan --no-progress -vvv
64+
65+
# ------------------------------------------------------------------------------------------------------------------------------------

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rosasurfer/ministruts",
33
"description": "MVC micro framework inspired by Java Struts",
44
"type": "library",
5-
"license": "WTFPL",
5+
"license": "Unlicense",
66
"authors": [{
77
"name": "Peter Walther",
88
"email": "[email protected]"

etc/phpstan/extension/CoreFunctionReturnType.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct() {
3737
$this->supportedFunctions = [
3838
// function type to remove original return type
3939
// -------------------------------------------------------------------------
40-
'curl_init' => $bool, // resource|CurlHandle|false (2) @see https://www.php.net/manual/en/function.curl-init.php
40+
'curl_init' => $bool, // resource|CurlHandle|false @see https://www.php.net/manual/en/function.curl-init.php
4141
'file' => $bool, // array|false
4242
'file_get_contents' => $bool, // string|false @see https://www.php.net/manual/en/function.file-get-contents.php
4343
'filemtime' => $bool, // int|false @see https://www.php.net/manual/en/function.filemtime.php
@@ -57,7 +57,7 @@ public function __construct() {
5757
'stream_get_contents' => $bool, // string|false @see https://www.php.net/manual/en/function.stream-get-contents.php
5858

5959
// (1) either PHPStan or the PHP documentation is wrong
60-
// (2) with PHPStan v1.11.10 the extension is not called
60+
// (2) the extension is not called by PHPStan
6161
];
6262
}
6363

@@ -104,8 +104,9 @@ protected function getOriginalTypeFromFunctionCall(FunctionReflection $function,
104104
public function getTypeFromFunctionCall(FunctionReflection $function, FuncCall $functionCall, Scope $scope): Type {
105105
$name = $function->getName();
106106

107-
if (in_array($name, ['curl_init', 'preg_replace'])) {
108-
throw new ExtensionException("function $name was passed to ".simpleClassName(__CLASS__).' extension');
107+
if (in_array($name, ['preg_replace'])) {
108+
// throw an exception to get notified when PHPStan bugs get fixed
109+
throw new ExtensionException("pewa: PHPStan bugfix -> core function $name is now passed to the ".simpleClassName(__CLASS__).' extension');
109110
}
110111

111112
$origType = $this->getOriginalTypeFromFunctionCall($function, $functionCall, $scope);

0 commit comments

Comments
 (0)