From 973fc3218a9998d0190e42feda772dd0ee2e5832 Mon Sep 17 00:00:00 2001 From: bidi Date: Fri, 4 Dec 2026 16:59:19 +0200 Subject: [PATCH 1/3] code refactor, updated composer, tests Signed-off-by: bidi --- .claude/hooks/guard-bash.sh | 246 ++++++ .claude/hooks/guard-protected-paths.sh | 57 ++ .claude/hooks/markdown-lint.sh | 49 ++ .claude/hooks/normalize-file.sh | 91 ++ .claude/hooks/php-lint.sh | 35 + .claude/hooks/session-start.sh | 89 ++ .claude/plan-code-review.md | 786 ++++++++++++++++++ .claude/skills/plan-major-upgrade/SKILL.md | 102 +++ .github/workflows/codecov.yml | 1 + .github/workflows/qodana_code_quality.yml | 2 +- .github/workflows/static-analysis.yml | 3 +- CHANGELOG.md | 112 +++ README.md | 8 +- composer.json | 37 +- config/autoload/error-handling.global.php | 103 ++- config/autoload/local.php.dist | 6 - phpunit.xml | 7 +- src/App/src/ConfigProvider.php | 2 +- src/Page/src/ConfigProvider.php | 24 +- src/Page/src/Handler/GetPageViewHandler.php | 9 +- test/Unit/App/ConfigProviderTest.php | 2 +- .../GetIndexViewHandlerFactoryTest.php | 29 + .../App/Handler/GetIndexViewHandlerTest.php | 28 + test/Unit/App/RoutesDelegatorTest.php | 32 + test/Unit/Fixture/InMemoryContainer.php | 37 + .../Unit/Fixture/ServiceNotFoundException.php | 18 + test/Unit/Page/ConfigProviderTest.php | 15 +- .../Factory/GetPageViewHandlerFactoryTest.php | 35 + .../Page/Handler/GetPageViewHandlerTest.php | 57 ++ test/Unit/Page/Handler/PageHandlerTest.php | 57 -- test/Unit/Page/RoutesDelegatorTest.php | 55 +- 31 files changed, 1957 insertions(+), 177 deletions(-) create mode 100644 .claude/hooks/guard-bash.sh create mode 100644 .claude/hooks/guard-protected-paths.sh create mode 100644 .claude/hooks/markdown-lint.sh create mode 100644 .claude/hooks/normalize-file.sh create mode 100644 .claude/hooks/php-lint.sh create mode 100644 .claude/hooks/session-start.sh create mode 100644 .claude/plan-code-review.md create mode 100644 .claude/skills/plan-major-upgrade/SKILL.md create mode 100644 test/Unit/App/Factory/GetIndexViewHandlerFactoryTest.php create mode 100644 test/Unit/App/Handler/GetIndexViewHandlerTest.php create mode 100644 test/Unit/App/RoutesDelegatorTest.php create mode 100644 test/Unit/Fixture/InMemoryContainer.php create mode 100644 test/Unit/Fixture/ServiceNotFoundException.php create mode 100644 test/Unit/Page/Factory/GetPageViewHandlerFactoryTest.php create mode 100644 test/Unit/Page/Handler/GetPageViewHandlerTest.php delete mode 100644 test/Unit/Page/Handler/PageHandlerTest.php diff --git a/.claude/hooks/guard-bash.sh b/.claude/hooks/guard-bash.sh new file mode 100644 index 0000000..e84159b --- /dev/null +++ b/.claude/hooks/guard-bash.sh @@ -0,0 +1,246 @@ +#!/usr/bin/env bash +# PreToolUse guard for Bash commands in Dotkernel projects. +# Catches installs and destructive git even when hidden inside compound commands +# ("cd x && composer require y"), which path-based permission rules cannot see. +# Quoted arguments, comments and heredoc bodies are data and are not matched, so +# grep "rm -rf" docs/ is allowed. Quoted code is still checked: the script after a -c +# option (sh -c "..."), the arguments of eval, ssh and watch, and a heredoc or +# here-string fed to a shell. +# This matches text, not a parsed shell: an unusual spelling can still get past it. +# bash, sed and awk; jq is used for the payload when installed. +# Exit 0 = allow, exit 2 = block. + +set -u +export LC_ALL=C + +payload=$(cat) + +# Print tool_input.command with its JSON escapes decoded. +extract_command() { + if command -v jq >/dev/null 2>&1 \ + && printf '%s' "$payload" | jq -r '.tool_input.command // empty' 2>/dev/null; then + return + fi + # No jq: park the two escapes that can hide a quote (\\ and \") on control bytes, + # which valid JSON never contains raw, so [^"]* ends exactly at the closing quote. + local bs='\' sl='/' esc_bs=$'\002' esc_q=$'\001' s + s=$(printf '%s' "$payload" | tr -d '\n' | sed -n \ + -e 's/\\\\/'"$esc_bs"'/g' \ + -e 's/\\"/'"$esc_q"'/g' \ + -e 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') + s=${s//"${bs}n"/$'\n'} + s=${s//"${bs}t"/$'\t'} + s=${s//"${bs}r"/$'\r'} + s=${s//"$bs$sl"/$sl} + s=${s//"$esc_q"/\"} + s=${s//"$esc_bs"/$bs} + printf '%s' "$s" +} + +cmd=$(extract_command) +[ -z "$cmd" ] && exit 0 + +# Reduce the command to the text that would run. Quoted strings, comments and heredoc +# bodies become the placeholder Q, and ; & | ( ) ` and newlines become separate words. +# Code inside quotes or a heredoc (the script after a -c option, the arguments of eval, +# ssh or watch, a heredoc or here-string fed to a shell) is reduced the same way and +# appended after a " ; ". An unterminated quote leaves the rest of the command unmasked. +IFS= read -r -d '' SHELL_VIEW <<'AWK' || true +{ src = (NR == 1) ? $0 : src "\n" $0 } +END { printf "%s", scan(src, 0) } + +# out: the reduced command; seg0: where the current simple command starts in out; +# ws: the next character starts a word (so # opens a comment). +function scan(s, depth, n, i, c, j, out, seg0, ws, extra, body, q, seg, code, strip, + d, nd, hd, hs, hf, h, lines, nl, ln, pos, found, cmp, start) { + n = length(s); i = 1; out = ""; seg0 = 1; ws = 1; extra = ""; nd = 0 + while (i <= n) { + if (match(substr(s, i, 512), /^[^\\'"$#<;&|()`\n]+/)) { # ordinary text, in runs + out = out substr(s, i, RLENGTH); i += RLENGTH + ws = (substr(out, length(out), 1) ~ /[ \t]/); continue + } + c = substr(s, i, 1) + + if (c == "\\") { # escaped character, or line continuation + if (substr(s, i + 1, 1) != "\n") { out = out substr(s, i + 1, 1); ws = 0 } + i += 2; continue + } + + if (c == "'" || c == "\"" || (c == "$" && substr(s, i + 1, 1) == "'")) { + q = c; j = i + 1 + if (c == "$") { q = "'"; j = i + 2 } + if (c == "'") { + j = index(substr(s, j), "'"); if (j) j += i + } else { # "..." and $'...' honour backslash escapes + while (j <= n && substr(s, j, 1) != q) j += (substr(s, j, 1) == "\\") ? 2 : 1 + if (j > n) j = 0 + } + if (!j) { out = out substr(s, i); break } + body = substr(s, i + 1, j - i - 1) + seg = substr(out, seg0); code = 0 + if (seg ~ /(^|[ \t])-[a-z]*c[ \t]*$/ || seg ~ /(^|[ \t\/])(eval|ssh|watch)[ \t]/) code = 1 + else if (sub(/<<<[ \t]*$/, "", seg)) code = feeds_shell(seg) + if (code && c != "$") extra = extra " ; " nested((c == "\"") ? undq(body) : body, depth) + out = out "Q"; i = j + 1; ws = 0; continue + } + + if (c == "#" && ws) { # comment, up to the end of the line + j = index(substr(s, i), "\n") + if (!j) break + i += j - 1; continue + } + + if (c == "<" && substr(s, i, 3) == "<<<") { out = out "<<<"; i += 3; ws = 1; continue } + if (c == "<" && substr(s, i, 2) == "<<") { # heredoc + j = i + 2; strip = 0 + if (substr(s, j, 1) == "-") { strip = 1; j++ } + while (substr(s, j, 1) == " " || substr(s, j, 1) == "\t") j++ + d = ""; q = substr(s, j, 1) + if (q == "'" || q == "\"") { + c = index(substr(s, j + 1), q) + if (c) { d = substr(s, j + 1, c - 1); j += c + 1 } + } else { + while (j <= n && substr(s, j, 1) !~ /[ \t\n;&|()<>'"]/) { + if (substr(s, j, 1) == "\\") j++ + d = d substr(s, j, 1); j++ + } + } + if (d == "") { out = out "<<"; i += 2; ws = 1; continue } + nd++; hd[nd] = d; hs[nd] = strip; hf[nd] = feeds_shell(substr(out, seg0)) + out = out " << Q "; i = j; ws = 0; continue + } + + if (c == "\n") { + out = out " ; "; seg0 = length(out) + 1; ws = 1; i++ + if (nd) { # bodies of the heredocs opened on that line + nl = split(substr(s, i), lines, "\n"); ln = 1; pos = i + for (h = 1; h <= nd; h++) { + start = pos; found = 0 + for (; ln <= nl; ln++) { + cmp = lines[ln] + if (hs[h]) sub(/^\t+/, "", cmp) + if (cmp == hd[h]) { found = 1; break } + pos += length(lines[ln]) + 1 + } + if (!found) { pos = start; break } # no terminator: scan it as commands + if (hf[h]) extra = extra " ; " nested(substr(s, start, pos - start), depth) + pos += length(lines[ln]) + 1; ln++ + } + i = pos; nd = 0 + } + continue + } + + if (index(";&|()`", c)) { out = out " " c " "; seg0 = length(out) + 1; ws = 1; i++; continue } + out = out c; ws = 0; i++ + } + return out extra +} + +# The command so far ends with a shell that reads its script from stdin. +function feeds_shell(seg) { return seg ~ /(^|[ \t\/])(ba|z|da|k|a)?sh([ \t]+-[a-z]+)*[ \t]*$/ } + +function nested(s, depth) { return (depth < 4) ? scan(s, depth + 1) : s } + +function undq(s, r, i, n, c, nx) { # remove the escapes "..." honours + r = ""; n = length(s) + for (i = 1; i <= n; i++) { + c = substr(s, i, 1) + if (c == "\\" && i < n) { + nx = substr(s, i + 1, 1) + if (nx == "\n") { i++; continue } + if (index("\"\\$`", nx)) { r = r nx; i++; continue } + } + r = r c + } + return r +} +AWK + +lc=$(printf '%s' "$cmd" | tr '[:upper:]' '[:lower:]') +view=$(printf '%s' "$lc" | awk "$SHELL_VIEW") || view=$lc +norm=$(printf '%s' "$view" | tr '\t\r\n' ' ' | tr -s ' ') + +block() { + local shown=$cmd + [ ${#shown} -gt 500 ] && shown="${shown:0:500}..." + printf 'BLOCKED command: %s\n%s\n' "$shown" "$1" >&2 + exit 2 +} + +set -f +# shellcheck disable=SC2206 # word splitting is the point; globbing is off +words=($norm) +set +f +nw=${#words[@]} + +# composer [options] [global] . Composer resolves any unambiguous prefix of a +# command name (req, upd, inst, rem) and the aliases r, i, u, upgrade, rm, uninstall. +for ((i = 0; i < nw; i++)); do + case ${words[i]} in + composer|composer.phar|*/composer|*/composer.phar) ;; + *) continue ;; + esac + j=$((i + 1)) + while ((j < nw)); do + case ${words[j]} in + -d|--working-dir) j=$((j + 2)) ;; + -*) j=$((j + 1)) ;; + *) [[ global == "${words[j]}"* ]] && j=$((j + 1)) || break ;; + esac + done + sub=${words[j]:-} + [[ $sub =~ ^[a-z]+$ ]] || continue + for name in require remove update upgrade install uninstall rm; do + [[ $name == "$sub"* ]] \ + && block "Dependency changes need my explicit approval. Tell me the package and why, and I will run it." + done +done + +case " $norm " in + *"npm install"*|*"npm i "*|*"npm uninstall"*|*"npm update"*|*"npm ci"*|\ + *"yarn add"*|*"yarn remove"*|*"pnpm add"*|*"pnpm remove"*|*"pip install"*) + block "Package installs need my explicit approval." ;; +esac + +case " $norm " in + *"git push"*|*"git reset --hard"*|*"git clean -"*|*"git checkout -- "*|\ + *"git submodule"*|*"git filter-branch"*|*"git rebase"*) + block "Destructive or publishing git operations are mine to run." ;; +esac + +# rm with both a recursive and a force flag, in any spelling: -rf, -fr, -r -f, -Rf, +# --recursive --force. Its arguments end at a separator, at -- and at find's "{} +". +for ((i = 0; i < nw; i++)); do + case ${words[i]} in rm|*/rm) ;; *) continue ;; esac + rec=0 force=0 + for ((j = i + 1; j < nw; j++)); do + w=${words[j]} + case $w in + ';'|'&'|'|'|'('|')'|'`'|--|+) break ;; + --?*) [[ recursive == "${w#--}"* ]] && rec=1 + [[ force == "${w#--}"* ]] && force=1 ;; + -?*) [[ $w == *r* ]] && rec=1 + [[ $w == *f* ]] && force=1 ;; + esac + done + ((rec && force)) && block "Refusing destructive filesystem command." +done + +case " $norm " in + *"mkfs"*|*"chmod -r 777"*) + block "Refusing destructive filesystem command." ;; +esac + +case " $norm " in + *"doctrine-migrations migrate"*|*"doctrine-migrations execute"*|\ + *"fixtures:execute"*|*"schema:drop"*|*"schema:update"*) + block "Database-mutating commands need my approval. Show me the command and what it will change." ;; +esac + +case " $norm " in + *"development-enable"*|*"development-disable"*) + block "Toggling development mode changes committed config state. Ask me first." ;; +esac + +exit 0 diff --git a/.claude/hooks/guard-protected-paths.sh b/.claude/hooks/guard-protected-paths.sh new file mode 100644 index 0000000..6dcb4fa --- /dev/null +++ b/.claude/hooks/guard-protected-paths.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# PreToolUse guard for Dotkernel projects. +# Blocks writes to vendored, generated, secret or dependency-manifest files. +# Pure bash, no jq — works in Git Bash on Windows. +# Exit 0 = allow, exit 2 = block (stderr is shown to Claude). + +set -u + +payload=$(cat) + +# Pull the target path out of tool_input without a JSON parser: "file_path" for +# Edit, Write and MultiEdit, "notebook_path" for NotebookEdit. +path_field() { + printf '%s' "$payload" \ + | tr -d '\n' \ + | sed -n 's/.*"'"$1"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' +} +raw_path=$(path_field file_path) +[ -z "$raw_path" ] && raw_path=$(path_field notebook_path) + +[ -z "$raw_path" ] && exit 0 + +# Normalise: unescape JSON backslashes, turn \ into /, drop a drive prefix, lowercase. +path=${raw_path//\\\\/\\} +path=${path//\\//} +path=${path#[A-Za-z]:} +lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') + +block() { + printf 'BLOCKED: %s\n%s\n' "$raw_path" "$1" >&2 + exit 2 +} + +case "$lower" in + */vendor/*|vendor/*) + block "vendor/ is Composer-managed. Change the dependency or your own code instead." ;; + */node_modules/*|node_modules/*) + block "node_modules/ is npm-managed." ;; + */migration/*|*/migrations/*) + block "Migrations are generated. Adjust the entity and regenerate with 'doctrine-migrations diff'." ;; + */data/cache/*|*/data/lock/*|*/data/oauth/*|data/cache/*|data/lock/*|data/oauth/*) + block "data/ holds generated cache, locks and keys. Never hand-edit." ;; + */log/*|log/*) + block "log/ is runtime output." ;; + */public/uploads/*|public/uploads/*) + block "public/uploads/ is user-uploaded content." ;; + *composer.json|*composer.lock|*package.json|*package-lock.json|*yarn.lock|*pnpm-lock.yaml) + block "Dependency manifests require explicit user approval. Propose the change in chat first." ;; + *.local.php|*/local.php|local.php|*/local.test.php|local.test.php) + block "Local config holds environment secrets and is git-ignored. Edit the .dist template and let the user apply it." ;; + *.phpcs-cache|*.phpunit.result.cache|*/.git/*) + block "Tool cache / git internals." ;; + *.png|*.jpg|*.jpeg|*.gif|*.svg|*.ico|*.zip|*.phar|*.key|*.pem) + block "Binary or key material." ;; +esac + +exit 0 diff --git a/.claude/hooks/markdown-lint.sh b/.claude/hooks/markdown-lint.sh new file mode 100644 index 0000000..84f3c8c --- /dev/null +++ b/.claude/hooks/markdown-lint.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# PostToolUse: markdownlint a .md file right after it is written. +# Report-only by design — it does NOT run --fix. Reformatting a file that Claude +# just wrote invalidates its in-memory copy and breaks the next targeted edit, +# so bulk fixing stays a deliberate end-of-task action. +# Exit 2 surfaces the violations to Claude immediately. +# Silent exit 0 when markdownlint-cli2 is not installed, so .claude/ stays +# drop-in with no npm requirement. + +set -u + +payload=$(cat) + +raw_path=$(printf '%s' "$payload" | tr -d '\n' \ + | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') + +[ -z "$raw_path" ] && exit 0 + +path=${raw_path//\\\\/\\} +path=${path//\\//} + +lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') + +case "$lower" in + *.md|*.markdown) ;; + *) exit 0 ;; +esac +case "$lower" in + */vendor/*|*/node_modules/*|*/.git/*|*/data/*|*/log/*) exit 0 ;; +esac +[ -f "$path" ] || exit 0 + +config="${CLAUDE_PROJECT_DIR:-.}/.claude/markdownlint.jsonc" +[ -f "$config" ] || exit 0 + +bin="" +if [ -x ./node_modules/.bin/markdownlint-cli2 ]; then + bin=./node_modules/.bin/markdownlint-cli2 +elif command -v markdownlint-cli2 >/dev/null 2>&1; then + bin=markdownlint-cli2 +fi +[ -z "$bin" ] && exit 0 + +if ! output=$("$bin" --config "$config" "$path" 2>&1); then + printf 'markdownlint violations in %s\n%s\n' "$path" "$output" >&2 + exit 2 +fi + +exit 0 diff --git a/.claude/hooks/normalize-file.sh b/.claude/hooks/normalize-file.sh new file mode 100644 index 0000000..e436548 --- /dev/null +++ b/.claude/hooks/normalize-file.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +# PostToolUse normaliser for Dotkernel projects. +# Enforces: UTF-8 without BOM, LF line endings, no trailing whitespace, +# exactly one trailing newline. Pure bash + sed + awk, no jq. +# Rewrites the file in place, so its permissions, owner and links survive. +# Exit 0 always — this fixes silently rather than blocking. + +set -u + +payload=$(cat) + +raw_path=$(printf '%s' "$payload" | tr -d '\n' \ + | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') + +[ -z "$raw_path" ] && exit 0 + +path=${raw_path//\\\\/\\} +path=${path//\\//} + +[ -f "$path" ] || exit 0 + +lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') + +# Skip binaries and anything not ours. +case "$lower" in + *.png|*.jpg|*.jpeg|*.gif|*.ico|*.svg|*.zip|*.phar|*.pdf|*.woff|*.woff2|*.ttf|*.eot|*.key|*.pem) + exit 0 ;; + */vendor/*|*/node_modules/*|*/.git/*|*/data/*|*/log/*) + exit 0 ;; +esac + +# Text files only. +case "$lower" in + *.php|*.phtml|*.twig|*.md|*.json|*.xml|*.neon|*.yml|*.yaml|*.sh|*.txt|*.dist|*.html|*.css|*.js|*.sql|*.editorconfig|*.gitattributes|*.gitignore) ;; + *) exit 0 ;; +esac + +changed="" +tmp=$(mktemp "${TMPDIR:-/tmp}/dk-normalize.XXXXXX") || exit 0 +trap 'rm -f "$tmp"' EXIT + +# Copy the fixed text back over the original. Writing through the existing file, rather +# than moving a new one into place, keeps its mode (an executable script stays +# executable), its owner, and any symlink or hard link to it. +write_back() { { cat "$tmp" > "$path"; } 2>/dev/null; } + +# 1. Strip UTF-8 BOM. +bom=$(printf '\357\273\277') +if [ "$(head -c 3 "$path" 2>/dev/null)" = "$bom" ]; then + tail -c +4 "$path" > "$tmp" && write_back && changed="${changed} BOM-removed" +fi + +# 2. CRLF -> LF, then a lone CR (classic Mac line ending) -> LF. +if LC_ALL=C grep -qU $'\r' "$path" 2>/dev/null; then + LC_ALL=C sed $'s/\r$//' "$path" | tr '\r' '\n' > "$tmp" && write_back \ + && changed="${changed} CRLF->LF" +fi + +# 3. Trailing whitespace (skip markdown: two trailing spaces are a hard line break). +case "$lower" in + *.md) ;; + *) + if LC_ALL=C grep -q '[[:space:]]$' "$path"; then + sed 's/[[:space:]]*$//' "$path" > "$tmp" && write_back \ + && changed="${changed} trailing-ws-stripped" + fi + ;; +esac + +# 4. Exactly one trailing newline: add a missing one, drop blank or whitespace-only lines +# at the end. A file with nothing but whitespace is left alone. +if [ -s "$path" ]; then + LC_ALL=C awk ' + /^[ \t\f\v]*$/ { held = held $0 "\n"; next } # blank: hold until a line follows + { printf "%s%s\n", held, $0; held = "" } # still held at the end: dropped + ' "$path" > "$tmp" + if [ -s "$tmp" ] && ! cmp -s "$tmp" "$path"; then + if [ "$(wc -c < "$tmp")" -gt "$(wc -c < "$path")" ]; then + fix=newline-added + else + fix=trailing-blank-lines-removed + fi + write_back && changed="${changed} ${fix}" + fi +fi + +if [ -n "$changed" ]; then + printf 'File hygiene applied to %s:%s\n' "$path" "$changed" >&2 +fi + +exit 0 diff --git a/.claude/hooks/php-lint.sh b/.claude/hooks/php-lint.sh new file mode 100644 index 0000000..d902a12 --- /dev/null +++ b/.claude/hooks/php-lint.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# PostToolUse: syntax-check a PHP file right after it is written. +# Report-only by design — it does NOT reformat. Reformatting a file that Claude +# just wrote invalidates its in-memory copy and breaks the next targeted edit, +# so phpcbf is deliberately left to `composer cs-fix` / /dk-check at the end. +# Exit 2 surfaces the parse error to Claude immediately. + +set -u + +payload=$(cat) + +raw_path=$(printf '%s' "$payload" | tr -d '\n' \ + | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') + +[ -z "$raw_path" ] && exit 0 + +path=${raw_path//\\\\/\\} +path=${path//\\//} + +case "$path" in + *.php) ;; + *) exit 0 ;; +esac +case "$path" in + */vendor/*|*/node_modules/*) exit 0 ;; +esac +[ -f "$path" ] || exit 0 +command -v php >/dev/null 2>&1 || exit 0 + +if ! output=$(php -l "$path" 2>&1); then + printf 'PHP syntax error in %s\n%s\n' "$path" "$output" >&2 + exit 2 +fi + +exit 0 diff --git a/.claude/hooks/session-start.sh b/.claude/hooks/session-start.sh new file mode 100644 index 0000000..fbcf056 --- /dev/null +++ b/.claude/hooks/session-start.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# SessionStart: print a short briefing that becomes part of Claude's context. +# Detects which Dotkernel project this is and what is not set up yet. +# Everything here is read-only. Keep the output compact. + +set -u +cd "${CLAUDE_PROJECT_DIR:-.}" 2>/dev/null || exit 0 + +echo "## Project state" + +# --- which Dotkernel project? --- +if [ -f composer.json ]; then + pkg=$(sed -n 's/.*"name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' composer.json | head -1) + ns=$(grep '": "src/' composer.json 2>/dev/null | grep -v '"Core' | head -1 \ + | sed 's/^[^"]*"\([A-Za-z]*\).*/\1/') + variant="unknown" + case "$pkg" in + */api) variant="API (REST/HAL)" ;; + */admin) variant="Admin (templated, forms)" ;; + */frontend) variant="Frontend (templated, forms)" ;; + */light) variant="Light (minimal starter)" ;; + */queue) variant="Queue (CLI/worker)" ;; + esac + if [ "$variant" = "unknown" ]; then + hal=0 form=0 + grep -q 'mezzio/mezzio-hal' composer.json && hal=1 + grep -q 'laminas/laminas-form' composer.json && form=1 + case "$hal$form" in + 10) variant="API-style (has mezzio-hal)" ;; + 01) variant="templated-style (has laminas-form)" ;; + 11) variant="unclear (has mezzio-hal and laminas-form; infer the parent from the PSR-4 roots)" ;; + esac + fi + echo "- package: ${pkg:-unknown} | variant: ${variant}" + [ -n "$ns" ] && echo "- root namespace: ${ns}" + guards=config/autoload/authorization-guards.global.php + if [ -f "$guards" ]; then + policy=$(sed -n "s/.*protection_policy.*\(POLICY_[A-Z]*\).*/\1/p" "$guards" | head -1) + echo "- authorization: guards + RBAC (${guards##*/}${policy:+, $policy})" + [ "$policy" = POLICY_ALLOW ] && echo " unlisted routes are PUBLIC — every new route needs a guard rule" + elif [ -f config/autoload/authorization.global.php ]; then + echo "- authorization: RBAC (authorization.global.php) — unlisted routes are denied" + fi +fi + +# --- git --- +# Ask git rather than test for a .git directory: in a worktree or a submodule checkout +# .git is a file. +if command -v git >/dev/null 2>&1 \ + && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; then + eol_bad=$(git ls-files --eol 2>/dev/null | grep -c 'w/crlf' || true) + [ "${eol_bad:-0}" -gt 0 ] && echo "- WARNING: ${eol_bad} tracked file(s) have CRLF in the worktree; run /dk-hygiene" + top=$(git rev-parse --show-toplevel 2>/dev/null) + if [ -f "$top/.gitmodules" ]; then + subs=$(git config -f "$top/.gitmodules" --get-regexp '^submodule\..*\.path$' 2>/dev/null \ + | cut -d' ' -f2- | tr '\n' ' ') + subs=${subs% } + case " $subs " in + *" src/Core "*) echo "- git submodules: ${subs}. Core is one: commit inside src/Core, then bump the pointer here" ;; + " ") ;; + *) echo "- git submodules: ${subs}" ;; + esac + fi +fi + +# --- setup completeness --- +[ -f composer.json ] && [ ! -d vendor ] \ + && echo "- vendor/ missing — dependencies are not installed (run /dk-bootstrap)" + +for d in config/autoload/*.dist config/*.dist; do + [ -e "$d" ] || continue + target=${d%.dist} + [ -f "$target" ] && continue + case "$target" in + config/development.config.php) continue ;; # managed by development-mode, not copied by hand + esac + echo "- missing ${target} (copy from ${d})" +done + +for d in docs/features documentation/features; do + [ -d "$d" ] || continue + n=$(ls -1 "$d"/*.md 2>/dev/null | grep -vc '/README\.md$' || true) + echo "- ${d}/: ${n:-0} feature doc(s) — read the relevant one before adding behaviour there" +done + +[ -f config/development.config.php ] && echo "- development mode is ENABLED" +[ -f data/cache/config-cache.php ] && echo "- config cache present; clear it after config edits" + +exit 0 diff --git a/.claude/plan-code-review.md b/.claude/plan-code-review.md new file mode 100644 index 0000000..d77f964 --- /dev/null +++ b/.claude/plan-code-review.md @@ -0,0 +1,786 @@ +# Plan: dotkernel/light 1.6.0 + +This plan covers the next release of Dotkernel Light, a Mezzio skeleton application. The work branch is `upgrade`, and the base is branch `1.0` at commit `aaf20d1` (`git describe --tags`: `1.5.0-17-gaaf20d1`). The maintainer asked for 1.6.0 if the release has no backward-incompatible changes, and for 2.0.0 otherwise. After the second review, the target is 1.6.0. The plan was first written on 2026-12-04 and checked again on the same day with PHP 8.5.13. Implementation started on 2026-12-04. The status table shows the state of each item. + +## Implementation status + +| Item | State | Notes | +| --- | --- | --- | +| V1 `composer.json` requirements | Done by maintainer | Uncommitted. `dot-errorhandler` is now `^5.1.0 \|\| ^6.0.0` | +| V2 PHP 8.6 in the workflows | Done | Qodana matrix has 8.6. The PHPStan job id is `phpstan` | +| V3 PHPStan level 8 | Done | `composer static-analysis`: no errors | +| V4 PHPUnit major version | Decision: stay on 12 | PHPUnit 13 needs PHP `>=8.4.1` | +| V5 `phpunit.xml` flags | Done | `failOn*` flags added, `stopOnError` and `` removed | +| V6 Release line | No change | 1.6.0 is released from branch `1.0` | +| V7 Node.js 20 in the build matrix | Open, optional | Needs a check of the Node.js release schedule | +| V8 Debug lines in `public/index.php` | Done by maintainer | `git diff public/index.php` is empty | +| F1 Page handler without a matched route | Done | Two new tests | +| F2 Page routes only in `local.php` | Done | Without `local.php`, all three routes exist. With the old `local.php`, the site works | +| F3 Cookies written unmasked to the error log | Done | A forced error gives status 500 and `PHPSESSID=******` in the log | +| F4 Unused `PageService` | Decision: keep | No change | +| F5 Stale config cache after `composer update` | Done by maintainer | Verified: `composer update` deleted `data/cache/config-cache.php` | +| F6 Tests double final classes | Done | `PageHandlerTest.php` renamed to `GetPageViewHandlerTest.php` with `git mv` | +| F7 Factories use `assert()` | Open, waits for a decision | Not implemented | +| F8 Malformed docblocks in the config providers | Done | | +| F9 Outdated docs link in `error-handling.global.php` | Done | Link points to v6. Published URL not verified | +| F10 Test coverage gaps | Done | 20 tests, 57 assertions. Fixture container in `test/Unit/Fixture` | +| T20 Remove `laminas-servicemanager` | Not applicable | See [V9](#v9-laminas-servicemanager-is-a-runtime-requirement) | +| CHANGELOG | Done | 1.3.0, 1.4.0, 1.5.0 and 1.6.0 added. 1.6.0 date is `TBD` | +| README | Done | PHP 8.6, route location, automatic cache clearing | +| D1 to D11 documentation | Done | Branch `upgrade-1.6` in `light-documentation`. `mkdocs build` not run, because `mkdocs` is not installed | + +## Decision: version 1.6.0 + +Light is a skeleton. Users run `composer create-project` and then merge later upstream changes into their own project. A change is breaking when a project made from 1.5.0 must change its own code or config to take the change. + +The first version of this plan chose 2.0.0 for two reasons. Both reasons are now gone: + +1. The maintainer keeps `PageService` (F4). No class, config key, route or template of Light is removed. +2. The maintainer changed the range to `"dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0"`. A project that cannot take `dot-errorhandler` 6 yet can stay on 5.1 with the same Light release. The Light config works without changes on 6.0.0. The default config uses a boolean `loggerEnabled` and a PSR-3 logger (`Dot\Log\Logger` extends `AbstractLogger`). It does not subclass any `dot-errorhandler` class. + +The changes in this plan are additive or internal: + +- New direct requirements (`dot-log`, `laminas-diactoros`, `laminas-servicemanager`) were already installed through `dot-errorhandler` 5. +- PHP 8.6 is added. No PHP version is removed. +- F2 moves the page routes into `Light\Page\ConfigProvider`. The config aggregator merges the routes from an existing `local.php`, so they still work. +- F1 replaces a PHP `Error` with a `RuntimeException` for a request without a matched route. Such a request does not reach the handler in the default pipeline. + +The project has a precedent. Light 1.5.0 raised `dot-errorhandler` from 4 to 5 and removed PHP 8.2 in a minor release (`light-documentation`, `docs/book/v1/upgrading/UPGRADE-1.5.md`). + +Two risks remain. Write them in the upgrade page (D10): + +- `composer update` selects `dot-errorhandler` 6 by default. A project with its own error handler code must check the `dot-errorhandler` 6 upgrade guide, or pin `^5.1`. +- After F2, a project that removed a page route from its `local.php` gets the route back from `Light\Page\ConfigProvider`, if the project merges that file without review. + +Verified on 2026-12-04: the maintainer installed `dot-errorhandler` 5.1.0 for a test. With 5.1.0, the container builds `ErrorHandlerInterface` as `Dot\ErrorHandler\LogErrorHandler` with the `Dot\Log\Logger` service. `/` and `/page/about` return 200, and `/missing` returns 404. `composer static-analysis` and `composer test` show only the two known F6 errors, the same as with 6.0.0. A forced error with a written log line was not tested. + +## Baseline + +Commands were run on branch `upgrade` after the maintainer's `composer update`. + +| Check | Result | +| --- | --- | +| `php -v` | PHP 8.5.13. No other PHP version is installed (`/usr/bin/php` only) | +| `git describe --tags` | `1.5.0-17-gaaf20d1` | +| `composer cs-check` | Pass | +| `composer twig-cs-check` | Pass, 7 files | +| `composer static-analysis` | **Fail.** 2 errors, both `method.unresolvableReturnType` | +| `composer test` | **Fail.** `ClassIsFinalException` in `PageHandlerTest::testHandle`. `stopOnError="true"` hides the second error in `RoutesDelegatorTest::testWillInvoke` | +| `curl http://localhost:8080` | `/`, `/page/about` and `/page/who-we-are` return 200. `/missing` returns 404 | +| `data/cache/config-cache.php` | Deleted by the new `@clear-config-cache` script | +| Coverage driver | None. `php -m` shows no `pcov` and no `xdebug` | +| Mutation testing | Not installed | + +Installed versions that matter for this plan: `mezzio/mezzio` 3.29.0, `mezzio/mezzio-router` 4.3.0, `laminas/laminas-servicemanager` 4.6.0, `dotkernel/dot-errorhandler` 6.0.0, `dotkernel/dot-log` 5.4.0, `phpunit/phpunit` 12.5.47 and `phpstan/phpstan` 2.4.0. + +What could not be checked here: + +- PHP 8.3, 8.4 and 8.6. Only 8.5 is installed. CI covers the others. +- The lowest dependency versions, except `dot-errorhandler` 5.1.0, which the maintainer installed for a test. +- The `mezzio-router` version that 1.5.0 used. `composer.lock` is in `.gitignore`, so git has no record of it. Thus it is unknown whether 1.5.0 already had the final `Route` and `RouteResult` classes. +- A Laminas backward-compatibility check does not apply. Light is a `project`, not a library. The decision above comes from a manual review. + +## Done by the maintainer + +These uncommitted edits exist in the working tree. Do not repeat them or revert them: + +```diff +- "php": "~8.3.0 || ~8.4.0 || ~8.5.0", +- "dotkernel/dot-errorhandler": "^5.0.0", ++ "php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0", ++ "dotkernel/dot-log": "^5.4.0 || ^6.0.0", ++ "dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0", ++ "laminas/laminas-diactoros": "^3.10.0", ++ "laminas/laminas-servicemanager": "^4.6.0", +... + "post-update-cmd": [ +- "php bin/composer-post-install-script.php" ++ "php bin/composer-post-install-script.php", ++ "@clear-config-cache" ++ ], ++ "post-install-cmd": [ ++ "@clear-config-cache" +``` + +The edits also raise the lower bounds of the other requirements, and they add `- "8.6"` to the PHP matrix of `codecov.yml` and `static-analysis.yml`. The debug lines in `public/index.php` are removed. + +The maintainer kept `"dotkernel/dot-log": "^5.4.0 || ^6.0.0"`. Today, `^6.0.0` matches only `6.0.x-dev`, which Composer does not install with the default `minimum-stability`. Check the range again when `dot-log` 6.0.0 is released. + +No edits are still needed in `composer.json`. + +## Findings + +### V1. Dependency review + +Location: `composer.json`. + +Evidence: each claim comes from `vendor/*/composer.json` or `composer show -a`. + +| Requirement | State | Comment | +| --- | --- | --- | +| `php` `~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0` | Correct | All Mezzio packages in `vendor/` allow the same range | +| `dotkernel/dot-errorhandler` `^5.1.0 \|\| ^6.0.0` | Correct, both majors tested | 5.1.0 requires PHP `~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0`, `dot-log ^5.3` and `laminas-diactoros ^3.8.0`. 6.0.0 is installed. Its `CHANGELOG.md` still says `6.0.0 - TBD`. Report this to the package | +| `dotkernel/dot-log` `^5.4.0 \|\| ^6.0.0` | Correct | `config/autoload/error-handling.global.php` uses `Dot\Log\Logger` and `Dot\Log\Formatter\Json`. See the note about `^6.0.0` above | +| `laminas/laminas-diactoros` `^3.10.0` | Needed | `GetIndexViewHandler` and `GetPageViewHandler` use `Laminas\Diactoros\Response\HtmlResponse` | +| `laminas/laminas-servicemanager` `^4.6.0` | Needed | `config/container.php` creates `Laminas\ServiceManager\ServiceManager` | +| `mezzio/mezzio-router` | Not declared, correct | Four Mezzio packages require it. The code uses only `RouteResult::getMatchedRouteName()`, which exists in 3.x and 4.x | +| `phpunit/phpunit` `^12.5.23` | Correct | See V4 | +| `roave/security-advisories` `dev-master` | Correct | | + +Declared but unused: none found. `laminas-component-installer` is a Composer plugin, and `config.allow-plugins` lists it. + +### V2. Workflows + +Location: `.github/workflows/qodana_code_quality.yml`. + +Evidence: the matrix stops at PHP 8.5, but the other workflows test 8.6. `continuous-integration.yml` uses `laminas/workflow-continuous-integration`, which reads the PHP range from `composer.json`. The repository has no `.laminas-ci.json`. The action versions are already `actions/checkout@v7`, `actions/cache@v6`, `codecov/codecov-action@v7` and `actions/setup-node@v7`. + +Before: + +```yaml + php-versions: [ '8.3', '8.4', '8.5' ] +``` + +After: + +```yaml + php-versions: [ '8.3', '8.4', '8.5', '8.6' ] +``` + +Why: all supported PHP versions get the same checks. + +Also in `static-analysis.yml`, the job id is `mutation`, but the job runs PHPStan. Rename it to `phpstan`. This change does not affect the badge, because the badge uses the workflow file name. + +### V3. PHPStan level 8 + +Location: `phpstan.neon`. + +Evidence: the level is already 8. `composer static-analysis` reports two errors: + +| File | Line | Identifier | Fix | +| --- | --- | --- | --- | +| `test/Unit/Page/Handler/PageHandlerTest.php` | 36 | `method.unresolvableReturnType` | F6: use a real `RouteResult` | +| `test/Unit/Page/RoutesDelegatorTest.php` | 36 | `method.unresolvableReturnType` | F6: use a real `Route` | + +Why: PHPStan cannot resolve a stub of a final class. Both errors have the same cause as the test failures. No ignores or baseline are necessary. + +### V4. PHPUnit major version + +Location: `composer.json`, `require-dev`. + +Evidence: `composer show -a phpunit/phpunit 13.5.1` requires `php >=8.4.1`. Version 12.5.47 requires `php >=8.3`. + +Decision: stay on `^12.5.23`. PHPUnit 13 would remove PHP 8.3 support. The tests already use no annotations and no data providers. So no syntax migration is necessary now. Close the open Renovate branch `renovate/phpunit-phpunit-13.x`, or let it wait until PHP 8.3 support ends. + +### V5. `phpunit.xml` flags + +Location: `phpunit.xml`. + +Evidence: `stopOnError="true"` hid the second test error in the baseline. The file has no `failOn*` flags, and it has an empty `` element. + +Before: + +```xml + displayDetailsOnPhpunitDeprecations="true" + stopOnError="true"> +``` + +After: + +```xml + displayDetailsOnPhpunitDeprecations="true" + failOnDeprecation="true" + failOnNotice="true" + failOnWarning="true" + failOnRisky="true" + failOnPhpunitDeprecation="true"> +``` + +Also remove ``. The `` element already sets the coverage scope. + +Why: all failures are visible in one run, and CI fails on deprecations. This includes deprecations from vendor code on PHP 8.6. If a vendor deprecation blocks CI on 8.6, report it upstream. Do not turn off the flag. + +Not verified: no PHP 8.6 is installed here, so the vendor deprecations on 8.6 are unknown. + +### V6. Release line + +1.6.0 is a minor release, so it comes from branch `1.0`. The README badges (`?branch=1.0`), the LICENSE link (`blob/1.0`), the Qodana branch list, `SECURITY.md` (`1.x` supported) and `OSSMETADATA` (`osslifecycle=active`) stay the same. + +### V7. Node.js 20 in the build matrix + +Location: `.github/workflows/build-assets.yml`, README. + +Evidence: the matrix is `["20", "22", "24", "26"]`. The installed Vite 8.0.14 requires Node.js `^20.19.0 || >=22.12.0`, and `package.json` copies that range. + +Recommendation: I am not certain of the current Node.js 20 status. You may want to verify it on the Node.js release page. If Node.js 20 is end of life, remove it from the matrix and change the README range. Keep `engines` the same as Vite's range. + +### V8. Debug lines in `public/index.php` + +Done by the maintainer. `git diff public/index.php` is empty. + +### V9. `laminas-servicemanager` is a runtime requirement + +Location: `composer.json`, `config/container.php`. + +Evidence: the skill item T20 removes `laminas-servicemanager` from packages. Light is an application, and `config/container.php` creates the container with `new ServiceManager($dependencies)`. Also, `dotkernel/dot-log` 5.4.0 and `laminas/laminas-validator` 3.21.0 require `laminas/laminas-servicemanager` `^4.0` and `^4.4.0`. + +Decision: do not remove it. An application must have one container, and the dependencies install the Service Manager in all cases. Keep it declared, because the application uses it directly. + +### F1. Page handler fails without a matched route + +Severity: low. In the current pipeline, `DispatchMiddleware` calls the handler only after a route matched. + +Location: `src/Page/src/Handler/GetPageViewHandler.php:24`. + +Evidence: a scratch script called the handler with real objects: + +```text +no RouteResult: Error: Call to a member function getMatchedRouteName() on null +failed RouteResult: TypeError: ...render(): Argument #1 ($name) must be of type string, false given +``` + +`RouteResult::getMatchedRouteName()` returns `false|string`, and `TemplateRendererInterface::render()` takes a `non-empty-string`. + +Before: + +```php +public function handle(ServerRequestInterface $request): ResponseInterface +{ + $template = $request->getAttribute(RouteResult::class)->getMatchedRouteName(); + + return new HtmlResponse( + $this->template->render($template) + ); +} +``` + +After: + +```php +public function handle(ServerRequestInterface $request): ResponseInterface +{ + $routeResult = $request->getAttribute(RouteResult::class); + $routeName = $routeResult instanceof RouteResult ? $routeResult->getMatchedRouteName() : false; + if ($routeName === false || $routeName === '') { + throw new RuntimeException('The page handler needs a matched route. Route the request before dispatch.'); + } + + return new HtmlResponse( + $this->template->render($routeName) + ); +} +``` + +Why: the error message names the cause. The prototype passes PHPStan level 8 and phpcs, and the scratch script then shows `RuntimeException` in both cases. + +### F2. Page routes exist only in `local.php` + +Severity: medium. + +Location: `config/autoload/local.php.dist`, `src/Page/src/RoutesDelegator.php:27`. + +Evidence: the `routes` key is set only in `local.php.dist`. `local.php` is git-ignored, and `bin/composer-post-install-script.php` does not overwrite an existing copy. A scratch script built the container twice: + +```text +with local routes: /, /page/about, /page/who-we-are +without local routes: / +``` + +Effects: + +- A deployment without the same `local.php` has no page routes, and the pages return 404. +- A new page in `local.php.dist` does not reach installations that already have a `local.php`. + +Before (`config/autoload/local.php.dist`): + +```php +return [ + 'application' => [ + 'url' => $baseUrl, + ], + 'routes' => [ + 'page' => [ + 'about' => 'about', + 'who-we-are' => 'who-we-are', + ], + ], +]; +``` + +After (`config/autoload/local.php.dist`): + +```php +return [ + 'application' => [ + 'url' => $baseUrl, + ], +]; +``` + +After (`src/Page/src/ConfigProvider.php`): + +```php +public function __invoke(): array +{ + return [ + 'dependencies' => $this->getDependencies(), + 'routes' => $this->getRoutes(), + 'templates' => $this->getTemplates(), + ]; +} + +/** + * @return array{page: array} + */ +public function getRoutes(): array +{ + return [ + 'page' => [ + 'about' => 'about', + 'who-we-are' => 'who-we-are', + ], + ]; +} +``` + +Why: routes are part of the application, not of the environment. The config aggregator merges arrays, so the routes in an existing `local.php` still work. I also checked a collision with the Mezzio `routes` key: `ApplicationConfigInjectionDelegator::injectRoutesFromConfig()` skips entries without `path` and `middleware`, and Light does not register that delegator. No defect was found there. + +### F3. Cookies are written unmasked to the error log + +Severity: high for projects that add sessions or authentication. + +Location: `config/autoload/error-handling.global.php`, `ServerProvider`. + +Evidence: `log/error-log-2026-12-04.log`, line 1, contains the full `HTTP_COOKIE` value, including `cookie_consent_user_consent_token`. A scratch script ran the provider with the current config and with the recommended config: + +```text +current Light config (no processor): {"HTTP_COOKIE":"PHPSESSID=abc123; theme=dark","PHP_AUTH_PW":"secret"} +recommended: {"HTTP_COOKIE":"PHPSESSID=******; theme=dark","PHP_AUTH_PW":"******"} +``` + +Before: + +```php +ServerProvider::class => [ + 'enabled' => true, +// 'processor' => [ +// ... +// ], +], +``` + +After: + +```php +ServerProvider::class => [ + 'enabled' => true, + 'processor' => [ + 'class' => ServerProcessor::class, + 'replacementStrategy' => ReplacementStrategy::Full, + 'sensitiveParameters' => [ + 'phpsessid', + 'php_auth_pw', + 'http_authorization', + 'http_proxy_authorization', + ], + ], +], +``` + +Also copy the 6.0 dist defaults for the disabled providers: real `use` statements in place of the commented FQCNs, and `authorization` and `proxy-authorization` in the `HeaderProvider` `sensitiveParameters`. Another option is to disable `ServerProvider`, as the 6.0 dist file does. + +Why: logs often go to other systems, and a session id in a log can be used to take over a session. The `ServerProcessor` masks each cookie name that is in `sensitiveParameters`. Names are compared in lower case. + +Verified with `dot-errorhandler` 5.1.0 too: the same config gives `{"HTTP_COOKIE":"PHPSESSID=***; theme=dark","PHP_AUTH_PW":"*"}`. The mask has the length of the original value in both versions. + +### F4. `PageService` is unused + +Decision by the maintainer: keep `PageService`, `PageServiceInterface`, `PageServiceFactory` and their test. No change. + +### F5. Stale config cache after `composer update` + +Done by the maintainer. The `post-update-cmd` and `post-install-cmd` scripts now run `@clear-config-cache`. After the maintainer's `composer update`, `data/cache/` contains only `.gitignore` and `twig/`, and the site works. + +### F6. Tests double final classes + +Severity: high for the release. `composer check` fails. + +Location: `test/Unit/Page/Handler/PageHandlerTest.php`, `test/Unit/Page/RoutesDelegatorTest.php`. + +Evidence: `Mezzio\Router\RouteResult` and `Mezzio\Router\Route` are `final` in `mezzio-router` 4.3.0. PHPUnit throws `ClassIsFinalException`, and PHPStan reports `method.unresolvableReturnType`. + +Also in `PageHandlerTest`: + +- `testWillInstantiate` makes a stub of the class under test. The test checks PHPUnit, not the handler. +- The file name does not match the class name `GetPageViewHandler`. + +Before (`PageHandlerTest::testHandle`, part): + +```php +$routeResult = $this->createStub(RouteResult::class); +$routeResult + ->method('getMatchedRouteName') + ->willReturn($routeName); +``` + +After: rename the file to `test/Unit/Page/Handler/GetPageViewHandlerTest.php`. + +```php +public function testHandleRendersTemplateNamedAfterMatchedRoute(): void +{ + $routeName = 'page::about'; + $route = new Route('/page/about', $this->createStub(MiddlewareInterface::class), ['GET'], $routeName); + $request = (new ServerRequest())->withAttribute(RouteResult::class, RouteResult::fromRoute($route)); + + $template = $this->createMock(TemplateRendererInterface::class); + $template->expects($this->once()) + ->method('render') + ->with($routeName) + ->willReturn('

