|
| 1 | +# Parser Reflection Library |
| 2 | + |
| 3 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 4 | + |
| 5 | +Parser Reflection is a **deprecated** PHP library that provides reflection capabilities without loading classes into memory. It extends PHP's internal reflection classes using nikic/PHP-Parser for static code analysis. The library is fully functional but deprecated in favor of [BetterReflection](https://github.com/Roave/BetterReflection). |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Bootstrap, Build and Test the Repository |
| 10 | + |
| 11 | +**CRITICAL: Set timeouts of 30+ minutes for all composer commands. NEVER CANCEL composer operations.** |
| 12 | + |
| 13 | +1. **Verify PHP version**: Requires PHP >=8.2 |
| 14 | + ```bash |
| 15 | + php --version # Should show PHP 8.2+ |
| 16 | + ``` |
| 17 | + |
| 18 | +2. **Install dependencies** (takes 15-25 minutes due to GitHub API rate limits): |
| 19 | + ```bash |
| 20 | + composer config --global process-timeout 2000 |
| 21 | + composer install --prefer-source --no-interaction |
| 22 | + ``` |
| 23 | + **NEVER CANCEL** - This process takes 15-25 minutes and may show authentication warnings. The `--prefer-source` flag is REQUIRED to avoid GitHub API rate limit issues. |
| 24 | + |
| 25 | +3. **Generate autoloader** (if not created during install): |
| 26 | + ```bash |
| 27 | + composer dump-autoload |
| 28 | + ``` |
| 29 | + |
| 30 | +4. **Run tests** - Takes ~6 seconds. NEVER CANCEL timeout should be 30+ minutes for safety: |
| 31 | + ```bash |
| 32 | + vendor/bin/phpunit # 10,579 tests, ~6 seconds |
| 33 | + ``` |
| 34 | + |
| 35 | +### Code Quality and Validation |
| 36 | + |
| 37 | +5. **Run static analysis** - Takes ~5 seconds: |
| 38 | + ```bash |
| 39 | + vendor/bin/phpstan analyse src --no-progress # Expect 18 existing errors (normal) |
| 40 | + ``` |
| 41 | + |
| 42 | +6. **Run code quality checks** - Takes ~5 seconds: |
| 43 | + ```bash |
| 44 | + vendor/bin/rector --dry-run # Shows suggested improvements, don't auto-apply |
| 45 | + ``` |
| 46 | + |
| 47 | +7. **Validate composer.json**: |
| 48 | + ```bash |
| 49 | + composer validate # Should complete in <1 second |
| 50 | + ``` |
| 51 | + |
| 52 | +### Test Library Functionality |
| 53 | + |
| 54 | +Always test changes by running actual reflection scenarios: |
| 55 | + |
| 56 | +```bash |
| 57 | +# Create test script |
| 58 | +cat > /tmp/test_reflection.php << 'EOF' |
| 59 | +<?php |
| 60 | +require_once 'vendor/autoload.php'; |
| 61 | +
|
| 62 | +$parsedFile = new \Go\ParserReflection\ReflectionFile('src/ReflectionClass.php'); |
| 63 | +$namespaces = $parsedFile->getFileNamespaces(); |
| 64 | +foreach ($namespaces as $namespace) { |
| 65 | + $classes = $namespace->getClasses(); |
| 66 | + foreach ($classes as $class) { |
| 67 | + echo "Found class: " . $class->getName() . " with " . count($class->getMethods()) . " methods\n"; |
| 68 | + } |
| 69 | +} |
| 70 | +EOF |
| 71 | + |
| 72 | +php /tmp/test_reflection.php |
| 73 | +``` |
| 74 | + |
| 75 | +## Repository Structure |
| 76 | + |
| 77 | +### Key Directories |
| 78 | +- `src/` - Main library code (30 PHP files) |
| 79 | + - Core reflection classes (ReflectionClass, ReflectionMethod, etc.) |
| 80 | + - `bootstrap.php` - Auto-initialization |
| 81 | + - `Locator/` - Class location logic |
| 82 | + - `Traits/` - Shared functionality |
| 83 | +- `tests/` - Test suite (37 test files, 10,579 tests) |
| 84 | +- `docs/` - API documentation for each reflection class |
| 85 | +- `vendor/` - Dependencies (created during build) |
| 86 | + |
| 87 | +### Important Files |
| 88 | +- `composer.json` - Dependencies: php >=8.2, nikic/php-parser ^5.0 |
| 89 | +- `phpunit.xml.dist` - Test configuration (1536M memory limit) |
| 90 | +- `rector.php` - Code quality rules |
| 91 | +- `.github/workflows/phpunit.yml` - CI pipeline (PHP 8.2, 8.3) |
| 92 | + |
| 93 | +## Common Issues and Troubleshooting |
| 94 | + |
| 95 | +### Network/Authentication Issues |
| 96 | +- **`composer install` fails with GitHub authentication errors**: Use `composer install --prefer-source --no-interaction` |
| 97 | +- **SSL timeout errors**: Increase timeout with `composer config --global process-timeout 2000` |
| 98 | +- **API rate limits**: The `--prefer-source` flag bypasses GitHub API limits by cloning repositories directly |
| 99 | + |
| 100 | +### Build Issues |
| 101 | +- **Missing vendor/autoload.php**: Run `composer dump-autoload` |
| 102 | +- **Class not found errors**: Ensure composer install completed successfully |
| 103 | +- **Memory errors during tests**: Tests are configured with 1536M memory limit in phpunit.xml.dist |
| 104 | + |
| 105 | +### Library Usage |
| 106 | +- **"Class not found by locator" errors**: This is expected for classes not autoloaded by Composer |
| 107 | +- **Parser errors**: Library only works with valid PHP syntax |
| 108 | +- **Missing nikic/php-parser**: This is the core dependency - ensure composer install succeeded |
| 109 | + |
| 110 | +## Validation Scenarios |
| 111 | + |
| 112 | +**ALWAYS test these scenarios after making changes:** |
| 113 | + |
| 114 | +1. **Basic reflection test**: |
| 115 | + ```bash |
| 116 | + php -r "require 'vendor/autoload.php'; \$f = new \Go\ParserReflection\ReflectionFile('src/ReflectionClass.php'); \$ns = \$f->getFileNamespaces(); foreach(\$ns as \$n) { echo 'Classes in ' . \$n->getName() . ': ' . count(\$n->getClasses()) . \"\n\"; }" |
| 117 | + ``` |
| 118 | + |
| 119 | +2. **Run core test suite**: |
| 120 | + ```bash |
| 121 | + vendor/bin/phpunit --testsuite="Parser Reflection Test Suite" |
| 122 | + ``` |
| 123 | + |
| 124 | +3. **Verify no syntax errors**: |
| 125 | + ```bash |
| 126 | + find src -name "*.php" -exec php -l {} \; | grep -v "No syntax errors" |
| 127 | + ``` |
| 128 | + |
| 129 | +## Build Timing Expectations |
| 130 | + |
| 131 | +**NEVER CANCEL - All timing includes 50% safety buffer:** |
| 132 | + |
| 133 | +- `composer install --prefer-source`: **15-25 minutes** (NEVER CANCEL - set 30+ minute timeout) |
| 134 | +- `vendor/bin/phpunit`: **~6 seconds** (set 30+ minute timeout for safety) |
| 135 | +- `vendor/bin/rector --dry-run`: **~5 seconds** (set 10+ minute timeout) |
| 136 | +- `vendor/bin/phpstan analyse src`: **~5 seconds** (set 10+ minute timeout) |
| 137 | +- Basic syntax check: **<10 seconds** (set 5+ minute timeout) |
| 138 | + |
| 139 | +## Development Notes |
| 140 | + |
| 141 | +- This library is **deprecated** - prefer BetterReflection for new projects |
| 142 | +- Library provides drop-in replacements for PHP's reflection classes |
| 143 | +- Core functionality requires nikic/php-parser for AST generation |
| 144 | +- Tests use Composer's autoloader for class location |
| 145 | +- Memory usage can be high for large codebases (configure php.ini accordingly) |
| 146 | +- Compatible with PHP 8.2+ (tested on 8.2, 8.3) |
| 147 | + |
| 148 | +## CI/Build Pipeline Reference |
| 149 | + |
| 150 | +The GitHub Actions pipeline (`.github/workflows/phpunit.yml`) runs: |
| 151 | +- Matrix testing: PHP 8.2, 8.3 on Ubuntu |
| 152 | +- Dependency variations: lowest, highest |
| 153 | +- Standard `composer install` (works in CI with GitHub tokens) |
| 154 | +- PHPUnit test suite execution |
0 commit comments