-
-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/claude phpstan level10 php85 #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dd8d4c8
feat: Initialize Claude for the repository
lisachenko 55157e1
feat: use phpstan in the pipeline with level:5
lisachenko f132557
chore: fix all PHPStan level 5 errors
lisachenko 23a859e
chore: fix PHPStan level 6 errors
lisachenko 51a1e0c
chore: fix PHPStan level 7 errors
lisachenko f5a7358
chore: fix PHPStan level 8 errors
lisachenko 9ff35b2
chore: fix PHPStan level 9 errors
lisachenko 0000dda
chore: fix PHPStan level 10 errors
lisachenko 704a24b
fix: resolve self/parent type hints to actual class names
lisachenko 3bc6721
fix: Remove the treatPhpDocTypesAsCertain: false for phpstan
lisachenko f00a6fe
fix: Remove old source code that causes deprecation warnings
lisachenko f805623
fix: address PR review comments
lisachenko 88397ba
fix(tests): Cover misc deprecations
lisachenko 48d2537
fix: resolve self/parent types only on PHP 8.5+ to match native behavior
lisachenko c9a86dd
fix(property): restore single-arg setValue() for static properties
lisachenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: "PHPStan analysis" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| build: | ||
| name: "PHPStan analysis - PHP8.4" | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: "Checkout" | ||
| uses: actions/checkout@v4 | ||
| - name: "Install PHP" | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: "8.4" | ||
| ini-values: memory_limit=-1 | ||
| tools: composer:v2 | ||
| - name: "Cache dependencies" | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.composer/cache | ||
| vendor | ||
| key: "php-8.4" | ||
| restore-keys: "php-8.4" | ||
| - name: "Install dependencies" | ||
| run: "composer install --no-interaction --no-progress" | ||
| - name: "Static analysis" | ||
| run: "vendor/bin/phpstan analyze --memory-limit=1G" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Overview | ||
|
|
||
| Parser Reflection is a **deprecated** PHP library (deprecated in favor of [BetterReflection](https://github.com/Roave/BetterReflection)) that extends PHP's internal reflection classes using nikic/PHP-Parser for static analysis. It reflects PHP code without loading classes into memory by parsing source files into an AST. | ||
|
|
||
| Requires PHP >=8.4. Namespace: `Go\ParserReflection\`. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| # Install dependencies (slow locally — see note below) | ||
| composer install --prefer-source --no-interaction | ||
|
|
||
| # Run tests (~6 seconds, ~10,500 tests) | ||
| vendor/bin/phpunit | ||
|
|
||
| # Run a single test file | ||
| vendor/bin/phpunit tests/ReflectionClassTest.php | ||
|
|
||
| # Run a specific test method | ||
| vendor/bin/phpunit --filter testMethodName | ||
|
|
||
| # Static analysis (~5 seconds, 18 known existing errors are normal) | ||
| vendor/bin/phpstan analyse src --no-progress | ||
| ``` | ||
|
|
||
| > **Note on `composer install` locally**: due to GitHub API rate limits, use `--prefer-source` and set a long timeout: `composer config --global process-timeout 2000`. In CI, standard `composer install` works fine with GitHub tokens. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Request flow | ||
|
|
||
| When you call `new ReflectionClass('SomeClass')`: | ||
| 1. `ReflectionClass` asks `ReflectionEngine` for the class's AST node | ||
| 2. `ReflectionEngine` uses the registered `LocatorInterface` to find the file | ||
| 3. The file is parsed by PHP-Parser into an AST | ||
| 4. Two node visitors run: `NameResolver` (resolves FQCNs) and `RootNamespaceNormalizer` (normalizes global namespace) | ||
| 5. The resulting `ClassLike` AST node is stored in `ReflectionEngine::$parsedFiles` (in-memory LRU cache) | ||
| 6. The node is wrapped in the appropriate reflection class | ||
|
|
||
| ### Key components | ||
|
|
||
| - **`ReflectionEngine`** (`src/ReflectionEngine.php`) — static class; central hub. Owns the PHP-Parser instance, AST cache, and locator. Entry points: `parseFile()`, `parseClass()`, `parseClassMethod()`, etc. | ||
| - **`LocatorInterface`** / **`ComposerLocator`** — pluggable class file finder. `ComposerLocator` delegates to Composer's classmap/autoloader. `bootstrap.php` auto-registers `ComposerLocator` on load. | ||
| - **Reflection classes** (`src/Reflection*.php`) — each extends its PHP internal counterpart (e.g. `ReflectionClass extends \ReflectionClass`) and holds an AST node. Methods that require a live object (e.g. `invoke()`) trigger actual class loading and fall back to native reflection. | ||
| - **Traits** (`src/Traits/`) — shared logic extracted to avoid duplication: | ||
| - `ReflectionClassLikeTrait` — used by `ReflectionClass`; implements most class inspection methods against the AST | ||
| - `ReflectionFunctionLikeTrait` — shared by `ReflectionMethod` and `ReflectionFunction` | ||
| - `InitializationTrait` — lazy initialization of AST node from engine | ||
| - `InternalPropertiesEmulationTrait` — makes `var_dump`/serialization look like native reflection | ||
| - `AttributeResolverTrait` — resolves PHP 8 attributes from AST nodes | ||
| - **Resolvers** (`src/Resolver/`) — `NodeExpressionResolver` evaluates constant expressions in the AST (used for default values, constants). `TypeExpressionResolver` resolves type AST nodes into reflection type objects. | ||
| - **`ReflectionFile` / `ReflectionFileNamespace`** — library-specific (not in native PHP reflection). Allow reflecting arbitrary PHP files and iterating their namespaces, classes, functions without knowing class names in advance. | ||
|
|
||
| ### Test structure | ||
|
|
||
| Tests in `tests/` mirror the reflection class names (e.g. `ReflectionClassTest.php`). PHP version-specific stub files in `tests/Stub/` (e.g. `FileWithClasses84.php`) contain the PHP code being reflected. Tests extend `AbstractTestCase` which sets up the `ReflectionEngine` with a `ComposerLocator`. | ||
|
|
||
| ### CI | ||
|
|
||
| GitHub Actions (`.github/workflows/phpunit.yml`) runs PHPUnit on PHP 8.2, 8.3, 8.4 with both lowest and highest dependency versions. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| parameters: | ||
| level: 10 | ||
| paths: | ||
| - src | ||
| ignoreErrors: | ||
| # Both classes are final, so "might have hooks in a subclass" is a false positive | ||
| - identifier: unset.possiblyHookedProperty | ||
| path: src/ReflectionFunction.php | ||
| - identifier: unset.possiblyHookedProperty | ||
| path: src/ReflectionMethod.php | ||
| # Class names from the AST are semantically class-strings by construction (they come from | ||
| # parsed PHP class declarations), but PHPStan cannot verify this without autoloading, which | ||
| # would violate the library's contract of reflecting code without loading classes. | ||
| - identifier: return.type | ||
| path: src/Traits/ReflectionClassLikeTrait.php | ||
| message: '#resolveAsClassString#' | ||
| - identifier: return.type | ||
| path: src/Traits/AttributeResolverTrait.php | ||
| message: '#resolveAttributeClassName#' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.