' . $routeName . '

'); + + $response = (new GetPageViewHandler($template))->handle($request); + + $this->assertInstanceOf(HtmlResponse::class, $response); + $this->assertSame('

' . $routeName . '

', (string) $response->getBody()); +} +``` + +Before (`RoutesDelegatorTest`, part): + +```php +$app->method('get')->willReturn($this->createStub(Route::class)); +$app + ->expects($this->exactly(1)) + ->method('get') + ->willReturnCallback(function (...$args) use ($routeUri, $templateName) { + $this->assertSame($routeUri, $args[0]); + $this->assertSame([GetPageViewHandler::class], [$args[1]]); + $this->assertSame($templateName, $args[2]); + }); +``` + +After: + +```php +public function testRegistersOneGetRoutePerConfiguredPage(): void +{ + $container = $this->createStub(ContainerInterface::class); + $container->method('get')->willReturn([ + 'routes' => [ + 'page' => ['about' => 'about'], + ], + ]); + + $route = new Route( + '/page/about', + $this->createStub(MiddlewareInterface::class), + ['GET'], + 'page::about' + ); + + $app = $this->createMock(Application::class); + $app->expects($this->once()) + ->method('get') + ->with('/page/about', GetPageViewHandler::class, 'page::about') + ->willReturn($route); + + $result = (new RoutesDelegator())($container, Application::class, static fn (): Application => $app); + + $this->assertSame($app, $result); +} +``` + +Why: real value objects remove the doubles of final classes. `with()` replaces the callback, so a wrong argument now fails with a clear diff. Both prototypes pass PHPUnit 12.5.47 (2 tests, 9 assertions) and PHPStan level 8 in a scratch directory. + +### F7. Factories use `assert()` as a type check + +Severity: low. + +Location: `src/App/src/Factory/GetIndexViewHandlerFactory.php:25`, `src/Page/src/Factory/GetPageViewHandlerFactory.php:25`, `src/App/src/RoutesDelegator.php:18`, `src/Page/src/RoutesDelegator.php:25`. + +Evidence: with `zend.assertions=-1`, which is the usual production value, PHP does not run `assert()`. The typed constructor parameters still stop a wrong service with a `TypeError`. Thus no bug exists, but the check in the factory is not the real check. `dot-errorhandler` 6 made the same change ("Service checks no longer depend on `zend.assertions`"). + +Before: + +```php +$template = $container->get(TemplateRendererInterface::class); +assert($template instanceof TemplateRendererInterface); +``` + +After: + +```php +$template = $container->get(TemplateRendererInterface::class); +if (! $template instanceof TemplateRendererInterface) { + throw new InvalidArgumentException( + sprintf('Service "%s" must implement %s', TemplateRendererInterface::class, TemplateRendererInterface::class) + ); +} +``` + +Why: the error names the service, and the check runs in every environment. This is optional. If the maintainer rejects it, keep the current code. + +### F8. Malformed docblocks in the config providers + +Severity: nit. + +Location: `src/App/src/ConfigProvider.php:14`, `src/Page/src/ConfigProvider.php:17,31,56`. + +Evidence: the line after `/**` starts with `@return array{`, without a leading `*`. + +Before: + +```php + /** + @return array{ +``` + +After: + +```php + /** + * @return array{ +``` + +Why: the other docblocks in the same files use this form. + +Not verified: I did not test whether PHPStan reads these tags. + +### F9. Outdated docs link in `error-handling.global.php` + +Severity: nit. + +Location: `config/autoload/error-handling.global.php:9`. + +Before: + +```php + * Read more about providers/processors here: https://docs.dotkernel.org/dot-errorhandler/v4/extra/introduction/ +``` + +After: + +```php + * Read more about providers/processors here: https://docs.dotkernel.org/dot-errorhandler/v6/extra/introduction/ +``` + +Not verified: the package has `docs/book/v6/extra/`, but I did not check that the published URL exists. The range also allows 5.1, so a link to the versions overview is another option. + +### F10. Test coverage gaps + +Location: `test/Unit`. + +Evidence: 14 tests in 5 files. No test covers these classes: + +| Class | Branches without a test | +| --- | --- | +| `Light\App\RoutesDelegator` | Registers `/` with the name `app::index` | +| `Light\App\Handler\GetIndexViewHandler` | Renders `app::index` | +| `Light\App\Factory\GetIndexViewHandlerFactory` | Builds the handler from the container | +| `Light\Page\Factory\GetPageViewHandlerFactory` | Builds the handler from the container | +| `Light\Page\Handler\GetPageViewHandler` | F1: no `RouteResult`, and a failed `RouteResult` | +| `Light\Page\ConfigProvider` | F2: the `routes` key | + +Recommendations: + +- Add one test for each row. Use real objects (`ServerRequest`, `Route`, `RouteResult`) and a small PSR-11 fixture container in `test/Unit/Fixture`. Use mocks only for `TemplateRendererInterface`. +- Rename the `setup()` methods in both `ConfigProviderTest` files to `setUp()`. PHP method names are case-insensitive, so the current code works. +- Install `pcov` locally for coverage. CI already uses `coverage: pcov`. +- Optional: add `infection/infection` in a later release. + +## Documentation + +### This repository + +| File | Required change | +| --- | --- | +| `README.md`, Requirements | `PHP 8.3, 8.4, 8.5 or 8.6 (~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0)`. "All four versions are covered by CI" | +| `README.md`, Installing | Remove "the page routes are defined here and nowhere else" (F2) | +| `README.md`, Running the Application | Say that `composer install` and `composer update` now clear the config cache (F5) | +| `README.md`, What's Inside | Nothing. The table already names Laminas Service Manager and Diactoros | +| `README.md`, Node.js | Only if V7 removes Node.js 20 | +| `SECURITY.md` | Nothing. `1.x` stays supported | +| `config/autoload/error-handling.global.php` | F3 and F9 | + +### Repository `light-documentation` + +Location: `/var/www/html/dotkernel/light-documentation`, branch `main`, commit `370ed55`. The repository has one version folder, `docs/book/v1`. Because the release is 1.6.0, keep `current_version: v1` and add no `v2` folder. The repository also has an untracked `AUDIT.md` (510 lines) from 2026-09-18 about the 1.5.0 content. This plan does not repeat its items. + +| Id | Page | Required change | +| --- | --- | --- | +| D1 | `docs/book/index.md` | The file is not a symlink. It contains only the text `# ../../README.md`, and the repository has no root `README.md`. Thus the home page shows that path as its title. Replace it with real content, or with a symlink to a file that exists | +| D2 | `v1/introduction/server-requirements.md` | Heading `## PHP: 8.3, 8.4 or 8.5` and the FAQ answer: add 8.6. The note "the versions declared by `composer.json` in Dotkernel Light 1.5.0" becomes 1.6.0, with "PHP 8.6 was added in release 1.6.0" | +| D3 | `v1/introduction/packages.md` | "The six direct Composer dependencies" becomes nine. Add `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager`. Change the FAQ answer "Six" to "Nine" | +| D4 | `v1/introduction/request-lifecycle.md`, step 6 | The snippet `$request->getAttribute(RouteResult::class)->getMatchedRouteName()` changes with F1. Show the new check, or describe it in one sentence | +| D5 | `v1/how-tos/routing.md` | "Those are being declared in the file `config/autoload/local.php`" and the FAQ answer: the routes are in `src/Page/src/ConfigProvider.php`, `getRoutes()` (F2). Say that `local.php` can still add routes | +| D6 | `v1/how-tos/create-pages.md` | "Open `config/autoload/local.php` and locate the **routes** key" and the FAQ answer: change to `src/Page/src/ConfigProvider.php` (F2) | +| D7 | `v1/introduction/file-structure.md` | `composer-post-install-script.php` line: the hook list now also clears the config cache. `local.php.dist` line: "overwrite application name and URL" is wrong already, because the file sets only `application.url`. Change it to "set the application URL" | +| D8 | `v1/installation/running-the-application.md` | Add that `composer install` and `composer update` clear the config cache. Keep the note about `sudo` | +| D9 | `v1/installation/composer.md`, `faq.md` | No change found by the search. Read both again after D5 to D8 | +| D10 | New `v1/upgrading/UPGRADE-1.6.md` | Same structure as `UPGRADE-1.5.md`: Summary, Details, Important updates, Other updates. Content: the table below | +| D11 | `mkdocs.yml` | Add `"Upgrading from 1.5 to 1.6": v1/upgrading/UPGRADE-1.6.md` under `Upgrading` | + +Content for D10: + +| Change | Symptom | Fix | +| --- | --- | --- | +| PHP 8.6 support added | None | None | +| `dot-log`, `laminas-diactoros` and `laminas-servicemanager` are direct requirements | None, they were installed before | Copy the three lines into your `composer.json` | +| `dot-errorhandler` range is `^5.1.0 \|\| ^6.0.0`, and `composer update` selects 6 | `InvalidArgumentException` from `LogErrorHandlerFactory`, only with custom error handler code or config | Follow the `dot-errorhandler` v6 upgrade guide, or pin `^5.1` | +| Page routes moved to `Light\Page\ConfigProvider` (F2) | A route that you removed from `local.php` comes back | Remove it from `getRoutes()` in your copy | +| Composer clears the config cache after install and update (F5) | None | Copy the two scripts into your `composer.json` | +| `ServerProvider` masks session and authorization values (F3) | Masked values in new log lines | Add your own cookie names to `sensitiveParameters` | + +## CHANGELOG + +Add these sections above `## 1.2.0`, newest first. The file uses `*` bullets. Keep that style. Renovate updates are grouped in one line per release. + +```markdown +## 1.6.0 - TBD + +### Changed + +* Widened `dotkernel/dot-errorhandler` to `^5.1.0 || ^6.0.0` +* Bumped the lower bounds of `laminas/*`, `mezzio/*` and dev dependencies +* Moved the page routes from `local.php.dist` to `Light\Page\ConfigProvider` +* `GetPageViewHandler` throws a `RuntimeException` when no route matched +* Masked session and authorization values in the error log +* Composer clears the configuration cache after install and update +* Tests use real `Route` and `RouteResult` objects +* PHPUnit fails on deprecations, notices, warnings and risky tests +* Vite config and npm vulnerability fixes by [@georgeStan](https://github.com/georgeStan) in [#120](https://github.com/dotkernel/light/pull/120) and [#123](https://github.com/dotkernel/light/pull/123) +* Aligned README with dotkernel.com wording by [@arhimede](https://github.com/arhimede) in [#119](https://github.com/dotkernel/light/pull/119) +* Renovate dependency and action updates in #118 to #127 + +### Added + +* Support for PHP 8.6 +* `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager` as direct requirements +* Tests for the App module, the factories and the page routes + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* `composer check` failed because the tests doubled final `mezzio-router` classes + +## 1.5.0 - 2026-08-03 + +### Changed + +* Issue [#72](https://github.com/dotkernel/light/issues/72): Bumped `phpunit/phpunit` to `^12.5.23` by [@OStefan2001](https://github.com/OStefan2001) in [#73](https://github.com/dotkernel/light/pull/73) +* Updated the Qodana action by [@arhimede](https://github.com/arhimede) in [#71](https://github.com/dotkernel/light/pull/71) and [#74](https://github.com/dotkernel/light/pull/74) +* Updated README and `package.json` by [@bidi47](https://github.com/bidi47) in [#95](https://github.com/dotkernel/light/pull/95) +* Cleaned branch `1.0` by [@georgeStan](https://github.com/georgeStan) in [#114](https://github.com/dotkernel/light/pull/114) +* Fixed ambiguities in README by [@arhimede](https://github.com/arhimede) in [#116](https://github.com/dotkernel/light/pull/116) +* Renovate dependency and action updates in #76 to #113 + +### Added + +* Issue [#97](https://github.com/dotkernel/light/issues/97): Workflow that builds the JS and CSS assets by [@alexmerlin](https://github.com/alexmerlin) in [#98](https://github.com/dotkernel/light/pull/98) +* Renovate configuration in [#75](https://github.com/dotkernel/light/pull/75) + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* Nothing + +## 1.4.0 - 2025-10-31 + +### Changed + +* Issue [#61](https://github.com/dotkernel/light/issues/61): Increased PHPStan level by [@Howriq](https://github.com/Howriq) in [#63](https://github.com/dotkernel/light/pull/63) +* Updated the Qodana workflow by [@arhimede](https://github.com/arhimede) in [#64](https://github.com/dotkernel/light/pull/64) +* Updated the Mezzio version by [@arhimede](https://github.com/arhimede) in [#65](https://github.com/dotkernel/light/pull/65) +* Updated the Packagist dependency badge by [@arhimede](https://github.com/arhimede) in [#66](https://github.com/dotkernel/light/pull/66) + +### Added + +* Support for PHP 8.5 by [@arhimede](https://github.com/arhimede) in [#68](https://github.com/dotkernel/light/pull/68) + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* Nothing + +## 1.3.0 - 2025-04-29 + +### Changed + +* Replaced webpack with Vite by [@georgeStan](https://github.com/georgeStan) in [#50](https://github.com/dotkernel/light/pull/50) +* Updated the title and added PSR-15 on the index page by [@arhimede](https://github.com/arhimede) in [#54](https://github.com/dotkernel/light/pull/54) +* Updated `.gitignore` by [@alexmerlin](https://github.com/alexmerlin) in [#55](https://github.com/dotkernel/light/pull/55) +* Updated the README section about static modules by [@bidi47](https://github.com/bidi47) in [#60](https://github.com/dotkernel/light/pull/60) + +### Added + +* Nothing + +### Deprecated + +* Nothing + +### Removed + +* Removed `.DS_Store` files by [@arhimede](https://github.com/arhimede) in [#56](https://github.com/dotkernel/light/pull/56) and [#57](https://github.com/dotkernel/light/pull/57) + +### Fixed + +* Nothing +``` + +## Rollout order + +1. Fix the tests (F6). `composer check` must pass from here on. +2. Change `phpunit.xml` (V5). Run `composer test`. +3. Fix the page handler and add its tests (F1, F10). +4. Move the page routes (F2) and add the `ConfigProvider` route test. +5. Mask the error log values (F3). Check a log line by hand after a forced error. +6. Optional: F7, F8 and F9. +7. Workflows (V2) and, if confirmed, Node.js (V7). +8. README and CHANGELOG. +9. Documentation repository: D1 to D11, on its own branch. +10. Maintainer: restore the `dot-errorhandler` range (see the checklist), then tag `1.6.0` on branch `1.0`. + +## Verification checklist + +- [x] `composer cs-check` passes +- [x] `composer twig-cs-check` passes +- [x] `composer static-analysis` passes at level 8 without ignores or baseline +- [x] `composer test` passes with the new `failOn*` flags +- [x] `composer check` passes +- [x] Without `local.php`, the container registers `/page/about` (scratch script, 2026-12-04) +- [x] A forced error writes a log line with `PHPSESSID=******` +- [ ] `composer update` deletes `data/cache/config-cache.php` (verified once on 2026-12-04) +- [ ] `public/index.php` has no `ini_set` lines (verified on 2026-12-04) +- [x] Every changed `.md` file in both repositories passes `npx --yes markdownlint-cli2 --config ~/.claude/.markdownlint.jsonc` +- [ ] `mkdocs build` in `light-documentation` shows no warnings for missing pages +- [x] `dot-errorhandler` 5.1.0: container, pages and F3 masking work (2026-12-04) +- [x] Restore `"dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0"` in `composer.json` after the 5.1 test, then run `composer update` +- [ ] Unverified here: a forced error with `dot-errorhandler` 5.1.0 writes a log line +- [ ] Unverified here, check in CI: PHP 8.3, 8.4 and 8.6 +- [ ] Unverified here, check in CI: vendor deprecations on PHP 8.6 with `failOnDeprecation` +- [ ] Unverified here, check in CI: coverage with `pcov` +- [ ] Unverified here: lowest dependency versions (`composer update --prefer-lowest`, then `composer check`) +- [ ] Unverified here: Node.js 20 status (V7) +- [ ] Unverified here: published URL in F9 diff --git a/.claude/skills/plan-major-upgrade/SKILL.md b/.claude/skills/plan-major-upgrade/SKILL.md new file mode 100644 index 0000000..541cb38 --- /dev/null +++ b/.claude/skills/plan-major-upgrade/SKILL.md @@ -0,0 +1,102 @@ +--- +name: plan-major-upgrade +description: Build the written plan for the next major version of a Dotkernel PHP package, saved in `.claude/plan-code-review.md`. Use when asked to review a package and plan its next major release - code review with before/after fixes, phpstan level, workflow and PHP version bumps, PHPUnit upgrade, new docs folder, CHANGELOG and tests. Also use to re-check or update that plan after the maintainer changes `composer.json`. +--- + +# Plan a major upgrade + +Produce one plan file, `.claude/plan-code-review.md`, and keep it current while the work is done. +The plan is the deliverable of the first pass. Make no other changes until the maintainer asks you to implement it. + +## Ground rules + +- **Measure before you claim.** Run the checks and reproduce each suspected bug with a failing test or a small script before it goes in the plan as a bug. Mark anything you could not run as "unverified" and say why (PHP version not installed, no coverage driver, lowest dependencies not installed). +- **Do not edit `composer.json` or install packages.** Edits are denied by the permission settings and the guard hooks block installs. Give the exact lines to change and ask the maintainer to apply them and run the install. Re-check the plan after every such change. +- **Do not circumvent a hook.** If a guard blocks a command, adapt (use the Edit and Write tools, a scratch directory) or ask. +- **Verify facts about other packages from the source**, for example `vendor/` or the published package listing, never from memory. A wrong claim in the plan becomes wrong docs. +- **Markdown is lint-clean.** Every `.md` file you write or edit must pass the maintainer's markdownlint config before you report it as done. + +## Inputs to settle first + +Ask only what you cannot determine from the repository. + +| Item | How to find it | +| --- | --- | +| Next major version number and branch | Ask. Use the current branch name for the plan. Check `git tag`, `git describe --tags` and the remote branches for existing lines | +| Whether other release lines exist | Check branches and tags. A separate line (for example an attribute-based `5.x`) changes the upgrade guide and the README | +| Target PHP versions | From the maintainer or the CI workflow. Note which are installed locally | +| What the maintainer does by hand | Typically `composer.json`, `phpstan.neon` level and the workflow versions. Do not redo or revert them | + +## Task list + +The first eight items (T1 to T8) are the requested tasks. The rest were missed in the original list and should be part of every plan. + +### Requested + +- **T1. Recommend fixes for issues and bugs in the codebase.** Review `src/` for correctness, robustness, types and style. Give each finding an id (F1, F2, ...), a severity, a location and evidence from a reproduction. +- **T2. Add before/after sections** for every recommended update: current code or behaviour, recommended code or behaviour, and why. Cover code, config, docs and tests. +- **T3. `phpstan.neon` to level 8.** Record the current level, run PHPStan at level 8 and list every error with its identifier and fix. Do not propose ignores, baselines or `assert()` workarounds. +- **T4. Workflow versions.** Remove the old PHP version, add the new one, and set the action versions the maintainer named (for example `actions/checkout@v7`, `actions/cache@v6`, `codecov/codecov-action@v7`). Check every file in `.github/workflows` and `.laminas-ci.json`. +- **T5. `phpunit/phpunit` to the new major.** Say whether the maintainer has to do it (it edits `composer.json`) and list the PHPUnit changes the tests need: configuration schema, attributes instead of annotations, static data providers, mock and stub rules, `failOn*` flags. +- **T6. New docs folder for the next major version** in `docs/book`, copied from the most recent version. Keep the old version folders unchanged. List every page that needs content changes. +- **T7. CHANGELOG.md** with all missing releases and the new major release, following the file's section convention. +- **T8. Update the tests**, including new tests for each fixed bug. + +### Recommended additions + +- **T9. Baseline.** Before planning, run `composer check` and record the result, the PHP versions available locally, and the nearest reachable tag (`git describe --tags`). State what the Laminas backward-compatibility check will compare against. +- **T10. Dependency review** of `composer.json`: PHP constraint, each runtime requirement and its range, requirements that are used but undeclared, requirements that are declared but unused, dev dependencies, `suggest` and `conflict`. List exact edits for the maintainer. +- **T11. Dependency removal evaluation.** For any dependency that exists for one import, check whether a PSR interface can replace it and what that would break. Give options and a recommendation. +- **T12. Upgrade guide** (`upgrading.md`) for each older line, with a table of changes that can break code: change, symptom, fix. +- **T13. Discontinued lines.** If a release line is discontinued, add a page in that version's docs folder and point to the replacement package. Read the replacement's source or listing first. +- **T14. README, `docs/book/index.md`, `SECURITY.md` and `mkdocs.yml`.** Version table rows, badges, the supported versions table, `current_version`, `versions` and the navigation. Check whether `docs/book/index.md` is a symlink to the README. +- **T15. `phpunit.xml` and CI flags.** Fail on notices, warnings, deprecations and risky tests. Plan for deprecations raised in vendor code on the newest PHP version. +- **T16. Test quality.** Prefer fixtures and a real collaborator over mocks. Check for traps, for example an annotation reader parsing an `@Inject` mentioned in prose inside a docblock. List coverage gaps by branch, and suggest a coverage driver and mutation testing if none is installed. +- **T17. Documentation examples.** Run every PHP snippet and check every link and navigation entry. Fix examples that never worked. +- **T18. Integration check** outside the repository with the real dependencies (for example a SQLite entity manager and a PSR-6 pool), in a scratch directory. +- **T19. Lifecycle metadata.** Check `OSSMETADATA`, badges and branch names for the new version. +- **T20. Remove `laminas/laminas-servicemanager` when it is a runtime requirement.** Check the `require` section of `composer.json` (a `require-dev` entry or an absence means skip this item). If it is there, implement the removal as `dot-dependency-injection` does, and put each step in the plan with before/after sections: + - Find every use: `grep -rni "laminas\|ServiceManager" src test`. Read `dot-dependency-injection` (`src/Factory`, `src/ConfigProvider.php`, `composer.json`) from its source, not from memory. + - Make the factories plain classes with `__invoke(ContainerInterface $container, string $requestedName)` and only `Psr\Container` imports, so they work with any PSR-11 container that accepts a factory per service key. + - Remove the classes that implement a Laminas interface, normally the abstract factory and its marker annotation. This is a breaking change: list it under Removed in the CHANGELOG and give a "replacing it" section in the upgrade guide, with before and after code. + - Make `ConfigProvider` return `[]` instead of registering `abstract_factories`. Keep the class so applications that list it do not break. + - Replace `ServiceManager` in the tests with a minimal PSR-11 fixture container (`get(string $id): mixed`, `has(string $id): bool`) and exception fixtures that implement `NotFoundExceptionInterface` and `ContainerExceptionInterface`. Class names must end in `Exception` for the coding standard. + - Update the docs, README, version table and CHANGELOG. Say the factories work with any PSR-11 container, and that applications using Laminas Service Manager require it themselves. + - Allow `psr/container` as `^1.1 || ^2.0`, and give the maintainer the `composer.json` edit: remove the requirement and reword the `description`. + - Verify: no `Laminas` or `ServiceManager` left in `src` or `test`, and `composer check` passes. State that the lowest `psr/container` version is unverified unless it was installed. +- **T21. Unverified list.** End the plan with what could not be tested here and how the maintainer can test it in CI. + +## Workflow + +1. Read the repository: `src/`, `test/`, `composer.json`, `phpstan.neon`, `phpunit.xml`, `.github/workflows`, `.laminas-ci.json`, `docs/book`, `README.md`, `CHANGELOG.md`, `SECURITY.md`, `mkdocs.yml`. +2. Run the baseline (T9). +3. Review the code and reproduce each suspected bug (T1 and T2). Use scratch files outside the repository. +4. Run PHPStan at the target level (T3). +5. Review dependencies, workflows and documentation (T4 to T6, T10 to T15 and T20). +6. Write the plan with the structure below. +7. Lint the plan, then tell the maintainer what they have to do by hand. +8. On request, implement the plan in the rollout order, run `composer check` after each step, and update the plan's status table. After every `composer.json` change by the maintainer, re-run the checks and update the docs and CHANGELOG. + +## Plan structure + +Use these headings, in this order. + +1. `# Plan: ` with one paragraph of context (branch, version, date). +2. `## Implementation status`: a table of item, state and notes. Update it as work lands. +3. `## Decision: version `: why this number, and how it relates to other release lines. +4. `## Baseline`: results of the commands you ran, and what you could not run. +5. `## Done by the maintainer`: the edits that were made by hand, and the exact edits still needed. +6. `## Findings`: one section per finding, each with Location, Evidence, Before, After and Why. Group as V1..Vn for version and tooling items, F1..Fn for code and test items. +7. `## Documentation`: a table of page and required change. +8. `## CHANGELOG`: the entries to add, by version. +9. `## Rollout order`: numbered steps, smallest safe change first. +10. `## Verification checklist`: checkboxes for every command and manual check, including the unverified list. + +Use `Before` and `After` as fenced code blocks (`php`, `diff`, `yaml`, `json` or `text`), never an untagged fence. + +## Checklist before reporting done + +- Every finding has a reproduction or is marked unverified. +- Every dependency claim was read from `vendor/` or `composer.json`. +- The plan file passes markdownlint. +- The final message lists what the maintainer must do by hand and what could not be tested here. diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 83ef9b3..9652006 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -18,6 +18,7 @@ jobs: - "8.3" - "8.4" - "8.5" + - "8.6" steps: - name: Checkout diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml index fbe7de0..899f98d 100644 --- a/.github/workflows/qodana_code_quality.yml +++ b/.github/workflows/qodana_code_quality.yml @@ -16,7 +16,7 @@ jobs: checks: write strategy: matrix: - php-versions: [ '8.3', '8.4', '8.5' ] + php-versions: [ '8.3', '8.4', '8.5', '8.6' ] steps: - uses: actions/checkout@v7 with: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 7390951..94c1ee7 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -4,7 +4,7 @@ on: name: Run PHPStan checks jobs: - mutation: + phpstan: name: PHPStan ${{ matrix.php }}-${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -18,6 +18,7 @@ jobs: - "8.3" - "8.4" - "8.5" + - "8.6" steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index f33f4f8..7e5178c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,117 @@ # Changelog +## 1.6.0 - TBD + +### Changed + +* Widened `dotkernel/dot-errorhandler` to `^5.1.0 || ^6.0.0` +* Bumped the lower bounds of `laminas/*`, `mezzio/*` and dev dependencies +* Moved the page routes from `local.php.dist` to `Light\Page\ConfigProvider` +* `GetPageViewHandler` throws a `RuntimeException` when no route matched +* Masked session and authorization values in the error log +* Composer clears the configuration cache after install and update +* Tests use real `Route` and `RouteResult` objects +* PHPUnit fails on deprecations, notices, warnings and risky tests +* Vite config and npm vulnerability fixes by [@georgeStan](https://github.com/georgeStan) in [#120](https://github.com/dotkernel/light/pull/120) and [#123](https://github.com/dotkernel/light/pull/123) +* Aligned README with dotkernel.com wording by [@arhimede](https://github.com/arhimede) in [#119](https://github.com/dotkernel/light/pull/119) +* Renovate dependency and action updates in #118 to #127 + +### Added + +* Support for PHP 8.6 +* `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager` as direct requirements +* Tests for the App module, the factories and the page routes + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* `composer check` failed because the tests doubled final `mezzio-router` classes + +## 1.5.0 - 2026-08-03 + +### Changed + +* Issue [#72](https://github.com/dotkernel/light/issues/72): Bumped `phpunit/phpunit` to `^12.5.23` by [@OStefan2001](https://github.com/OStefan2001) in [#73](https://github.com/dotkernel/light/pull/73) +* Updated the Qodana action by [@arhimede](https://github.com/arhimede) in [#71](https://github.com/dotkernel/light/pull/71) and [#74](https://github.com/dotkernel/light/pull/74) +* Updated README and `package.json` by [@bidi47](https://github.com/bidi47) in [#95](https://github.com/dotkernel/light/pull/95) +* Cleaned branch `1.0` by [@georgeStan](https://github.com/georgeStan) in [#114](https://github.com/dotkernel/light/pull/114) +* Fixed ambiguities in README by [@arhimede](https://github.com/arhimede) in [#116](https://github.com/dotkernel/light/pull/116) +* Renovate dependency and action updates in #76 to #113 + +### Added + +* Issue [#97](https://github.com/dotkernel/light/issues/97): Workflow that builds the JS and CSS assets by [@alexmerlin](https://github.com/alexmerlin) in [#98](https://github.com/dotkernel/light/pull/98) +* Renovate configuration in [#75](https://github.com/dotkernel/light/pull/75) + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* Nothing + +## 1.4.0 - 2025-10-31 + +### Changed + +* Issue [#61](https://github.com/dotkernel/light/issues/61): Increased PHPStan level by [@Howriq](https://github.com/Howriq) in [#63](https://github.com/dotkernel/light/pull/63) +* Updated the Qodana workflow by [@arhimede](https://github.com/arhimede) in [#64](https://github.com/dotkernel/light/pull/64) +* Updated the Mezzio version by [@arhimede](https://github.com/arhimede) in [#65](https://github.com/dotkernel/light/pull/65) +* Updated the Packagist dependency badge by [@arhimede](https://github.com/arhimede) in [#66](https://github.com/dotkernel/light/pull/66) + +### Added + +* Support for PHP 8.5 by [@arhimede](https://github.com/arhimede) in [#68](https://github.com/dotkernel/light/pull/68) + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* Nothing + +## 1.3.0 - 2025-04-29 + +### Changed + +* Replaced webpack with Vite by [@georgeStan](https://github.com/georgeStan) in [#50](https://github.com/dotkernel/light/pull/50) +* Updated the title and added PSR-15 on the index page by [@arhimede](https://github.com/arhimede) in [#54](https://github.com/dotkernel/light/pull/54) +* Updated `.gitignore` by [@alexmerlin](https://github.com/alexmerlin) in [#55](https://github.com/dotkernel/light/pull/55) +* Updated the README section about static modules by [@bidi47](https://github.com/bidi47) in [#60](https://github.com/dotkernel/light/pull/60) + +### Added + +* Nothing + +### Deprecated + +* Nothing + +### Removed + +* Removed `.DS_Store` files by [@arhimede](https://github.com/arhimede) in [#56](https://github.com/dotkernel/light/pull/56) and [#57](https://github.com/dotkernel/light/pull/57) + +### Fixed + +* Nothing + ## 1.2.0 - 2025-03-03 Implemented `PSR-15`-compliant request handlers, which replace request controllers. diff --git a/README.md b/README.md index 38990b4..452d0e9 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ Documentation is available at: https://docs.dotkernel.org/light-documentation/ ## Requirements -- **PHP** 8.3, 8.4 or 8.5 (`~8.3.0 || ~8.4.0 || ~8.5.0`). - All three versions are covered by CI. +- **PHP** 8.3, 8.4, 8.5 or 8.6 (`~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0`). + All four versions are covered by CI. - **Node.js** `^20.19.0 || >=22.12.0` — required by the Vite and Sass versions used to build the interface. npm ships bundled with Node.js, so any supported Node.js release provides a compatible npm. @@ -143,7 +143,8 @@ cp config/autoload/local.php.dist config/autoload/local.php ``` > A Composer hook normally creates this file for you, but it is registered on `post-update-cmd` only, so it does not run for installs performed from an existing `composer.lock`. -> The file is git-ignored and holds your local settings — `application.url` and the page routes are defined here and nowhere else. +> The file is git-ignored and holds your local settings, for example `application.url`. +> The page routes are defined in `src/Page/src/ConfigProvider.php`. ## Development Mode @@ -209,6 +210,7 @@ You should see the `Dotkernel Light` welcome page. **NOTE:** +- `composer install` and `composer update` clear the configuration cache automatically. - If you are getting exceptions or errors regarding some missing services, clear the configuration cache: ```shell diff --git a/composer.json b/composer.json index 0fd72d2..7cb703a 100644 --- a/composer.json +++ b/composer.json @@ -26,24 +26,27 @@ } }, "require": { - "php": "~8.3.0 || ~8.4.0 || ~8.5.0", - "dotkernel/dot-errorhandler": "^5.0.0", - "laminas/laminas-component-installer": "^3.5.0", - "laminas/laminas-config-aggregator": "^1.17.0", - "mezzio/mezzio": "^3.24.0", - "mezzio/mezzio-fastroute": "^3.13.0", - "mezzio/mezzio-twigrenderer": "^2.17.0" + "php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0", + "dotkernel/dot-log": "^5.4.0 || ^6.0.0", + "dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0", + "laminas/laminas-component-installer": "^3.9.0", + "laminas/laminas-config-aggregator": "^1.21.0", + "laminas/laminas-diactoros": "^3.10.0", + "laminas/laminas-servicemanager": "^4.6.0", + "mezzio/mezzio": "^3.29.0", + "mezzio/mezzio-fastroute": "^3.15.0", + "mezzio/mezzio-twigrenderer": "^2.21.0" }, "require-dev": { - "filp/whoops": "^2.17.0", - "laminas/laminas-coding-standard": "^3.0.1", - "laminas/laminas-development-mode": "^3.13.0", - "phpstan/phpstan": "^2.1.2", - "phpstan/phpstan-phpunit": "^2.0.4", + "filp/whoops": "^2.19.0", + "laminas/laminas-coding-standard": "^3.1.0", + "laminas/laminas-development-mode": "^3.16.0", + "phpstan/phpstan": "^2.4.0", + "phpstan/phpstan-phpunit": "^2.1.7", "phpunit/phpunit": "^12.5.23", "roave/security-advisories": "dev-master", - "symfony/var-dumper": "^7.2.3", - "vincentlanglet/twig-cs-fixer": "^4.0.0" + "symfony/var-dumper": "^7.2.3 || ^8.0.0", + "vincentlanglet/twig-cs-fixer": "^4.2.0" }, "autoload": { "psr-4": { @@ -61,7 +64,11 @@ "@development-enable" ], "post-update-cmd": [ - "php bin/composer-post-install-script.php" + "php bin/composer-post-install-script.php", + "@clear-config-cache" + ], + "post-install-cmd": [ + "@clear-config-cache" ], "development-disable": "laminas-development-mode disable", "development-enable": "laminas-development-mode enable", diff --git a/config/autoload/error-handling.global.php b/config/autoload/error-handling.global.php index bf31f2a..968e00b 100644 --- a/config/autoload/error-handling.global.php +++ b/config/autoload/error-handling.global.php @@ -1,23 +1,32 @@ 'dot-log.default_logger', ExtraProvider::CONFIG_KEY => [ CookieProvider::class => [ - 'enabled' => false, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\CookieProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [ -// \Dot\ErrorHandler\Extra\Processor\ProcessorInterface::ALL, -// ], -// ], + 'enabled' => false, + 'processor' => [ + 'class' => CookieProcessor::class, + 'replacementStrategy' => ReplacementStrategy::Full, + 'sensitiveParameters' => [ + ProcessorInterface::ALL, + ], + ], ], HeaderProvider::class => [ - 'enabled' => false, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\HeaderProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [], -// ], + 'enabled' => false, + 'processor' => [ + 'class' => HeaderProcessor::class, + 'replacementStrategy' => ReplacementStrategy::Full, + 'sensitiveParameters' => [ + 'authorization', + 'proxy-authorization', + ], + ], ], RequestProvider::class => [ - 'enabled' => false, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\RequestProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [ -// 'password', -// ], -// ], + 'enabled' => false, + 'processor' => [ + 'class' => RequestProcessor::class, + 'replacementStrategy' => ReplacementStrategy::Full, + 'sensitiveParameters' => [ + 'password', + ], + ], ], ServerProvider::class => [ - 'enabled' => true, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\ServerProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [ -// \Dot\ErrorHandler\Extra\Processor\ProcessorInterface::ALL, -// ], -// ], + 'enabled' => true, + 'processor' => [ + 'class' => ServerProcessor::class, + 'replacementStrategy' => ReplacementStrategy::Full, + 'sensitiveParameters' => [ + 'phpsessid', + 'php_auth_pw', + 'http_authorization', + 'http_proxy_authorization', + ], + ], ], SessionProvider::class => [ - 'enabled' => false, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\SessionProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [], -// ], + 'enabled' => false, + 'processor' => [ + 'class' => SessionProcessor::class, + ], ], TraceProvider::class => [ - 'enabled' => true, -// 'processor' => [ -// 'class' => \Dot\ErrorHandler\Extra\Processor\TraceProcessor::class, -// 'replacementStrategy' => \Dot\ErrorHandler\Extra\ReplacementStrategy::Full, -// 'sensitiveParameters' => [], -// ], + 'enabled' => true, + 'processor' => [ + 'class' => TraceProcessor::class, + ], ], ], ], diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist index 7dba947..5b50b90 100644 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -15,10 +15,4 @@ return [ 'application' => [ 'url' => $baseUrl, ], - 'routes' => [ - 'page' => [ - 'about' => 'about', - 'who-we-are' => 'who-we-are', - ], - ], ]; diff --git a/phpunit.xml b/phpunit.xml index b98b821..c894171 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,14 +6,17 @@ displayDetailsOnPhpunitNotices="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitDeprecations="true" - stopOnError="true"> + failOnDeprecation="true" + failOnNotice="true" + failOnWarning="true" + failOnRisky="true" + failOnPhpunitDeprecation="true"> ./test/Unit ./test/Unit/UnitTest.php - ./src diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index 82b5fcc..a096824 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -11,7 +11,7 @@ class ConfigProvider { /** - @return array{ + * @return array{ * dependencies: array, * templates: array, * } diff --git a/src/Page/src/ConfigProvider.php b/src/Page/src/ConfigProvider.php index 6041f62..396c8ea 100644 --- a/src/Page/src/ConfigProvider.php +++ b/src/Page/src/ConfigProvider.php @@ -14,8 +14,9 @@ class ConfigProvider { /** - @return array{ + * @return array{ * dependencies: array, + * routes: array, * templates: array, * } */ @@ -23,12 +24,13 @@ public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), + 'routes' => $this->getRoutes(), 'templates' => $this->getTemplates(), ]; } /** - @return array{ + * @return array{ * delegators: array>, * factories: array, * aliases: array @@ -53,7 +55,23 @@ public function getDependencies(): array } /** - @return array{ + * Page routes. Each key is the URI segment after "/page/", and each value is the template name. + * The RoutesDelegator registers each entry as "/page/" with the route name "page::". + * + * @return array{page: array} + */ + public function getRoutes(): array + { + return [ + 'page' => [ + 'about' => 'about', + 'who-we-are' => 'who-we-are', + ], + ]; + } + + /** + * @return array{ * paths: array{page: array{literal-string&non-falsy-string}} * } */ diff --git a/src/Page/src/Handler/GetPageViewHandler.php b/src/Page/src/Handler/GetPageViewHandler.php index 210bd6b..9e842fc 100644 --- a/src/Page/src/Handler/GetPageViewHandler.php +++ b/src/Page/src/Handler/GetPageViewHandler.php @@ -10,6 +10,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use RuntimeException; class GetPageViewHandler implements RequestHandlerInterface { @@ -20,10 +21,14 @@ public function __construct( public function handle(ServerRequestInterface $request): ResponseInterface { - $template = $request->getAttribute(RouteResult::class)->getMatchedRouteName(); + $routeResult = $request->getAttribute(RouteResult::class); + $routeName = $routeResult instanceof RouteResult ? $routeResult->getMatchedRouteName() : false; + if ($routeName === false || $routeName === '') { + throw new RuntimeException('The page handler needs a matched route. Route the request before dispatch.'); + } return new HtmlResponse( - $this->template->render($template) + $this->template->render($routeName) ); } } diff --git a/test/Unit/App/ConfigProviderTest.php b/test/Unit/App/ConfigProviderTest.php index 970ad88..523f07f 100644 --- a/test/Unit/App/ConfigProviderTest.php +++ b/test/Unit/App/ConfigProviderTest.php @@ -13,7 +13,7 @@ class ConfigProviderTest extends TestCase /** @var array>*/ protected array $config = []; - protected function setup(): void + protected function setUp(): void { parent::setUp(); diff --git a/test/Unit/App/Factory/GetIndexViewHandlerFactoryTest.php b/test/Unit/App/Factory/GetIndexViewHandlerFactoryTest.php new file mode 100644 index 0000000..5f3a5cf --- /dev/null +++ b/test/Unit/App/Factory/GetIndexViewHandlerFactoryTest.php @@ -0,0 +1,29 @@ +createMock(TemplateRendererInterface::class); + $template->expects($this->once()) + ->method('render') + ->with('app::index') + ->willReturn('

