headercat/phpstan-extension-ide-helper
Installation:
composer require --dev headercat/phpstan-extension-ide-helper:^2.2.4
Ensure phpstan/phpstan:^2.2.0 is installed in require-dev (required for compatibility).
Trigger IDE Helper Generation: Run the helper to generate stubs for PHPStan 2.2.4:
vendor/bin/phpstan-extension-ide-helper generate
Stubs are generated in ./stubs/phpstan/ (default) with updated 2.2.4 API coverage.
Configure IDE:
stubs/phpstan/ to "PHPStan" settings under Settings > Languages & Frameworks > PHP > PHPStan.phpstan.phar path and stub directory).First Use Case: Write a PHPStan extension (e.g., a custom rule). Leverage autocompletion for:
PhpStan\Analyser\Error or PhpStan\Rules\Type\TypeRule.PhpStan\Rule\Rule (e.g., refineNodes() with new parameters).PhpStan\Reflection\MethodReflection::getReturnType().Extension Development with 2.2.4:
PhpStan\Rule\Rule with autocompletion for new abstract methods like getNodeType() or refineNodes().
use PhpStan\Rules\Type\TypeRule; // New in 2.2.4
class CustomTypeRule extends TypeRule {
public function getNodeType(): string {
return TypeRule::BUILTIN_TYPE_STRING;
}
}
PhpStan\Analyser\Error stubs for reporting issues:
$this->reportError($error, $node); // Autocompleted
PhpStan\Reflection\ClassReflection::getNativeMethods()).Integration with PHPStan 2.2.4:
src/Rules/ or src/Extension/ and reference stubs for:
PhpStan\Broker\Container methods (e.g., getRuleLoader()).PhpStan\Analyser\Scope APIs (e.g., getFunction() with new parameters).use PhpStan\Broker\Container; // Autocompleted
use PhpStan\Analyser\Error; // Autocompleted
class MyExtension implements Extension {
public function getRuleLoader(): RuleLoader {
return RuleLoader::createFromRulesetProvider($this);
}
}
Testing with 2.2.4:
PhpStan\Testing\PhpStanTestCase with new assertions):
use PhpStan\Testing\PhpStanTestCase;
use PhpStan\Analyser\Error; // Autocompleted
class CustomRuleTest extends PhpStanTestCase {
public function testErrorReporting() {
$this->analyse([__DIR__ . '/fixtures/test.php']);
$this->assertErrorLogged(Error::LEVEL_ERROR, 'Custom error message');
}
}
vendor/bin/phpstan-extension-ide-helper generate --output=./stubs/phpstan-2.2.4/
composer.json to include the new stubs:
"autoload-dev": {
"psr-4": {
"PhpStan\\": ["./stubs/phpstan/", "./stubs/phpstan-2.2.4/"]
}
}
- name: Generate PHPStan 2.2.4 stubs
run: composer require phpstan/phpstan:^2.2.0 && vendor/bin/phpstan-extension-ide-helper generate
Stub Version Mismatch (Critical):
<2.2.0 will break with 2.2.4 due to:
PhpStan\Rule\Rule.PhpStan\Rules\Functions\* restructuring).composer require phpstan/phpstan:^2.2.0
vendor/bin/phpstan-extension-ide-helper generate --force
IDE-Specific Quirks (Updated):
File > Invalidate Caches) if autocompletion fails after stub generation.
phpstan.phar points to ./vendor/bin/phpstan.phar in Settings > PHPStan.phpstan.stubsPath in settings).Missing 2.2.4 Namespaces:
PhpStan\Type\ObjectType) may lack stubs.phpstan-src.Dependency Conflicts:
phpstan/phpstan-src isn’t cloned during stub generation.phpstan-src repo (check composer.json for headercat/phpstan-extension-ide-helper dependencies)../stubs/phpstan/PhpStan/ for new files like:
PhpStan/
├── Analyser/
│ ├── Error.php # New in 2.2.4
├── Rules/
│ ├── Type/ # Restructured
│ │ ├── TypeRule.php
├── Reflection/
│ ├── MethodReflection.php
vendor/bin/phpstan-extension-ide-helper generate --verbose
PhpStan\Analyser\Error::LEVEL_ERRORPhpStan\Rules\Type\TypeRule::getNodeType()Custom Stub Generation for 2.2.4:
PhpStan\Type\ObjectType).src/Generator.php to include additional paths from phpstan-src (check phpstan-src/PhpStan/).IDE-Specific Enhancements:
@method static Error create(string $message)).// In a generated stub file
namespace PhpStan\Analyser;
/**
* @method static Error create(string $message, int $level = Error::LEVEL_ERROR)
*/
class Error {}
CI Automation for 2.2.4:
- name: Generate and commit PHPStan 2.2.4 stubs
run: |
composer require phpstan/phpstan:^2.2.0
vendor/bin/phpstan-extension-ide-helper generate
git add stubs/phpstan/
git commit -m "chore: update PHPStan 2.2.4 stubs"
- name: Cache PHPStan stubs
uses: actions/cache@v3
with:
path: stubs/phpstan/
key: phpstan-stubs-2.2.4
How can I help you explore Laravel packages today?