Skip to content

Commit 46fcba9

Browse files
Dynamically determine maximum level in PHPStan baseline generator
The generate-baselines.sh script now automatically reads the maximum level from phpstan.neon or phpstan.neon.dist instead of using a hardcoded value. Additionally, the script was updated to use indexed arrays for compatibility with Bash 3.2 (macOS default), and the README was updated to reflect these changes and fix minor typos. Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 6eb24f9 commit 46fcba9

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

tests/phpstan/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Sometimes, due to the lack of type information in legacy code, PHPStan may still
8989
9090
The `generate-baselines.sh` script is a helper tool to generate per-level baseline files for triaging PHPStan errors. It iterates through the specified levels, generates a baseline for each level, and outputs a summary of the results.
9191

92-
The process relies on iteration, and assumes that the baseline for the previous level has been freshly generated to capture any new/remediated errors on that level before generating the next level's baseline.
92+
The process relies on iteration, and assumes that the baseline for the previous level has been freshly generated to capture any new/remediated errors on that level before generating the next level's baseline. The maximum level is automatically determined from the `level` parameter in `phpstan.neon` (or `phpstan.neon.dist`).
9393

9494
### Usage
9595

@@ -98,8 +98,7 @@ To run the script, use the following command:
9898
```bash
9999
bash tests/phpstan/generate-baselines.sh --all # to generate baselines for all levels
100100
bash tests/phpstan/generate-baselines.sh --start=1 --end=3 # to generate baselines for levels 1 to 3
101-
bash tests/phpstan/generate-baselines.sh --level=6 # to generate a baseline for level 2 only. ASSUMES that the baseline for level 1 has been freshly generated.
101+
bash tests/phpstan/generate-baselines.sh --level=6 # to generate a baseline for level 6 only. ASSUMES that the baseline for the previous level has been freshly generated.
102102
bash tests/phpstan/generate-baselines.sh --summary-only # to only output the summary of results for the existing baselines, without regenerating them.
103103

104104
```
105-
To change the max level, update the `MAX_LEVEL` variable at the top of the script, alongside any changes to the root `phpstan.neon.dist` file to add the new level.

tests/phpstan/generate-baselines.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
# generate-baselines.sh
33
# Generate PHPStan baseline files for each level
44

5-
set -e
5+
# Determine MAX_LEVEL from configuration files
6+
MAX_LEVEL=""
7+
if [[ -f "phpstan.neon" ]]; then
8+
MAX_LEVEL=$(sed -n 's/^[[:space:]]*level:[[:space:]]*\([0-9]\+\)/\1/p' "phpstan.neon" | head -n 1)
9+
fi
10+
11+
if [[ -z "$MAX_LEVEL" ]] && [[ -f "phpstan.neon.dist" ]]; then
12+
MAX_LEVEL=$(sed -n 's/^[[:space:]]*level:[[:space:]]*\([0-9]\+\)/\1/p' "phpstan.neon.dist" | head -n 1)
13+
fi
614

7-
MAX_LEVEL=6 # Change this when adding new levels
15+
MAX_LEVEL=${MAX_LEVEL:-0}
16+
17+
if (( MAX_LEVEL == 0 )); then
18+
echo "Notice: Maximum level is 0. No per-level baselines to generate for levels 1 and above."
19+
exit 0
20+
fi
821

922
LEVEL_START=""
1023
LEVEL_END=""
11-
declare -A BEFORE_COUNTS
12-
declare -A AFTER_COUNTS
24+
declare -a BEFORE_COUNTS
25+
declare -a AFTER_COUNTS
1326

1427
usage() {
1528
cat <<EOF

0 commit comments

Comments
 (0)