index

'); + $container = new InMemoryContainer([TemplateRendererInterface::class => $template]); + + $handler = (new GetIndexViewHandlerFactory())($container, GetIndexViewHandler::class); + + $this->assertSame('

index

', (string) $handler->handle(new ServerRequest())->getBody()); + } +} diff --git a/test/Unit/App/Handler/GetIndexViewHandlerTest.php b/test/Unit/App/Handler/GetIndexViewHandlerTest.php new file mode 100644 index 0000000..69d4238 --- /dev/null +++ b/test/Unit/App/Handler/GetIndexViewHandlerTest.php @@ -0,0 +1,28 @@ +createMock(TemplateRendererInterface::class); + $template->expects($this->once()) + ->method('render') + ->with('app::index') + ->willReturn('

index

'); + + $response = (new GetIndexViewHandler($template))->handle(new ServerRequest()); + + $this->assertInstanceOf(HtmlResponse::class, $response); + $this->assertSame('

index

', (string) $response->getBody()); + } +} diff --git a/test/Unit/App/RoutesDelegatorTest.php b/test/Unit/App/RoutesDelegatorTest.php new file mode 100644 index 0000000..653fb7c --- /dev/null +++ b/test/Unit/App/RoutesDelegatorTest.php @@ -0,0 +1,32 @@ +createStub(MiddlewareInterface::class), ['GET'], 'app::index'); + + $app = $this->createMock(Application::class); + $app->expects($this->once()) + ->method('get') + ->with('/', [GetIndexViewHandler::class], 'app::index') + ->willReturn($route); + + $callback = static fn (): Application => $app; + $result = (new RoutesDelegator())(new InMemoryContainer(), Application::class, $callback); + + $this->assertSame($app, $result); + } +} diff --git a/test/Unit/Fixture/InMemoryContainer.php b/test/Unit/Fixture/InMemoryContainer.php new file mode 100644 index 0000000..59fc9fe --- /dev/null +++ b/test/Unit/Fixture/InMemoryContainer.php @@ -0,0 +1,37 @@ + $services + */ + public function __construct( + private readonly array $services = [], + ) { + } + + public function get(string $id): mixed + { + if (! $this->has($id)) { + throw new ServiceNotFoundException($id); + } + + return $this->services[$id]; + } + + public function has(string $id): bool + { + return array_key_exists($id, $this->services); + } +} diff --git a/test/Unit/Fixture/ServiceNotFoundException.php b/test/Unit/Fixture/ServiceNotFoundException.php new file mode 100644 index 0000000..751514e --- /dev/null +++ b/test/Unit/Fixture/ServiceNotFoundException.php @@ -0,0 +1,18 @@ +>*/ protected array $config = []; - protected function setup(): void + protected function setUp(): void { parent::setUp(); @@ -59,6 +59,19 @@ public function testDependenciesHasAliases(): void $this->assertArrayHasKey(PageServiceInterface::class, $this->config['dependencies']['aliases']); } + public function testConfigHasPageRoutes(): void + { + $this->assertSame( + [ + 'page' => [ + 'about' => 'about', + 'who-we-are' => 'who-we-are', + ], + ], + $this->config['routes'] + ); + } + public function testGetTemplates(): void { $this->assertArrayHasKey('paths', $this->config['templates']); diff --git a/test/Unit/Page/Factory/GetPageViewHandlerFactoryTest.php b/test/Unit/Page/Factory/GetPageViewHandlerFactoryTest.php new file mode 100644 index 0000000..4932fc3 --- /dev/null +++ b/test/Unit/Page/Factory/GetPageViewHandlerFactoryTest.php @@ -0,0 +1,35 @@ +createMock(TemplateRendererInterface::class); + $template->expects($this->once()) + ->method('render') + ->with('page::about') + ->willReturn('

