Skip to content

Keep an optional path as written where a plain one would be - #6452

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
SanderMuller:optional-path-relative
Sep 16, 2026
Merged

staabm merged 1 commit into
phpstan:2.2.xfrom
SanderMuller:optional-path-relative

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

- path (?) in excludePaths was expanded and absolutized whatever the loader was asked to expand. A plain entry under the same key is only touched when that key is listed in expandRelativePaths. CommandHelper reads the project config for the result cache metadata with a list holding just paths and tmpDir.

So the required entry stayed as written and the optional one beside it turned absolute. Moving the anchor directory then changed projectConfig and threw the whole cache away. Same project, two paths, before:

A   excludePaths: {analyse: [src/Excluded, {path: /tmp/relpath/src/Optional}]}
B   excludePaths: {analyse: [src/Excluded, {path: /tmp/relpathB/src/Optional}]}

After, both:

    excludePaths: {analyse: [src/Excluded, {path: src/Optional}]}

All three shapes an entry can take now store the way a plain one does. Relative stays relative, absolute stays absolute, and a %placeholder% stays unexpanded. The container load is unaffected, because every excludePaths key is in its expandRelativePaths list. I checked that rather than assumed it: an error in each excluded directory, and the reported set is identical before and after.

The e2e fixture gains one optional excludePaths entry, so the scenario's existing "no checkout prefix anywhere in the cache" assertion covers this. It fails on the base and passes with the change.

Closes phpstan/phpstan#15238

Comment thread e2e/result-cache-relative-path/phpstan.neon Outdated
Comment on lines +13 to +15
excludePaths:
analyse:
- src/NotThere (?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need another test in which a file which is configured optional exists?

@SanderMuller SanderMuller Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one. optional-src/ now exists, holds a file with a level 8 error, and is excluded optionally alongside the missing path.

It does not change how the path is stored. createOptionalPath() never touches the filesystem, and I checked that an existing and a missing entry store identically. What it adds is an assertion the missing-path version could not make: that the entry still excludes. I confirmed that by pointing the entry at a typo, which makes the analyse exit 1 on the error in that file.

`- path (?)` in excludePaths was expanded and absolutized whatever the loader
was asked to expand. A plain entry under the same key is only touched when that
key is listed in expandRelativePaths. CommandHelper reads the project config for
the result cache metadata with a list holding just paths and tmpDir.

So a relative optional path was stored absolute in the cache metadata while the
required entry beside it stayed as written. Moving the anchor directory - a
fresh CI checkout, a git worktree - then changed projectConfig and discarded the
whole cache.

The three shapes an entry can take now store the same way as a plain one:
relative stays relative, absolute stays absolute, and a %placeholder% stays
unexpanded. The container load is unaffected, because every excludePaths key is
in its expandRelativePaths list.

The e2e scenario reuses the existing sources through a second config file, so
what the first one covers is unchanged. That config carries its own tmpDir:
two configs sharing one write the same %tmpDir%/resultCache.php and discard each
other's cache, which is a separate problem.

Closes phpstan/phpstan#15238

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@staabm
staabm merged commit f11b30b into phpstan:2.2.x Sep 16, 2026
861 of 892 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants