eliashaeussler/phpstan-config
Composer 安装命令:
composer require eliashaeussler/phpstan-config
包简介
My personal configuration for PHPStan
README 文档
README
PHPStan config
This package contains basic PHPStan config for use in my personal projects. It is not meant to be used anywhere else. I won't provide support and don't accept pull requests for this repo.
🔥 Installation
composer require eliashaeussler/phpstan-config
⚡ Usage
With extension installer
If you have the phpstan/extension-installer
package installed, there's nothing more to do. The base configuration
is automatically included.
Manual include
Create a phpstan.neon file and include the
phpstan.neon.dist file:
# phpstan.neon includes: - %rootDir%/../../eliashaeussler/phpstan-config/phpstan.neon.dist
PHP API
The package provides a PHP configuration API for PHPStan. Add this
to your phpstan.php file:
// phpstan.php use EliasHaeussler\PHPStanConfig; $config = PHPStanConfig\Config\Config::create(__DIR__)->in( 'src', 'tests', ); // Exclude specific paths $config->not( 'src/lib/*', 'tests/test-application/vendor/*', ); // Configure rule level $config->level(9); $config->maxLevel(); // Enable bleeding edge $config->withBleedingEdge(); // Include baseline file $config->withBaseline(); // Include additional config files $config->with( 'phpstan-custom-rules.neon', 'vendor/foo/baz/optional-phpstan-rules.neon', ); // Define bootstrap files $config->bootstrapFiles( 'tests/build/phpstan-bootstrap.php', ); // Define stub files $config->stubFiles( 'tests/stubs/ThirdPartyClass.stub', 'tests/stubs/AnotherStubFile.stub', ); // Override cache path $config->useCacheDir('var/cache/phpstan'); // Ignore errors $config->ignoreError('Access to constant EXTENSIONS on an unknown class PHPStan\ExtensionInstaller\GeneratedConfig.'); $config->ignoreError('#^Access to constant EXTENSIONS on an unknown class .+\\.$#'); // Configure unmatched error reporting $config->reportUnmatchedIgnoredErrors(false); // Define error formatter $config->formatAs(PHPStanConfig\Enums\ErrorFormat::Json); // Treat phpdoc types as certain $config->treatPhpDocTypesAsCertain(); // Enable or disable custom rules (see rules below) $config->useCustomRule('ignoreAnnotationWithoutErrorIdentifier', false); // Include Doctrine set $config->withSet( static function (PHPStanConfig\Set\DoctrineSet $set): void { $set->withObjectManagerLoader('tests/object-manager.php'); $set->withOrmRepositoryClass(\MyApp\Doctrine\BetterEntityRepository::class); $set->withOdmRepositoryClass(\MyApp\Doctrine\BetterDocumentRepository::class); }, ); // Include Symfony set $config->withSet( static function (PHPStanConfig\Set\SymfonySet $set): void { $set->withConsoleApplicationLoader('tests/build/console-application.php'); $set->withContainerXmlPath('var/cache/test-container.xml'); $set->disableConstantHassers(); }, ); // Include TYPO3 set $typo3Set = PHPStanConfig\Set\TYPO3Set::create() ->withCustomAspect('myCustomAspect', \FlowdGmbh\MyProject\Context\MyCustomAspect::class) ->withCustomRequestAttribute('myAttribute', \FlowdGmbh\MyProject\Http\MyAttribute::class) ->withCustomSiteAttribute('myArrayAttribute', 'array'); $config->withSets($typo3Set); // Set custom parameters $config->parameters->set('tipsOfTheDay', false); return $config->toArray();
🔎 Rules
The packages also provides some additional PHPStan rules. All rules are enabled by default.
IgnoreAnnotationWithoutErrorIdentifierRule
A custom rule to report too loose ignore annotations that don't specify an error identifier.
By default, both @phpstan-ignore-line and @phpstan-ignore-next-line annotations are monitored.
parameters: ignoreAnnotationWithoutErrorIdentifier: # Enable or disable this rule enabled: true # Define monitored annotations (without "@" prefix) monitoredAnnotations: - phpstan-ignore-line - phpstan-ignore-next-line
This rule can also be customized using the PHP API:
# phpstan.php use EliasHaeussler\PHPStanConfig; $config = PHPStanConfig\Config\Config::create(__DIR__); $config->parameters->set('ignoreAnnotationWithoutErrorIdentifier/enabled', false); $config->parameters->set('ignoreAnnotationWithoutErrorIdentifier/monitoredAnnotations', [ // These annotations don't actually exist, this is just for demonstration purposes 'phpstan-ignore-start', 'phpstan-ignore-end', ]); return $config->toArray();
⭐ License
This project is licensed under GNU General Public License 3.0 (or later).
eliashaeussler/phpstan-config 适用场景与选型建议
eliashaeussler/phpstan-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 756.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 eliashaeussler/phpstan-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eliashaeussler/phpstan-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 756.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 22
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-02-20