about

'); + $container = new InMemoryContainer([TemplateRendererInterface::class => $template]); + + $handler = (new GetPageViewHandlerFactory())($container, GetPageViewHandler::class); + + $route = new Route('/page/about', $this->createStub(MiddlewareInterface::class), ['GET'], 'page::about'); + $request = (new ServerRequest())->withAttribute(RouteResult::class, RouteResult::fromRoute($route)); + + $this->assertSame('

about

', (string) $handler->handle($request)->getBody()); + } +} diff --git a/test/Unit/Page/Handler/GetPageViewHandlerTest.php b/test/Unit/Page/Handler/GetPageViewHandlerTest.php new file mode 100644 index 0000000..7b9a258 --- /dev/null +++ b/test/Unit/Page/Handler/GetPageViewHandlerTest.php @@ -0,0 +1,57 @@ +createStub(MiddlewareInterface::class), ['GET'], $routeName); + $request = (new ServerRequest())->withAttribute(RouteResult::class, RouteResult::fromRoute($route)); + + $template = $this->createMock(TemplateRendererInterface::class); + $template->expects($this->once()) + ->method('render') + ->with($routeName) + ->willReturn('

' . $routeName . '

'); + + $response = (new GetPageViewHandler($template))->handle($request); + + $this->assertInstanceOf(HtmlResponse::class, $response); + $this->assertSame('

' . $routeName . '

', (string) $response->getBody()); + } + + public function testHandleThrowsWithoutRouteResult(): void + { + $handler = new GetPageViewHandler($this->createStub(TemplateRendererInterface::class)); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('The page handler needs a matched route.'); + + $handler->handle(new ServerRequest()); + } + + public function testHandleThrowsWhenRoutingFailed(): void + { + $handler = new GetPageViewHandler($this->createStub(TemplateRendererInterface::class)); + $request = (new ServerRequest())->withAttribute(RouteResult::class, RouteResult::fromRouteFailure(null)); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('The page handler needs a matched route.'); + + $handler->handle($request); + } +} diff --git a/test/Unit/Page/Handler/PageHandlerTest.php b/test/Unit/Page/Handler/PageHandlerTest.php deleted file mode 100644 index 61400db..0000000 --- a/test/Unit/Page/Handler/PageHandlerTest.php +++ /dev/null @@ -1,57 +0,0 @@ -createStub(GetPageViewHandler::class); - - $this->assertContainsOnlyInstancesOf(RequestHandlerInterface::class, [$handler]); - } - - /** - * @throws Exception - */ - public function testHandle(): void - { - $routeName = 'test_route_name'; - $request = $this->createStub(ServerRequestInterface::class); - $template = $this->createStub(TemplateRendererInterface::class); - $routeResult = $this->createStub(RouteResult::class); - - $routeResult - ->method('getMatchedRouteName') - ->willReturn($routeName); - - $request - ->method('getAttribute') - ->willReturn($routeResult); - - $template - ->method('render') - ->willReturn('

' . $routeName . '

'); - - $handler = new GetPageViewHandler($template); - - $response = $handler->handle($request); - - $this->assertInstanceOf(HtmlResponse::class, $response); - $this->assertSame('

' . $routeName . '

', $response->getBody()->getContents()); - } -} diff --git a/test/Unit/Page/RoutesDelegatorTest.php b/test/Unit/Page/RoutesDelegatorTest.php index bd94d63..f9d3217 100644 --- a/test/Unit/Page/RoutesDelegatorTest.php +++ b/test/Unit/Page/RoutesDelegatorTest.php @@ -8,57 +8,36 @@ use Light\Page\RoutesDelegator; use Mezzio\Application; use Mezzio\Router\Route; -use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; -use Psr\Container\NotFoundExceptionInterface; - -use function sprintf; +use Psr\Http\Server\MiddlewareInterface; class RoutesDelegatorTest extends TestCase { - /** - * @throws ContainerExceptionInterface - * @throws Exception - * @throws NotFoundExceptionInterface - */ - public function testWillInvoke(): void + public function testRegistersOneGetRoutePerConfiguredPage(): void { - $moduleName = 'test'; - $routeName = 'test_route_name'; - $routeUri = sprintf('/%s/%s', $moduleName, $routeName); - $templateName = sprintf('%s::%s', $moduleName, $routeName); - $container = $this->createStub(ContainerInterface::class); - $app = $this->createMock(Application::class); - - $app->method('get')->willReturn($this->createStub(Route::class)); - $app - ->expects($this->exactly(1)) - ->method('get') - ->willReturnCallback(function (...$args) use ($routeUri, $templateName) { - $this->assertSame($routeUri, $args[0]); - $this->assertSame([GetPageViewHandler::class], [$args[1]]); - $this->assertSame($templateName, $args[2]); - }); - $container->method('get')->willReturn([ 'routes' => [ - $moduleName => [ - $routeName => $routeName, - ], + 'page' => ['about' => 'about'], ], ]); - $application = (new RoutesDelegator())( - $container, - '', - $callback = function () use ($app) { - return $app; - } + $route = new Route( + '/page/about', + $this->createStub(MiddlewareInterface::class), + ['GET'], + 'page::about' ); - $this->assertContainsOnlyInstancesOf(Application::class, [$application]); + $app = $this->createMock(Application::class); + $app->expects($this->once()) + ->method('get') + ->with('/page/about', GetPageViewHandler::class, 'page::about') + ->willReturn($route); + + $result = (new RoutesDelegator())($container, Application::class, static fn (): Application => $app); + + $this->assertSame($app, $result); } } From dc725dcdab51e432a640b293766ce7dc33324fe8 Mon Sep 17 00:00:00 2001 From: bidi Date: Fri, 4 Dec 2026 17:05:33 +0200 Subject: [PATCH 2/3] removed folder Signed-off-by: bidi --- .claude/hooks/guard-bash.sh | 246 ------- .claude/hooks/guard-protected-paths.sh | 57 -- .claude/hooks/markdown-lint.sh | 49 -- .claude/hooks/normalize-file.sh | 91 --- .claude/hooks/php-lint.sh | 35 - .claude/hooks/session-start.sh | 89 --- .claude/plan-code-review.md | 786 --------------------- .claude/skills/plan-major-upgrade/SKILL.md | 102 --- 8 files changed, 1455 deletions(-) delete mode 100644 .claude/hooks/guard-bash.sh delete mode 100644 .claude/hooks/guard-protected-paths.sh delete mode 100644 .claude/hooks/markdown-lint.sh delete mode 100644 .claude/hooks/normalize-file.sh delete mode 100644 .claude/hooks/php-lint.sh delete mode 100644 .claude/hooks/session-start.sh delete mode 100644 .claude/plan-code-review.md delete mode 100644 .claude/skills/plan-major-upgrade/SKILL.md diff --git a/.claude/hooks/guard-bash.sh b/.claude/hooks/guard-bash.sh deleted file mode 100644 index e84159b..0000000 --- a/.claude/hooks/guard-bash.sh +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env bash -# PreToolUse guard for Bash commands in Dotkernel projects. -# Catches installs and destructive git even when hidden inside compound commands -# ("cd x && composer require y"), which path-based permission rules cannot see. -# Quoted arguments, comments and heredoc bodies are data and are not matched, so -# grep "rm -rf" docs/ is allowed. Quoted code is still checked: the script after a -c -# option (sh -c "..."), the arguments of eval, ssh and watch, and a heredoc or -# here-string fed to a shell. -# This matches text, not a parsed shell: an unusual spelling can still get past it. -# bash, sed and awk; jq is used for the payload when installed. -# Exit 0 = allow, exit 2 = block. - -set -u -export LC_ALL=C - -payload=$(cat) - -# Print tool_input.command with its JSON escapes decoded. -extract_command() { - if command -v jq >/dev/null 2>&1 \ - && printf '%s' "$payload" | jq -r '.tool_input.command // empty' 2>/dev/null; then - return - fi - # No jq: park the two escapes that can hide a quote (\\ and \") on control bytes, - # which valid JSON never contains raw, so [^"]* ends exactly at the closing quote. - local bs='\' sl='/' esc_bs=$'\002' esc_q=$'\001' s - s=$(printf '%s' "$payload" | tr -d '\n' | sed -n \ - -e 's/\\\\/'"$esc_bs"'/g' \ - -e 's/\\"/'"$esc_q"'/g' \ - -e 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') - s=${s//"${bs}n"/$'\n'} - s=${s//"${bs}t"/$'\t'} - s=${s//"${bs}r"/$'\r'} - s=${s//"$bs$sl"/$sl} - s=${s//"$esc_q"/\"} - s=${s//"$esc_bs"/$bs} - printf '%s' "$s" -} - -cmd=$(extract_command) -[ -z "$cmd" ] && exit 0 - -# Reduce the command to the text that would run. Quoted strings, comments and heredoc -# bodies become the placeholder Q, and ; & | ( ) ` and newlines become separate words. -# Code inside quotes or a heredoc (the script after a -c option, the arguments of eval, -# ssh or watch, a heredoc or here-string fed to a shell) is reduced the same way and -# appended after a " ; ". An unterminated quote leaves the rest of the command unmasked. -IFS= read -r -d '' SHELL_VIEW <<'AWK' || true -{ src = (NR == 1) ? $0 : src "\n" $0 } -END { printf "%s", scan(src, 0) } - -# out: the reduced command; seg0: where the current simple command starts in out; -# ws: the next character starts a word (so # opens a comment). -function scan(s, depth, n, i, c, j, out, seg0, ws, extra, body, q, seg, code, strip, - d, nd, hd, hs, hf, h, lines, nl, ln, pos, found, cmp, start) { - n = length(s); i = 1; out = ""; seg0 = 1; ws = 1; extra = ""; nd = 0 - while (i <= n) { - if (match(substr(s, i, 512), /^[^\\'"$#<;&|()`\n]+/)) { # ordinary text, in runs - out = out substr(s, i, RLENGTH); i += RLENGTH - ws = (substr(out, length(out), 1) ~ /[ \t]/); continue - } - c = substr(s, i, 1) - - if (c == "\\") { # escaped character, or line continuation - if (substr(s, i + 1, 1) != "\n") { out = out substr(s, i + 1, 1); ws = 0 } - i += 2; continue - } - - if (c == "'" || c == "\"" || (c == "$" && substr(s, i + 1, 1) == "'")) { - q = c; j = i + 1 - if (c == "$") { q = "'"; j = i + 2 } - if (c == "'") { - j = index(substr(s, j), "'"); if (j) j += i - } else { # "..." and $'...' honour backslash escapes - while (j <= n && substr(s, j, 1) != q) j += (substr(s, j, 1) == "\\") ? 2 : 1 - if (j > n) j = 0 - } - if (!j) { out = out substr(s, i); break } - body = substr(s, i + 1, j - i - 1) - seg = substr(out, seg0); code = 0 - if (seg ~ /(^|[ \t])-[a-z]*c[ \t]*$/ || seg ~ /(^|[ \t\/])(eval|ssh|watch)[ \t]/) code = 1 - else if (sub(/<<<[ \t]*$/, "", seg)) code = feeds_shell(seg) - if (code && c != "$") extra = extra " ; " nested((c == "\"") ? undq(body) : body, depth) - out = out "Q"; i = j + 1; ws = 0; continue - } - - if (c == "#" && ws) { # comment, up to the end of the line - j = index(substr(s, i), "\n") - if (!j) break - i += j - 1; continue - } - - if (c == "<" && substr(s, i, 3) == "<<<") { out = out "<<<"; i += 3; ws = 1; continue } - if (c == "<" && substr(s, i, 2) == "<<") { # heredoc - j = i + 2; strip = 0 - if (substr(s, j, 1) == "-") { strip = 1; j++ } - while (substr(s, j, 1) == " " || substr(s, j, 1) == "\t") j++ - d = ""; q = substr(s, j, 1) - if (q == "'" || q == "\"") { - c = index(substr(s, j + 1), q) - if (c) { d = substr(s, j + 1, c - 1); j += c + 1 } - } else { - while (j <= n && substr(s, j, 1) !~ /[ \t\n;&|()<>'"]/) { - if (substr(s, j, 1) == "\\") j++ - d = d substr(s, j, 1); j++ - } - } - if (d == "") { out = out "<<"; i += 2; ws = 1; continue } - nd++; hd[nd] = d; hs[nd] = strip; hf[nd] = feeds_shell(substr(out, seg0)) - out = out " << Q "; i = j; ws = 0; continue - } - - if (c == "\n") { - out = out " ; "; seg0 = length(out) + 1; ws = 1; i++ - if (nd) { # bodies of the heredocs opened on that line - nl = split(substr(s, i), lines, "\n"); ln = 1; pos = i - for (h = 1; h <= nd; h++) { - start = pos; found = 0 - for (; ln <= nl; ln++) { - cmp = lines[ln] - if (hs[h]) sub(/^\t+/, "", cmp) - if (cmp == hd[h]) { found = 1; break } - pos += length(lines[ln]) + 1 - } - if (!found) { pos = start; break } # no terminator: scan it as commands - if (hf[h]) extra = extra " ; " nested(substr(s, start, pos - start), depth) - pos += length(lines[ln]) + 1; ln++ - } - i = pos; nd = 0 - } - continue - } - - if (index(";&|()`", c)) { out = out " " c " "; seg0 = length(out) + 1; ws = 1; i++; continue } - out = out c; ws = 0; i++ - } - return out extra -} - -# The command so far ends with a shell that reads its script from stdin. -function feeds_shell(seg) { return seg ~ /(^|[ \t\/])(ba|z|da|k|a)?sh([ \t]+-[a-z]+)*[ \t]*$/ } - -function nested(s, depth) { return (depth < 4) ? scan(s, depth + 1) : s } - -function undq(s, r, i, n, c, nx) { # remove the escapes "..." honours - r = ""; n = length(s) - for (i = 1; i <= n; i++) { - c = substr(s, i, 1) - if (c == "\\" && i < n) { - nx = substr(s, i + 1, 1) - if (nx == "\n") { i++; continue } - if (index("\"\\$`", nx)) { r = r nx; i++; continue } - } - r = r c - } - return r -} -AWK - -lc=$(printf '%s' "$cmd" | tr '[:upper:]' '[:lower:]') -view=$(printf '%s' "$lc" | awk "$SHELL_VIEW") || view=$lc -norm=$(printf '%s' "$view" | tr '\t\r\n' ' ' | tr -s ' ') - -block() { - local shown=$cmd - [ ${#shown} -gt 500 ] && shown="${shown:0:500}..." - printf 'BLOCKED command: %s\n%s\n' "$shown" "$1" >&2 - exit 2 -} - -set -f -# shellcheck disable=SC2206 # word splitting is the point; globbing is off -words=($norm) -set +f -nw=${#words[@]} - -# composer [options] [global] . Composer resolves any unambiguous prefix of a -# command name (req, upd, inst, rem) and the aliases r, i, u, upgrade, rm, uninstall. -for ((i = 0; i < nw; i++)); do - case ${words[i]} in - composer|composer.phar|*/composer|*/composer.phar) ;; - *) continue ;; - esac - j=$((i + 1)) - while ((j < nw)); do - case ${words[j]} in - -d|--working-dir) j=$((j + 2)) ;; - -*) j=$((j + 1)) ;; - *) [[ global == "${words[j]}"* ]] && j=$((j + 1)) || break ;; - esac - done - sub=${words[j]:-} - [[ $sub =~ ^[a-z]+$ ]] || continue - for name in require remove update upgrade install uninstall rm; do - [[ $name == "$sub"* ]] \ - && block "Dependency changes need my explicit approval. Tell me the package and why, and I will run it." - done -done - -case " $norm " in - *"npm install"*|*"npm i "*|*"npm uninstall"*|*"npm update"*|*"npm ci"*|\ - *"yarn add"*|*"yarn remove"*|*"pnpm add"*|*"pnpm remove"*|*"pip install"*) - block "Package installs need my explicit approval." ;; -esac - -case " $norm " in - *"git push"*|*"git reset --hard"*|*"git clean -"*|*"git checkout -- "*|\ - *"git submodule"*|*"git filter-branch"*|*"git rebase"*) - block "Destructive or publishing git operations are mine to run." ;; -esac - -# rm with both a recursive and a force flag, in any spelling: -rf, -fr, -r -f, -Rf, -# --recursive --force. Its arguments end at a separator, at -- and at find's "{} +". -for ((i = 0; i < nw; i++)); do - case ${words[i]} in rm|*/rm) ;; *) continue ;; esac - rec=0 force=0 - for ((j = i + 1; j < nw; j++)); do - w=${words[j]} - case $w in - ';'|'&'|'|'|'('|')'|'`'|--|+) break ;; - --?*) [[ recursive == "${w#--}"* ]] && rec=1 - [[ force == "${w#--}"* ]] && force=1 ;; - -?*) [[ $w == *r* ]] && rec=1 - [[ $w == *f* ]] && force=1 ;; - esac - done - ((rec && force)) && block "Refusing destructive filesystem command." -done - -case " $norm " in - *"mkfs"*|*"chmod -r 777"*) - block "Refusing destructive filesystem command." ;; -esac - -case " $norm " in - *"doctrine-migrations migrate"*|*"doctrine-migrations execute"*|\ - *"fixtures:execute"*|*"schema:drop"*|*"schema:update"*) - block "Database-mutating commands need my approval. Show me the command and what it will change." ;; -esac - -case " $norm " in - *"development-enable"*|*"development-disable"*) - block "Toggling development mode changes committed config state. Ask me first." ;; -esac - -exit 0 diff --git a/.claude/hooks/guard-protected-paths.sh b/.claude/hooks/guard-protected-paths.sh deleted file mode 100644 index 6dcb4fa..0000000 --- a/.claude/hooks/guard-protected-paths.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# PreToolUse guard for Dotkernel projects. -# Blocks writes to vendored, generated, secret or dependency-manifest files. -# Pure bash, no jq — works in Git Bash on Windows. -# Exit 0 = allow, exit 2 = block (stderr is shown to Claude). - -set -u - -payload=$(cat) - -# Pull the target path out of tool_input without a JSON parser: "file_path" for -# Edit, Write and MultiEdit, "notebook_path" for NotebookEdit. -path_field() { - printf '%s' "$payload" \ - | tr -d '\n' \ - | sed -n 's/.*"'"$1"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' -} -raw_path=$(path_field file_path) -[ -z "$raw_path" ] && raw_path=$(path_field notebook_path) - -[ -z "$raw_path" ] && exit 0 - -# Normalise: unescape JSON backslashes, turn \ into /, drop a drive prefix, lowercase. -path=${raw_path//\\\\/\\} -path=${path//\\//} -path=${path#[A-Za-z]:} -lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') - -block() { - printf 'BLOCKED: %s\n%s\n' "$raw_path" "$1" >&2 - exit 2 -} - -case "$lower" in - */vendor/*|vendor/*) - block "vendor/ is Composer-managed. Change the dependency or your own code instead." ;; - */node_modules/*|node_modules/*) - block "node_modules/ is npm-managed." ;; - */migration/*|*/migrations/*) - block "Migrations are generated. Adjust the entity and regenerate with 'doctrine-migrations diff'." ;; - */data/cache/*|*/data/lock/*|*/data/oauth/*|data/cache/*|data/lock/*|data/oauth/*) - block "data/ holds generated cache, locks and keys. Never hand-edit." ;; - */log/*|log/*) - block "log/ is runtime output." ;; - */public/uploads/*|public/uploads/*) - block "public/uploads/ is user-uploaded content." ;; - *composer.json|*composer.lock|*package.json|*package-lock.json|*yarn.lock|*pnpm-lock.yaml) - block "Dependency manifests require explicit user approval. Propose the change in chat first." ;; - *.local.php|*/local.php|local.php|*/local.test.php|local.test.php) - block "Local config holds environment secrets and is git-ignored. Edit the .dist template and let the user apply it." ;; - *.phpcs-cache|*.phpunit.result.cache|*/.git/*) - block "Tool cache / git internals." ;; - *.png|*.jpg|*.jpeg|*.gif|*.svg|*.ico|*.zip|*.phar|*.key|*.pem) - block "Binary or key material." ;; -esac - -exit 0 diff --git a/.claude/hooks/markdown-lint.sh b/.claude/hooks/markdown-lint.sh deleted file mode 100644 index 84f3c8c..0000000 --- a/.claude/hooks/markdown-lint.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -# PostToolUse: markdownlint a .md file right after it is written. -# Report-only by design — it does NOT run --fix. Reformatting a file that Claude -# just wrote invalidates its in-memory copy and breaks the next targeted edit, -# so bulk fixing stays a deliberate end-of-task action. -# Exit 2 surfaces the violations to Claude immediately. -# Silent exit 0 when markdownlint-cli2 is not installed, so .claude/ stays -# drop-in with no npm requirement. - -set -u - -payload=$(cat) - -raw_path=$(printf '%s' "$payload" | tr -d '\n' \ - | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') - -[ -z "$raw_path" ] && exit 0 - -path=${raw_path//\\\\/\\} -path=${path//\\//} - -lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') - -case "$lower" in - *.md|*.markdown) ;; - *) exit 0 ;; -esac -case "$lower" in - */vendor/*|*/node_modules/*|*/.git/*|*/data/*|*/log/*) exit 0 ;; -esac -[ -f "$path" ] || exit 0 - -config="${CLAUDE_PROJECT_DIR:-.}/.claude/markdownlint.jsonc" -[ -f "$config" ] || exit 0 - -bin="" -if [ -x ./node_modules/.bin/markdownlint-cli2 ]; then - bin=./node_modules/.bin/markdownlint-cli2 -elif command -v markdownlint-cli2 >/dev/null 2>&1; then - bin=markdownlint-cli2 -fi -[ -z "$bin" ] && exit 0 - -if ! output=$("$bin" --config "$config" "$path" 2>&1); then - printf 'markdownlint violations in %s\n%s\n' "$path" "$output" >&2 - exit 2 -fi - -exit 0 diff --git a/.claude/hooks/normalize-file.sh b/.claude/hooks/normalize-file.sh deleted file mode 100644 index e436548..0000000 --- a/.claude/hooks/normalize-file.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env bash -# PostToolUse normaliser for Dotkernel projects. -# Enforces: UTF-8 without BOM, LF line endings, no trailing whitespace, -# exactly one trailing newline. Pure bash + sed + awk, no jq. -# Rewrites the file in place, so its permissions, owner and links survive. -# Exit 0 always — this fixes silently rather than blocking. - -set -u - -payload=$(cat) - -raw_path=$(printf '%s' "$payload" | tr -d '\n' \ - | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') - -[ -z "$raw_path" ] && exit 0 - -path=${raw_path//\\\\/\\} -path=${path//\\//} - -[ -f "$path" ] || exit 0 - -lower=$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]') - -# Skip binaries and anything not ours. -case "$lower" in - *.png|*.jpg|*.jpeg|*.gif|*.ico|*.svg|*.zip|*.phar|*.pdf|*.woff|*.woff2|*.ttf|*.eot|*.key|*.pem) - exit 0 ;; - */vendor/*|*/node_modules/*|*/.git/*|*/data/*|*/log/*) - exit 0 ;; -esac - -# Text files only. -case "$lower" in - *.php|*.phtml|*.twig|*.md|*.json|*.xml|*.neon|*.yml|*.yaml|*.sh|*.txt|*.dist|*.html|*.css|*.js|*.sql|*.editorconfig|*.gitattributes|*.gitignore) ;; - *) exit 0 ;; -esac - -changed="" -tmp=$(mktemp "${TMPDIR:-/tmp}/dk-normalize.XXXXXX") || exit 0 -trap 'rm -f "$tmp"' EXIT - -# Copy the fixed text back over the original. Writing through the existing file, rather -# than moving a new one into place, keeps its mode (an executable script stays -# executable), its owner, and any symlink or hard link to it. -write_back() { { cat "$tmp" > "$path"; } 2>/dev/null; } - -# 1. Strip UTF-8 BOM. -bom=$(printf '\357\273\277') -if [ "$(head -c 3 "$path" 2>/dev/null)" = "$bom" ]; then - tail -c +4 "$path" > "$tmp" && write_back && changed="${changed} BOM-removed" -fi - -# 2. CRLF -> LF, then a lone CR (classic Mac line ending) -> LF. -if LC_ALL=C grep -qU $'\r' "$path" 2>/dev/null; then - LC_ALL=C sed $'s/\r$//' "$path" | tr '\r' '\n' > "$tmp" && write_back \ - && changed="${changed} CRLF->LF" -fi - -# 3. Trailing whitespace (skip markdown: two trailing spaces are a hard line break). -case "$lower" in - *.md) ;; - *) - if LC_ALL=C grep -q '[[:space:]]$' "$path"; then - sed 's/[[:space:]]*$//' "$path" > "$tmp" && write_back \ - && changed="${changed} trailing-ws-stripped" - fi - ;; -esac - -# 4. Exactly one trailing newline: add a missing one, drop blank or whitespace-only lines -# at the end. A file with nothing but whitespace is left alone. -if [ -s "$path" ]; then - LC_ALL=C awk ' - /^[ \t\f\v]*$/ { held = held $0 "\n"; next } # blank: hold until a line follows - { printf "%s%s\n", held, $0; held = "" } # still held at the end: dropped - ' "$path" > "$tmp" - if [ -s "$tmp" ] && ! cmp -s "$tmp" "$path"; then - if [ "$(wc -c < "$tmp")" -gt "$(wc -c < "$path")" ]; then - fix=newline-added - else - fix=trailing-blank-lines-removed - fi - write_back && changed="${changed} ${fix}" - fi -fi - -if [ -n "$changed" ]; then - printf 'File hygiene applied to %s:%s\n' "$path" "$changed" >&2 -fi - -exit 0 diff --git a/.claude/hooks/php-lint.sh b/.claude/hooks/php-lint.sh deleted file mode 100644 index d902a12..0000000 --- a/.claude/hooks/php-lint.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# PostToolUse: syntax-check a PHP file right after it is written. -# Report-only by design — it does NOT reformat. Reformatting a file that Claude -# just wrote invalidates its in-memory copy and breaks the next targeted edit, -# so phpcbf is deliberately left to `composer cs-fix` / /dk-check at the end. -# Exit 2 surfaces the parse error to Claude immediately. - -set -u - -payload=$(cat) - -raw_path=$(printf '%s' "$payload" | tr -d '\n' \ - | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') - -[ -z "$raw_path" ] && exit 0 - -path=${raw_path//\\\\/\\} -path=${path//\\//} - -case "$path" in - *.php) ;; - *) exit 0 ;; -esac -case "$path" in - */vendor/*|*/node_modules/*) exit 0 ;; -esac -[ -f "$path" ] || exit 0 -command -v php >/dev/null 2>&1 || exit 0 - -if ! output=$(php -l "$path" 2>&1); then - printf 'PHP syntax error in %s\n%s\n' "$path" "$output" >&2 - exit 2 -fi - -exit 0 diff --git a/.claude/hooks/session-start.sh b/.claude/hooks/session-start.sh deleted file mode 100644 index fbcf056..0000000 --- a/.claude/hooks/session-start.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -# SessionStart: print a short briefing that becomes part of Claude's context. -# Detects which Dotkernel project this is and what is not set up yet. -# Everything here is read-only. Keep the output compact. - -set -u -cd "${CLAUDE_PROJECT_DIR:-.}" 2>/dev/null || exit 0 - -echo "## Project state" - -# --- which Dotkernel project? --- -if [ -f composer.json ]; then - pkg=$(sed -n 's/.*"name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' composer.json | head -1) - ns=$(grep '": "src/' composer.json 2>/dev/null | grep -v '"Core' | head -1 \ - | sed 's/^[^"]*"\([A-Za-z]*\).*/\1/') - variant="unknown" - case "$pkg" in - */api) variant="API (REST/HAL)" ;; - */admin) variant="Admin (templated, forms)" ;; - */frontend) variant="Frontend (templated, forms)" ;; - */light) variant="Light (minimal starter)" ;; - */queue) variant="Queue (CLI/worker)" ;; - esac - if [ "$variant" = "unknown" ]; then - hal=0 form=0 - grep -q 'mezzio/mezzio-hal' composer.json && hal=1 - grep -q 'laminas/laminas-form' composer.json && form=1 - case "$hal$form" in - 10) variant="API-style (has mezzio-hal)" ;; - 01) variant="templated-style (has laminas-form)" ;; - 11) variant="unclear (has mezzio-hal and laminas-form; infer the parent from the PSR-4 roots)" ;; - esac - fi - echo "- package: ${pkg:-unknown} | variant: ${variant}" - [ -n "$ns" ] && echo "- root namespace: ${ns}" - guards=config/autoload/authorization-guards.global.php - if [ -f "$guards" ]; then - policy=$(sed -n "s/.*protection_policy.*\(POLICY_[A-Z]*\).*/\1/p" "$guards" | head -1) - echo "- authorization: guards + RBAC (${guards##*/}${policy:+, $policy})" - [ "$policy" = POLICY_ALLOW ] && echo " unlisted routes are PUBLIC — every new route needs a guard rule" - elif [ -f config/autoload/authorization.global.php ]; then - echo "- authorization: RBAC (authorization.global.php) — unlisted routes are denied" - fi -fi - -# --- git --- -# Ask git rather than test for a .git directory: in a worktree or a submodule checkout -# .git is a file. -if command -v git >/dev/null 2>&1 \ - && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; then - eol_bad=$(git ls-files --eol 2>/dev/null | grep -c 'w/crlf' || true) - [ "${eol_bad:-0}" -gt 0 ] && echo "- WARNING: ${eol_bad} tracked file(s) have CRLF in the worktree; run /dk-hygiene" - top=$(git rev-parse --show-toplevel 2>/dev/null) - if [ -f "$top/.gitmodules" ]; then - subs=$(git config -f "$top/.gitmodules" --get-regexp '^submodule\..*\.path$' 2>/dev/null \ - | cut -d' ' -f2- | tr '\n' ' ') - subs=${subs% } - case " $subs " in - *" src/Core "*) echo "- git submodules: ${subs}. Core is one: commit inside src/Core, then bump the pointer here" ;; - " ") ;; - *) echo "- git submodules: ${subs}" ;; - esac - fi -fi - -# --- setup completeness --- -[ -f composer.json ] && [ ! -d vendor ] \ - && echo "- vendor/ missing — dependencies are not installed (run /dk-bootstrap)" - -for d in config/autoload/*.dist config/*.dist; do - [ -e "$d" ] || continue - target=${d%.dist} - [ -f "$target" ] && continue - case "$target" in - config/development.config.php) continue ;; # managed by development-mode, not copied by hand - esac - echo "- missing ${target} (copy from ${d})" -done - -for d in docs/features documentation/features; do - [ -d "$d" ] || continue - n=$(ls -1 "$d"/*.md 2>/dev/null | grep -vc '/README\.md$' || true) - echo "- ${d}/: ${n:-0} feature doc(s) — read the relevant one before adding behaviour there" -done - -[ -f config/development.config.php ] && echo "- development mode is ENABLED" -[ -f data/cache/config-cache.php ] && echo "- config cache present; clear it after config edits" - -exit 0 diff --git a/.claude/plan-code-review.md b/.claude/plan-code-review.md deleted file mode 100644 index d77f964..0000000 --- a/.claude/plan-code-review.md +++ /dev/null @@ -1,786 +0,0 @@ -# Plan: dotkernel/light 1.6.0 - -This plan covers the next release of Dotkernel Light, a Mezzio skeleton application. The work branch is `upgrade`, and the base is branch `1.0` at commit `aaf20d1` (`git describe --tags`: `1.5.0-17-gaaf20d1`). The maintainer asked for 1.6.0 if the release has no backward-incompatible changes, and for 2.0.0 otherwise. After the second review, the target is 1.6.0. The plan was first written on 2026-12-04 and checked again on the same day with PHP 8.5.13. Implementation started on 2026-12-04. The status table shows the state of each item. - -## Implementation status - -| Item | State | Notes | -| --- | --- | --- | -| V1 `composer.json` requirements | Done by maintainer | Uncommitted. `dot-errorhandler` is now `^5.1.0 \|\| ^6.0.0` | -| V2 PHP 8.6 in the workflows | Done | Qodana matrix has 8.6. The PHPStan job id is `phpstan` | -| V3 PHPStan level 8 | Done | `composer static-analysis`: no errors | -| V4 PHPUnit major version | Decision: stay on 12 | PHPUnit 13 needs PHP `>=8.4.1` | -| V5 `phpunit.xml` flags | Done | `failOn*` flags added, `stopOnError` and `` removed | -| V6 Release line | No change | 1.6.0 is released from branch `1.0` | -| V7 Node.js 20 in the build matrix | Open, optional | Needs a check of the Node.js release schedule | -| V8 Debug lines in `public/index.php` | Done by maintainer | `git diff public/index.php` is empty | -| F1 Page handler without a matched route | Done | Two new tests | -| F2 Page routes only in `local.php` | Done | Without `local.php`, all three routes exist. With the old `local.php`, the site works | -| F3 Cookies written unmasked to the error log | Done | A forced error gives status 500 and `PHPSESSID=******` in the log | -| F4 Unused `PageService` | Decision: keep | No change | -| F5 Stale config cache after `composer update` | Done by maintainer | Verified: `composer update` deleted `data/cache/config-cache.php` | -| F6 Tests double final classes | Done | `PageHandlerTest.php` renamed to `GetPageViewHandlerTest.php` with `git mv` | -| F7 Factories use `assert()` | Open, waits for a decision | Not implemented | -| F8 Malformed docblocks in the config providers | Done | | -| F9 Outdated docs link in `error-handling.global.php` | Done | Link points to v6. Published URL not verified | -| F10 Test coverage gaps | Done | 20 tests, 57 assertions. Fixture container in `test/Unit/Fixture` | -| T20 Remove `laminas-servicemanager` | Not applicable | See [V9](#v9-laminas-servicemanager-is-a-runtime-requirement) | -| CHANGELOG | Done | 1.3.0, 1.4.0, 1.5.0 and 1.6.0 added. 1.6.0 date is `TBD` | -| README | Done | PHP 8.6, route location, automatic cache clearing | -| D1 to D11 documentation | Done | Branch `upgrade-1.6` in `light-documentation`. `mkdocs build` not run, because `mkdocs` is not installed | - -## Decision: version 1.6.0 - -Light is a skeleton. Users run `composer create-project` and then merge later upstream changes into their own project. A change is breaking when a project made from 1.5.0 must change its own code or config to take the change. - -The first version of this plan chose 2.0.0 for two reasons. Both reasons are now gone: - -1. The maintainer keeps `PageService` (F4). No class, config key, route or template of Light is removed. -2. The maintainer changed the range to `"dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0"`. A project that cannot take `dot-errorhandler` 6 yet can stay on 5.1 with the same Light release. The Light config works without changes on 6.0.0. The default config uses a boolean `loggerEnabled` and a PSR-3 logger (`Dot\Log\Logger` extends `AbstractLogger`). It does not subclass any `dot-errorhandler` class. - -The changes in this plan are additive or internal: - -- New direct requirements (`dot-log`, `laminas-diactoros`, `laminas-servicemanager`) were already installed through `dot-errorhandler` 5. -- PHP 8.6 is added. No PHP version is removed. -- F2 moves the page routes into `Light\Page\ConfigProvider`. The config aggregator merges the routes from an existing `local.php`, so they still work. -- F1 replaces a PHP `Error` with a `RuntimeException` for a request without a matched route. Such a request does not reach the handler in the default pipeline. - -The project has a precedent. Light 1.5.0 raised `dot-errorhandler` from 4 to 5 and removed PHP 8.2 in a minor release (`light-documentation`, `docs/book/v1/upgrading/UPGRADE-1.5.md`). - -Two risks remain. Write them in the upgrade page (D10): - -- `composer update` selects `dot-errorhandler` 6 by default. A project with its own error handler code must check the `dot-errorhandler` 6 upgrade guide, or pin `^5.1`. -- After F2, a project that removed a page route from its `local.php` gets the route back from `Light\Page\ConfigProvider`, if the project merges that file without review. - -Verified on 2026-12-04: the maintainer installed `dot-errorhandler` 5.1.0 for a test. With 5.1.0, the container builds `ErrorHandlerInterface` as `Dot\ErrorHandler\LogErrorHandler` with the `Dot\Log\Logger` service. `/` and `/page/about` return 200, and `/missing` returns 404. `composer static-analysis` and `composer test` show only the two known F6 errors, the same as with 6.0.0. A forced error with a written log line was not tested. - -## Baseline - -Commands were run on branch `upgrade` after the maintainer's `composer update`. - -| Check | Result | -| --- | --- | -| `php -v` | PHP 8.5.13. No other PHP version is installed (`/usr/bin/php` only) | -| `git describe --tags` | `1.5.0-17-gaaf20d1` | -| `composer cs-check` | Pass | -| `composer twig-cs-check` | Pass, 7 files | -| `composer static-analysis` | **Fail.** 2 errors, both `method.unresolvableReturnType` | -| `composer test` | **Fail.** `ClassIsFinalException` in `PageHandlerTest::testHandle`. `stopOnError="true"` hides the second error in `RoutesDelegatorTest::testWillInvoke` | -| `curl http://localhost:8080` | `/`, `/page/about` and `/page/who-we-are` return 200. `/missing` returns 404 | -| `data/cache/config-cache.php` | Deleted by the new `@clear-config-cache` script | -| Coverage driver | None. `php -m` shows no `pcov` and no `xdebug` | -| Mutation testing | Not installed | - -Installed versions that matter for this plan: `mezzio/mezzio` 3.29.0, `mezzio/mezzio-router` 4.3.0, `laminas/laminas-servicemanager` 4.6.0, `dotkernel/dot-errorhandler` 6.0.0, `dotkernel/dot-log` 5.4.0, `phpunit/phpunit` 12.5.47 and `phpstan/phpstan` 2.4.0. - -What could not be checked here: - -- PHP 8.3, 8.4 and 8.6. Only 8.5 is installed. CI covers the others. -- The lowest dependency versions, except `dot-errorhandler` 5.1.0, which the maintainer installed for a test. -- The `mezzio-router` version that 1.5.0 used. `composer.lock` is in `.gitignore`, so git has no record of it. Thus it is unknown whether 1.5.0 already had the final `Route` and `RouteResult` classes. -- A Laminas backward-compatibility check does not apply. Light is a `project`, not a library. The decision above comes from a manual review. - -## Done by the maintainer - -These uncommitted edits exist in the working tree. Do not repeat them or revert them: - -```diff -- "php": "~8.3.0 || ~8.4.0 || ~8.5.0", -- "dotkernel/dot-errorhandler": "^5.0.0", -+ "php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0", -+ "dotkernel/dot-log": "^5.4.0 || ^6.0.0", -+ "dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0", -+ "laminas/laminas-diactoros": "^3.10.0", -+ "laminas/laminas-servicemanager": "^4.6.0", -... - "post-update-cmd": [ -- "php bin/composer-post-install-script.php" -+ "php bin/composer-post-install-script.php", -+ "@clear-config-cache" -+ ], -+ "post-install-cmd": [ -+ "@clear-config-cache" -``` - -The edits also raise the lower bounds of the other requirements, and they add `- "8.6"` to the PHP matrix of `codecov.yml` and `static-analysis.yml`. The debug lines in `public/index.php` are removed. - -The maintainer kept `"dotkernel/dot-log": "^5.4.0 || ^6.0.0"`. Today, `^6.0.0` matches only `6.0.x-dev`, which Composer does not install with the default `minimum-stability`. Check the range again when `dot-log` 6.0.0 is released. - -No edits are still needed in `composer.json`. - -## Findings - -### V1. Dependency review - -Location: `composer.json`. - -Evidence: each claim comes from `vendor/*/composer.json` or `composer show -a`. - -| Requirement | State | Comment | -| --- | --- | --- | -| `php` `~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0` | Correct | All Mezzio packages in `vendor/` allow the same range | -| `dotkernel/dot-errorhandler` `^5.1.0 \|\| ^6.0.0` | Correct, both majors tested | 5.1.0 requires PHP `~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0`, `dot-log ^5.3` and `laminas-diactoros ^3.8.0`. 6.0.0 is installed. Its `CHANGELOG.md` still says `6.0.0 - TBD`. Report this to the package | -| `dotkernel/dot-log` `^5.4.0 \|\| ^6.0.0` | Correct | `config/autoload/error-handling.global.php` uses `Dot\Log\Logger` and `Dot\Log\Formatter\Json`. See the note about `^6.0.0` above | -| `laminas/laminas-diactoros` `^3.10.0` | Needed | `GetIndexViewHandler` and `GetPageViewHandler` use `Laminas\Diactoros\Response\HtmlResponse` | -| `laminas/laminas-servicemanager` `^4.6.0` | Needed | `config/container.php` creates `Laminas\ServiceManager\ServiceManager` | -| `mezzio/mezzio-router` | Not declared, correct | Four Mezzio packages require it. The code uses only `RouteResult::getMatchedRouteName()`, which exists in 3.x and 4.x | -| `phpunit/phpunit` `^12.5.23` | Correct | See V4 | -| `roave/security-advisories` `dev-master` | Correct | | - -Declared but unused: none found. `laminas-component-installer` is a Composer plugin, and `config.allow-plugins` lists it. - -### V2. Workflows - -Location: `.github/workflows/qodana_code_quality.yml`. - -Evidence: the matrix stops at PHP 8.5, but the other workflows test 8.6. `continuous-integration.yml` uses `laminas/workflow-continuous-integration`, which reads the PHP range from `composer.json`. The repository has no `.laminas-ci.json`. The action versions are already `actions/checkout@v7`, `actions/cache@v6`, `codecov/codecov-action@v7` and `actions/setup-node@v7`. - -Before: - -```yaml - php-versions: [ '8.3', '8.4', '8.5' ] -``` - -After: - -```yaml - php-versions: [ '8.3', '8.4', '8.5', '8.6' ] -``` - -Why: all supported PHP versions get the same checks. - -Also in `static-analysis.yml`, the job id is `mutation`, but the job runs PHPStan. Rename it to `phpstan`. This change does not affect the badge, because the badge uses the workflow file name. - -### V3. PHPStan level 8 - -Location: `phpstan.neon`. - -Evidence: the level is already 8. `composer static-analysis` reports two errors: - -| File | Line | Identifier | Fix | -| --- | --- | --- | --- | -| `test/Unit/Page/Handler/PageHandlerTest.php` | 36 | `method.unresolvableReturnType` | F6: use a real `RouteResult` | -| `test/Unit/Page/RoutesDelegatorTest.php` | 36 | `method.unresolvableReturnType` | F6: use a real `Route` | - -Why: PHPStan cannot resolve a stub of a final class. Both errors have the same cause as the test failures. No ignores or baseline are necessary. - -### V4. PHPUnit major version - -Location: `composer.json`, `require-dev`. - -Evidence: `composer show -a phpunit/phpunit 13.5.1` requires `php >=8.4.1`. Version 12.5.47 requires `php >=8.3`. - -Decision: stay on `^12.5.23`. PHPUnit 13 would remove PHP 8.3 support. The tests already use no annotations and no data providers. So no syntax migration is necessary now. Close the open Renovate branch `renovate/phpunit-phpunit-13.x`, or let it wait until PHP 8.3 support ends. - -### V5. `phpunit.xml` flags - -Location: `phpunit.xml`. - -Evidence: `stopOnError="true"` hid the second test error in the baseline. The file has no `failOn*` flags, and it has an empty `` element. - -Before: - -```xml - displayDetailsOnPhpunitDeprecations="true" - stopOnError="true"> -``` - -After: - -```xml - displayDetailsOnPhpunitDeprecations="true" - failOnDeprecation="true" - failOnNotice="true" - failOnWarning="true" - failOnRisky="true" - failOnPhpunitDeprecation="true"> -``` - -Also remove ``. The `` element already sets the coverage scope. - -Why: all failures are visible in one run, and CI fails on deprecations. This includes deprecations from vendor code on PHP 8.6. If a vendor deprecation blocks CI on 8.6, report it upstream. Do not turn off the flag. - -Not verified: no PHP 8.6 is installed here, so the vendor deprecations on 8.6 are unknown. - -### V6. Release line - -1.6.0 is a minor release, so it comes from branch `1.0`. The README badges (`?branch=1.0`), the LICENSE link (`blob/1.0`), the Qodana branch list, `SECURITY.md` (`1.x` supported) and `OSSMETADATA` (`osslifecycle=active`) stay the same. - -### V7. Node.js 20 in the build matrix - -Location: `.github/workflows/build-assets.yml`, README. - -Evidence: the matrix is `["20", "22", "24", "26"]`. The installed Vite 8.0.14 requires Node.js `^20.19.0 || >=22.12.0`, and `package.json` copies that range. - -Recommendation: I am not certain of the current Node.js 20 status. You may want to verify it on the Node.js release page. If Node.js 20 is end of life, remove it from the matrix and change the README range. Keep `engines` the same as Vite's range. - -### V8. Debug lines in `public/index.php` - -Done by the maintainer. `git diff public/index.php` is empty. - -### V9. `laminas-servicemanager` is a runtime requirement - -Location: `composer.json`, `config/container.php`. - -Evidence: the skill item T20 removes `laminas-servicemanager` from packages. Light is an application, and `config/container.php` creates the container with `new ServiceManager($dependencies)`. Also, `dotkernel/dot-log` 5.4.0 and `laminas/laminas-validator` 3.21.0 require `laminas/laminas-servicemanager` `^4.0` and `^4.4.0`. - -Decision: do not remove it. An application must have one container, and the dependencies install the Service Manager in all cases. Keep it declared, because the application uses it directly. - -### F1. Page handler fails without a matched route - -Severity: low. In the current pipeline, `DispatchMiddleware` calls the handler only after a route matched. - -Location: `src/Page/src/Handler/GetPageViewHandler.php:24`. - -Evidence: a scratch script called the handler with real objects: - -```text -no RouteResult: Error: Call to a member function getMatchedRouteName() on null -failed RouteResult: TypeError: ...render(): Argument #1 ($name) must be of type string, false given -``` - -`RouteResult::getMatchedRouteName()` returns `false|string`, and `TemplateRendererInterface::render()` takes a `non-empty-string`. - -Before: - -```php -public function handle(ServerRequestInterface $request): ResponseInterface -{ - $template = $request->getAttribute(RouteResult::class)->getMatchedRouteName(); - - return new HtmlResponse( - $this->template->render($template) - ); -} -``` - -After: - -```php -public function handle(ServerRequestInterface $request): ResponseInterface -{ - $routeResult = $request->getAttribute(RouteResult::class); - $routeName = $routeResult instanceof RouteResult ? $routeResult->getMatchedRouteName() : false; - if ($routeName === false || $routeName === '') { - throw new RuntimeException('The page handler needs a matched route. Route the request before dispatch.'); - } - - return new HtmlResponse( - $this->template->render($routeName) - ); -} -``` - -Why: the error message names the cause. The prototype passes PHPStan level 8 and phpcs, and the scratch script then shows `RuntimeException` in both cases. - -### F2. Page routes exist only in `local.php` - -Severity: medium. - -Location: `config/autoload/local.php.dist`, `src/Page/src/RoutesDelegator.php:27`. - -Evidence: the `routes` key is set only in `local.php.dist`. `local.php` is git-ignored, and `bin/composer-post-install-script.php` does not overwrite an existing copy. A scratch script built the container twice: - -```text -with local routes: /, /page/about, /page/who-we-are -without local routes: / -``` - -Effects: - -- A deployment without the same `local.php` has no page routes, and the pages return 404. -- A new page in `local.php.dist` does not reach installations that already have a `local.php`. - -Before (`config/autoload/local.php.dist`): - -```php -return [ - 'application' => [ - 'url' => $baseUrl, - ], - 'routes' => [ - 'page' => [ - 'about' => 'about', - 'who-we-are' => 'who-we-are', - ], - ], -]; -``` - -After (`config/autoload/local.php.dist`): - -```php -return [ - 'application' => [ - 'url' => $baseUrl, - ], -]; -``` - -After (`src/Page/src/ConfigProvider.php`): - -```php -public function __invoke(): array -{ - return [ - 'dependencies' => $this->getDependencies(), - 'routes' => $this->getRoutes(), - 'templates' => $this->getTemplates(), - ]; -} - -/** - * @return array{page: array} - */ -public function getRoutes(): array -{ - return [ - 'page' => [ - 'about' => 'about', - 'who-we-are' => 'who-we-are', - ], - ]; -} -``` - -Why: routes are part of the application, not of the environment. The config aggregator merges arrays, so the routes in an existing `local.php` still work. I also checked a collision with the Mezzio `routes` key: `ApplicationConfigInjectionDelegator::injectRoutesFromConfig()` skips entries without `path` and `middleware`, and Light does not register that delegator. No defect was found there. - -### F3. Cookies are written unmasked to the error log - -Severity: high for projects that add sessions or authentication. - -Location: `config/autoload/error-handling.global.php`, `ServerProvider`. - -Evidence: `log/error-log-2026-12-04.log`, line 1, contains the full `HTTP_COOKIE` value, including `cookie_consent_user_consent_token`. A scratch script ran the provider with the current config and with the recommended config: - -```text -current Light config (no processor): {"HTTP_COOKIE":"PHPSESSID=abc123; theme=dark","PHP_AUTH_PW":"secret"} -recommended: {"HTTP_COOKIE":"PHPSESSID=******; theme=dark","PHP_AUTH_PW":"******"} -``` - -Before: - -```php -ServerProvider::class => [ - 'enabled' => true, -// 'processor' => [ -// ... -// ], -], -``` - -After: - -```php -ServerProvider::class => [ - 'enabled' => true, - 'processor' => [ - 'class' => ServerProcessor::class, - 'replacementStrategy' => ReplacementStrategy::Full, - 'sensitiveParameters' => [ - 'phpsessid', - 'php_auth_pw', - 'http_authorization', - 'http_proxy_authorization', - ], - ], -], -``` - -Also copy the 6.0 dist defaults for the disabled providers: real `use` statements in place of the commented FQCNs, and `authorization` and `proxy-authorization` in the `HeaderProvider` `sensitiveParameters`. Another option is to disable `ServerProvider`, as the 6.0 dist file does. - -Why: logs often go to other systems, and a session id in a log can be used to take over a session. The `ServerProcessor` masks each cookie name that is in `sensitiveParameters`. Names are compared in lower case. - -Verified with `dot-errorhandler` 5.1.0 too: the same config gives `{"HTTP_COOKIE":"PHPSESSID=***; theme=dark","PHP_AUTH_PW":"*"}`. The mask has the length of the original value in both versions. - -### F4. `PageService` is unused - -Decision by the maintainer: keep `PageService`, `PageServiceInterface`, `PageServiceFactory` and their test. No change. - -### F5. Stale config cache after `composer update` - -Done by the maintainer. The `post-update-cmd` and `post-install-cmd` scripts now run `@clear-config-cache`. After the maintainer's `composer update`, `data/cache/` contains only `.gitignore` and `twig/`, and the site works. - -### F6. Tests double final classes - -Severity: high for the release. `composer check` fails. - -Location: `test/Unit/Page/Handler/PageHandlerTest.php`, `test/Unit/Page/RoutesDelegatorTest.php`. - -Evidence: `Mezzio\Router\RouteResult` and `Mezzio\Router\Route` are `final` in `mezzio-router` 4.3.0. PHPUnit throws `ClassIsFinalException`, and PHPStan reports `method.unresolvableReturnType`. - -Also in `PageHandlerTest`: - -- `testWillInstantiate` makes a stub of the class under test. The test checks PHPUnit, not the handler. -- The file name does not match the class name `GetPageViewHandler`. - -Before (`PageHandlerTest::testHandle`, part): - -```php -$routeResult = $this->createStub(RouteResult::class); -$routeResult - ->method('getMatchedRouteName') - ->willReturn($routeName); -``` - -After: rename the file to `test/Unit/Page/Handler/GetPageViewHandlerTest.php`. - -```php -public function testHandleRendersTemplateNamedAfterMatchedRoute(): void -{ - $routeName = 'page::about'; - $route = new Route('/page/about', $this->createStub(MiddlewareInterface::class), ['GET'], $routeName); - $request = (new ServerRequest())->withAttribute(RouteResult::class, RouteResult::fromRoute($route)); - - $template = $this->createMock(TemplateRendererInterface::class); - $template->expects($this->once()) - ->method('render') - ->with($routeName) - ->willReturn('

' . $routeName . '

'); - - $response = (new GetPageViewHandler($template))->handle($request); - - $this->assertInstanceOf(HtmlResponse::class, $response); - $this->assertSame('

' . $routeName . '

', (string) $response->getBody()); -} -``` - -Before (`RoutesDelegatorTest`, part): - -```php -$app->method('get')->willReturn($this->createStub(Route::class)); -$app - ->expects($this->exactly(1)) - ->method('get') - ->willReturnCallback(function (...$args) use ($routeUri, $templateName) { - $this->assertSame($routeUri, $args[0]); - $this->assertSame([GetPageViewHandler::class], [$args[1]]); - $this->assertSame($templateName, $args[2]); - }); -``` - -After: - -```php -public function testRegistersOneGetRoutePerConfiguredPage(): void -{ - $container = $this->createStub(ContainerInterface::class); - $container->method('get')->willReturn([ - 'routes' => [ - 'page' => ['about' => 'about'], - ], - ]); - - $route = new Route( - '/page/about', - $this->createStub(MiddlewareInterface::class), - ['GET'], - 'page::about' - ); - - $app = $this->createMock(Application::class); - $app->expects($this->once()) - ->method('get') - ->with('/page/about', GetPageViewHandler::class, 'page::about') - ->willReturn($route); - - $result = (new RoutesDelegator())($container, Application::class, static fn (): Application => $app); - - $this->assertSame($app, $result); -} -``` - -Why: real value objects remove the doubles of final classes. `with()` replaces the callback, so a wrong argument now fails with a clear diff. Both prototypes pass PHPUnit 12.5.47 (2 tests, 9 assertions) and PHPStan level 8 in a scratch directory. - -### F7. Factories use `assert()` as a type check - -Severity: low. - -Location: `src/App/src/Factory/GetIndexViewHandlerFactory.php:25`, `src/Page/src/Factory/GetPageViewHandlerFactory.php:25`, `src/App/src/RoutesDelegator.php:18`, `src/Page/src/RoutesDelegator.php:25`. - -Evidence: with `zend.assertions=-1`, which is the usual production value, PHP does not run `assert()`. The typed constructor parameters still stop a wrong service with a `TypeError`. Thus no bug exists, but the check in the factory is not the real check. `dot-errorhandler` 6 made the same change ("Service checks no longer depend on `zend.assertions`"). - -Before: - -```php -$template = $container->get(TemplateRendererInterface::class); -assert($template instanceof TemplateRendererInterface); -``` - -After: - -```php -$template = $container->get(TemplateRendererInterface::class); -if (! $template instanceof TemplateRendererInterface) { - throw new InvalidArgumentException( - sprintf('Service "%s" must implement %s', TemplateRendererInterface::class, TemplateRendererInterface::class) - ); -} -``` - -Why: the error names the service, and the check runs in every environment. This is optional. If the maintainer rejects it, keep the current code. - -### F8. Malformed docblocks in the config providers - -Severity: nit. - -Location: `src/App/src/ConfigProvider.php:14`, `src/Page/src/ConfigProvider.php:17,31,56`. - -Evidence: the line after `/**` starts with `@return array{`, without a leading `*`. - -Before: - -```php - /** - @return array{ -``` - -After: - -```php - /** - * @return array{ -``` - -Why: the other docblocks in the same files use this form. - -Not verified: I did not test whether PHPStan reads these tags. - -### F9. Outdated docs link in `error-handling.global.php` - -Severity: nit. - -Location: `config/autoload/error-handling.global.php:9`. - -Before: - -```php - * Read more about providers/processors here: https://docs.dotkernel.org/dot-errorhandler/v4/extra/introduction/ -``` - -After: - -```php - * Read more about providers/processors here: https://docs.dotkernel.org/dot-errorhandler/v6/extra/introduction/ -``` - -Not verified: the package has `docs/book/v6/extra/`, but I did not check that the published URL exists. The range also allows 5.1, so a link to the versions overview is another option. - -### F10. Test coverage gaps - -Location: `test/Unit`. - -Evidence: 14 tests in 5 files. No test covers these classes: - -| Class | Branches without a test | -| --- | --- | -| `Light\App\RoutesDelegator` | Registers `/` with the name `app::index` | -| `Light\App\Handler\GetIndexViewHandler` | Renders `app::index` | -| `Light\App\Factory\GetIndexViewHandlerFactory` | Builds the handler from the container | -| `Light\Page\Factory\GetPageViewHandlerFactory` | Builds the handler from the container | -| `Light\Page\Handler\GetPageViewHandler` | F1: no `RouteResult`, and a failed `RouteResult` | -| `Light\Page\ConfigProvider` | F2: the `routes` key | - -Recommendations: - -- Add one test for each row. Use real objects (`ServerRequest`, `Route`, `RouteResult`) and a small PSR-11 fixture container in `test/Unit/Fixture`. Use mocks only for `TemplateRendererInterface`. -- Rename the `setup()` methods in both `ConfigProviderTest` files to `setUp()`. PHP method names are case-insensitive, so the current code works. -- Install `pcov` locally for coverage. CI already uses `coverage: pcov`. -- Optional: add `infection/infection` in a later release. - -## Documentation - -### This repository - -| File | Required change | -| --- | --- | -| `README.md`, Requirements | `PHP 8.3, 8.4, 8.5 or 8.6 (~8.3.0 \|\| ~8.4.0 \|\| ~8.5.0 \|\| ~8.6.0)`. "All four versions are covered by CI" | -| `README.md`, Installing | Remove "the page routes are defined here and nowhere else" (F2) | -| `README.md`, Running the Application | Say that `composer install` and `composer update` now clear the config cache (F5) | -| `README.md`, What's Inside | Nothing. The table already names Laminas Service Manager and Diactoros | -| `README.md`, Node.js | Only if V7 removes Node.js 20 | -| `SECURITY.md` | Nothing. `1.x` stays supported | -| `config/autoload/error-handling.global.php` | F3 and F9 | - -### Repository `light-documentation` - -Location: `/var/www/html/dotkernel/light-documentation`, branch `main`, commit `370ed55`. The repository has one version folder, `docs/book/v1`. Because the release is 1.6.0, keep `current_version: v1` and add no `v2` folder. The repository also has an untracked `AUDIT.md` (510 lines) from 2026-09-18 about the 1.5.0 content. This plan does not repeat its items. - -| Id | Page | Required change | -| --- | --- | --- | -| D1 | `docs/book/index.md` | The file is not a symlink. It contains only the text `# ../../README.md`, and the repository has no root `README.md`. Thus the home page shows that path as its title. Replace it with real content, or with a symlink to a file that exists | -| D2 | `v1/introduction/server-requirements.md` | Heading `## PHP: 8.3, 8.4 or 8.5` and the FAQ answer: add 8.6. The note "the versions declared by `composer.json` in Dotkernel Light 1.5.0" becomes 1.6.0, with "PHP 8.6 was added in release 1.6.0" | -| D3 | `v1/introduction/packages.md` | "The six direct Composer dependencies" becomes nine. Add `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager`. Change the FAQ answer "Six" to "Nine" | -| D4 | `v1/introduction/request-lifecycle.md`, step 6 | The snippet `$request->getAttribute(RouteResult::class)->getMatchedRouteName()` changes with F1. Show the new check, or describe it in one sentence | -| D5 | `v1/how-tos/routing.md` | "Those are being declared in the file `config/autoload/local.php`" and the FAQ answer: the routes are in `src/Page/src/ConfigProvider.php`, `getRoutes()` (F2). Say that `local.php` can still add routes | -| D6 | `v1/how-tos/create-pages.md` | "Open `config/autoload/local.php` and locate the **routes** key" and the FAQ answer: change to `src/Page/src/ConfigProvider.php` (F2) | -| D7 | `v1/introduction/file-structure.md` | `composer-post-install-script.php` line: the hook list now also clears the config cache. `local.php.dist` line: "overwrite application name and URL" is wrong already, because the file sets only `application.url`. Change it to "set the application URL" | -| D8 | `v1/installation/running-the-application.md` | Add that `composer install` and `composer update` clear the config cache. Keep the note about `sudo` | -| D9 | `v1/installation/composer.md`, `faq.md` | No change found by the search. Read both again after D5 to D8 | -| D10 | New `v1/upgrading/UPGRADE-1.6.md` | Same structure as `UPGRADE-1.5.md`: Summary, Details, Important updates, Other updates. Content: the table below | -| D11 | `mkdocs.yml` | Add `"Upgrading from 1.5 to 1.6": v1/upgrading/UPGRADE-1.6.md` under `Upgrading` | - -Content for D10: - -| Change | Symptom | Fix | -| --- | --- | --- | -| PHP 8.6 support added | None | None | -| `dot-log`, `laminas-diactoros` and `laminas-servicemanager` are direct requirements | None, they were installed before | Copy the three lines into your `composer.json` | -| `dot-errorhandler` range is `^5.1.0 \|\| ^6.0.0`, and `composer update` selects 6 | `InvalidArgumentException` from `LogErrorHandlerFactory`, only with custom error handler code or config | Follow the `dot-errorhandler` v6 upgrade guide, or pin `^5.1` | -| Page routes moved to `Light\Page\ConfigProvider` (F2) | A route that you removed from `local.php` comes back | Remove it from `getRoutes()` in your copy | -| Composer clears the config cache after install and update (F5) | None | Copy the two scripts into your `composer.json` | -| `ServerProvider` masks session and authorization values (F3) | Masked values in new log lines | Add your own cookie names to `sensitiveParameters` | - -## CHANGELOG - -Add these sections above `## 1.2.0`, newest first. The file uses `*` bullets. Keep that style. Renovate updates are grouped in one line per release. - -```markdown -## 1.6.0 - TBD - -### Changed - -* Widened `dotkernel/dot-errorhandler` to `^5.1.0 || ^6.0.0` -* Bumped the lower bounds of `laminas/*`, `mezzio/*` and dev dependencies -* Moved the page routes from `local.php.dist` to `Light\Page\ConfigProvider` -* `GetPageViewHandler` throws a `RuntimeException` when no route matched -* Masked session and authorization values in the error log -* Composer clears the configuration cache after install and update -* Tests use real `Route` and `RouteResult` objects -* PHPUnit fails on deprecations, notices, warnings and risky tests -* Vite config and npm vulnerability fixes by [@georgeStan](https://github.com/georgeStan) in [#120](https://github.com/dotkernel/light/pull/120) and [#123](https://github.com/dotkernel/light/pull/123) -* Aligned README with dotkernel.com wording by [@arhimede](https://github.com/arhimede) in [#119](https://github.com/dotkernel/light/pull/119) -* Renovate dependency and action updates in #118 to #127 - -### Added - -* Support for PHP 8.6 -* `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager` as direct requirements -* Tests for the App module, the factories and the page routes - -### Deprecated - -* Nothing - -### Removed - -* Nothing - -### Fixed - -* `composer check` failed because the tests doubled final `mezzio-router` classes - -## 1.5.0 - 2026-08-03 - -### Changed - -* Issue [#72](https://github.com/dotkernel/light/issues/72): Bumped `phpunit/phpunit` to `^12.5.23` by [@OStefan2001](https://github.com/OStefan2001) in [#73](https://github.com/dotkernel/light/pull/73) -* Updated the Qodana action by [@arhimede](https://github.com/arhimede) in [#71](https://github.com/dotkernel/light/pull/71) and [#74](https://github.com/dotkernel/light/pull/74) -* Updated README and `package.json` by [@bidi47](https://github.com/bidi47) in [#95](https://github.com/dotkernel/light/pull/95) -* Cleaned branch `1.0` by [@georgeStan](https://github.com/georgeStan) in [#114](https://github.com/dotkernel/light/pull/114) -* Fixed ambiguities in README by [@arhimede](https://github.com/arhimede) in [#116](https://github.com/dotkernel/light/pull/116) -* Renovate dependency and action updates in #76 to #113 - -### Added - -* Issue [#97](https://github.com/dotkernel/light/issues/97): Workflow that builds the JS and CSS assets by [@alexmerlin](https://github.com/alexmerlin) in [#98](https://github.com/dotkernel/light/pull/98) -* Renovate configuration in [#75](https://github.com/dotkernel/light/pull/75) - -### Deprecated - -* Nothing - -### Removed - -* Nothing - -### Fixed - -* Nothing - -## 1.4.0 - 2025-10-31 - -### Changed - -* Issue [#61](https://github.com/dotkernel/light/issues/61): Increased PHPStan level by [@Howriq](https://github.com/Howriq) in [#63](https://github.com/dotkernel/light/pull/63) -* Updated the Qodana workflow by [@arhimede](https://github.com/arhimede) in [#64](https://github.com/dotkernel/light/pull/64) -* Updated the Mezzio version by [@arhimede](https://github.com/arhimede) in [#65](https://github.com/dotkernel/light/pull/65) -* Updated the Packagist dependency badge by [@arhimede](https://github.com/arhimede) in [#66](https://github.com/dotkernel/light/pull/66) - -### Added - -* Support for PHP 8.5 by [@arhimede](https://github.com/arhimede) in [#68](https://github.com/dotkernel/light/pull/68) - -### Deprecated - -* Nothing - -### Removed - -* Nothing - -### Fixed - -* Nothing - -## 1.3.0 - 2025-04-29 - -### Changed - -* Replaced webpack with Vite by [@georgeStan](https://github.com/georgeStan) in [#50](https://github.com/dotkernel/light/pull/50) -* Updated the title and added PSR-15 on the index page by [@arhimede](https://github.com/arhimede) in [#54](https://github.com/dotkernel/light/pull/54) -* Updated `.gitignore` by [@alexmerlin](https://github.com/alexmerlin) in [#55](https://github.com/dotkernel/light/pull/55) -* Updated the README section about static modules by [@bidi47](https://github.com/bidi47) in [#60](https://github.com/dotkernel/light/pull/60) - -### Added - -* Nothing - -### Deprecated - -* Nothing - -### Removed - -* Removed `.DS_Store` files by [@arhimede](https://github.com/arhimede) in [#56](https://github.com/dotkernel/light/pull/56) and [#57](https://github.com/dotkernel/light/pull/57) - -### Fixed - -* Nothing -``` - -## Rollout order - -1. Fix the tests (F6). `composer check` must pass from here on. -2. Change `phpunit.xml` (V5). Run `composer test`. -3. Fix the page handler and add its tests (F1, F10). -4. Move the page routes (F2) and add the `ConfigProvider` route test. -5. Mask the error log values (F3). Check a log line by hand after a forced error. -6. Optional: F7, F8 and F9. -7. Workflows (V2) and, if confirmed, Node.js (V7). -8. README and CHANGELOG. -9. Documentation repository: D1 to D11, on its own branch. -10. Maintainer: restore the `dot-errorhandler` range (see the checklist), then tag `1.6.0` on branch `1.0`. - -## Verification checklist - -- [x] `composer cs-check` passes -- [x] `composer twig-cs-check` passes -- [x] `composer static-analysis` passes at level 8 without ignores or baseline -- [x] `composer test` passes with the new `failOn*` flags -- [x] `composer check` passes -- [x] Without `local.php`, the container registers `/page/about` (scratch script, 2026-12-04) -- [x] A forced error writes a log line with `PHPSESSID=******` -- [ ] `composer update` deletes `data/cache/config-cache.php` (verified once on 2026-12-04) -- [ ] `public/index.php` has no `ini_set` lines (verified on 2026-12-04) -- [x] Every changed `.md` file in both repositories passes `npx --yes markdownlint-cli2 --config ~/.claude/.markdownlint.jsonc` -- [ ] `mkdocs build` in `light-documentation` shows no warnings for missing pages -- [x] `dot-errorhandler` 5.1.0: container, pages and F3 masking work (2026-12-04) -- [x] Restore `"dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0"` in `composer.json` after the 5.1 test, then run `composer update` -- [ ] Unverified here: a forced error with `dot-errorhandler` 5.1.0 writes a log line -- [ ] Unverified here, check in CI: PHP 8.3, 8.4 and 8.6 -- [ ] Unverified here, check in CI: vendor deprecations on PHP 8.6 with `failOnDeprecation` -- [ ] Unverified here, check in CI: coverage with `pcov` -- [ ] Unverified here: lowest dependency versions (`composer update --prefer-lowest`, then `composer check`) -- [ ] Unverified here: Node.js 20 status (V7) -- [ ] Unverified here: published URL in F9 diff --git a/.claude/skills/plan-major-upgrade/SKILL.md b/.claude/skills/plan-major-upgrade/SKILL.md deleted file mode 100644 index 541cb38..0000000 --- a/.claude/skills/plan-major-upgrade/SKILL.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -name: plan-major-upgrade -description: Build the written plan for the next major version of a Dotkernel PHP package, saved in `.claude/plan-code-review.md`. Use when asked to review a package and plan its next major release - code review with before/after fixes, phpstan level, workflow and PHP version bumps, PHPUnit upgrade, new docs folder, CHANGELOG and tests. Also use to re-check or update that plan after the maintainer changes `composer.json`. ---- - -# Plan a major upgrade - -Produce one plan file, `.claude/plan-code-review.md`, and keep it current while the work is done. -The plan is the deliverable of the first pass. Make no other changes until the maintainer asks you to implement it. - -## Ground rules - -- **Measure before you claim.** Run the checks and reproduce each suspected bug with a failing test or a small script before it goes in the plan as a bug. Mark anything you could not run as "unverified" and say why (PHP version not installed, no coverage driver, lowest dependencies not installed). -- **Do not edit `composer.json` or install packages.** Edits are denied by the permission settings and the guard hooks block installs. Give the exact lines to change and ask the maintainer to apply them and run the install. Re-check the plan after every such change. -- **Do not circumvent a hook.** If a guard blocks a command, adapt (use the Edit and Write tools, a scratch directory) or ask. -- **Verify facts about other packages from the source**, for example `vendor/` or the published package listing, never from memory. A wrong claim in the plan becomes wrong docs. -- **Markdown is lint-clean.** Every `.md` file you write or edit must pass the maintainer's markdownlint config before you report it as done. - -## Inputs to settle first - -Ask only what you cannot determine from the repository. - -| Item | How to find it | -| --- | --- | -| Next major version number and branch | Ask. Use the current branch name for the plan. Check `git tag`, `git describe --tags` and the remote branches for existing lines | -| Whether other release lines exist | Check branches and tags. A separate line (for example an attribute-based `5.x`) changes the upgrade guide and the README | -| Target PHP versions | From the maintainer or the CI workflow. Note which are installed locally | -| What the maintainer does by hand | Typically `composer.json`, `phpstan.neon` level and the workflow versions. Do not redo or revert them | - -## Task list - -The first eight items (T1 to T8) are the requested tasks. The rest were missed in the original list and should be part of every plan. - -### Requested - -- **T1. Recommend fixes for issues and bugs in the codebase.** Review `src/` for correctness, robustness, types and style. Give each finding an id (F1, F2, ...), a severity, a location and evidence from a reproduction. -- **T2. Add before/after sections** for every recommended update: current code or behaviour, recommended code or behaviour, and why. Cover code, config, docs and tests. -- **T3. `phpstan.neon` to level 8.** Record the current level, run PHPStan at level 8 and list every error with its identifier and fix. Do not propose ignores, baselines or `assert()` workarounds. -- **T4. Workflow versions.** Remove the old PHP version, add the new one, and set the action versions the maintainer named (for example `actions/checkout@v7`, `actions/cache@v6`, `codecov/codecov-action@v7`). Check every file in `.github/workflows` and `.laminas-ci.json`. -- **T5. `phpunit/phpunit` to the new major.** Say whether the maintainer has to do it (it edits `composer.json`) and list the PHPUnit changes the tests need: configuration schema, attributes instead of annotations, static data providers, mock and stub rules, `failOn*` flags. -- **T6. New docs folder for the next major version** in `docs/book`, copied from the most recent version. Keep the old version folders unchanged. List every page that needs content changes. -- **T7. CHANGELOG.md** with all missing releases and the new major release, following the file's section convention. -- **T8. Update the tests**, including new tests for each fixed bug. - -### Recommended additions - -- **T9. Baseline.** Before planning, run `composer check` and record the result, the PHP versions available locally, and the nearest reachable tag (`git describe --tags`). State what the Laminas backward-compatibility check will compare against. -- **T10. Dependency review** of `composer.json`: PHP constraint, each runtime requirement and its range, requirements that are used but undeclared, requirements that are declared but unused, dev dependencies, `suggest` and `conflict`. List exact edits for the maintainer. -- **T11. Dependency removal evaluation.** For any dependency that exists for one import, check whether a PSR interface can replace it and what that would break. Give options and a recommendation. -- **T12. Upgrade guide** (`upgrading.md`) for each older line, with a table of changes that can break code: change, symptom, fix. -- **T13. Discontinued lines.** If a release line is discontinued, add a page in that version's docs folder and point to the replacement package. Read the replacement's source or listing first. -- **T14. README, `docs/book/index.md`, `SECURITY.md` and `mkdocs.yml`.** Version table rows, badges, the supported versions table, `current_version`, `versions` and the navigation. Check whether `docs/book/index.md` is a symlink to the README. -- **T15. `phpunit.xml` and CI flags.** Fail on notices, warnings, deprecations and risky tests. Plan for deprecations raised in vendor code on the newest PHP version. -- **T16. Test quality.** Prefer fixtures and a real collaborator over mocks. Check for traps, for example an annotation reader parsing an `@Inject` mentioned in prose inside a docblock. List coverage gaps by branch, and suggest a coverage driver and mutation testing if none is installed. -- **T17. Documentation examples.** Run every PHP snippet and check every link and navigation entry. Fix examples that never worked. -- **T18. Integration check** outside the repository with the real dependencies (for example a SQLite entity manager and a PSR-6 pool), in a scratch directory. -- **T19. Lifecycle metadata.** Check `OSSMETADATA`, badges and branch names for the new version. -- **T20. Remove `laminas/laminas-servicemanager` when it is a runtime requirement.** Check the `require` section of `composer.json` (a `require-dev` entry or an absence means skip this item). If it is there, implement the removal as `dot-dependency-injection` does, and put each step in the plan with before/after sections: - - Find every use: `grep -rni "laminas\|ServiceManager" src test`. Read `dot-dependency-injection` (`src/Factory`, `src/ConfigProvider.php`, `composer.json`) from its source, not from memory. - - Make the factories plain classes with `__invoke(ContainerInterface $container, string $requestedName)` and only `Psr\Container` imports, so they work with any PSR-11 container that accepts a factory per service key. - - Remove the classes that implement a Laminas interface, normally the abstract factory and its marker annotation. This is a breaking change: list it under Removed in the CHANGELOG and give a "replacing it" section in the upgrade guide, with before and after code. - - Make `ConfigProvider` return `[]` instead of registering `abstract_factories`. Keep the class so applications that list it do not break. - - Replace `ServiceManager` in the tests with a minimal PSR-11 fixture container (`get(string $id): mixed`, `has(string $id): bool`) and exception fixtures that implement `NotFoundExceptionInterface` and `ContainerExceptionInterface`. Class names must end in `Exception` for the coding standard. - - Update the docs, README, version table and CHANGELOG. Say the factories work with any PSR-11 container, and that applications using Laminas Service Manager require it themselves. - - Allow `psr/container` as `^1.1 || ^2.0`, and give the maintainer the `composer.json` edit: remove the requirement and reword the `description`. - - Verify: no `Laminas` or `ServiceManager` left in `src` or `test`, and `composer check` passes. State that the lowest `psr/container` version is unverified unless it was installed. -- **T21. Unverified list.** End the plan with what could not be tested here and how the maintainer can test it in CI. - -## Workflow - -1. Read the repository: `src/`, `test/`, `composer.json`, `phpstan.neon`, `phpunit.xml`, `.github/workflows`, `.laminas-ci.json`, `docs/book`, `README.md`, `CHANGELOG.md`, `SECURITY.md`, `mkdocs.yml`. -2. Run the baseline (T9). -3. Review the code and reproduce each suspected bug (T1 and T2). Use scratch files outside the repository. -4. Run PHPStan at the target level (T3). -5. Review dependencies, workflows and documentation (T4 to T6, T10 to T15 and T20). -6. Write the plan with the structure below. -7. Lint the plan, then tell the maintainer what they have to do by hand. -8. On request, implement the plan in the rollout order, run `composer check` after each step, and update the plan's status table. After every `composer.json` change by the maintainer, re-run the checks and update the docs and CHANGELOG. - -## Plan structure - -Use these headings, in this order. - -1. `# Plan: ` with one paragraph of context (branch, version, date). -2. `## Implementation status`: a table of item, state and notes. Update it as work lands. -3. `## Decision: version `: why this number, and how it relates to other release lines. -4. `## Baseline`: results of the commands you ran, and what you could not run. -5. `## Done by the maintainer`: the edits that were made by hand, and the exact edits still needed. -6. `## Findings`: one section per finding, each with Location, Evidence, Before, After and Why. Group as V1..Vn for version and tooling items, F1..Fn for code and test items. -7. `## Documentation`: a table of page and required change. -8. `## CHANGELOG`: the entries to add, by version. -9. `## Rollout order`: numbered steps, smallest safe change first. -10. `## Verification checklist`: checkboxes for every command and manual check, including the unverified list. - -Use `Before` and `After` as fenced code blocks (`php`, `diff`, `yaml`, `json` or `text`), never an untagged fence. - -## Checklist before reporting done - -- Every finding has a reproduction or is marked unverified. -- Every dependency claim was read from `vendor/` or `composer.json`. -- The plan file passes markdownlint. -- The final message lists what the maintainer must do by hand and what could not be tested here. From 668ec5d2d28637ee8720ccd5c28c270d05e1122c Mon Sep 17 00:00:00 2001 From: bidi Date: Fri, 4 Dec 2026 17:23:08 +0200 Subject: [PATCH 3/3] updated composer Signed-off-by: bidi --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7cb703a..ed5d328 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ }, "require": { "php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0", - "dotkernel/dot-log": "^5.4.0 || ^6.0.0", - "dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0", + "dotkernel/dot-log": "^5.4.0", + "dotkernel/dot-errorhandler": "^6.0.0", "laminas/laminas-component-installer": "^3.9.0", "laminas/laminas-config-aggregator": "^1.21.0", "laminas/laminas-diactoros": "^3.10.0",