DIC compiler pass has() false positive
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start with DependencyInjection/Compiler/AddCustomFakerGeneratorProvidersPass.php and reproduce the report using the shown PHPStan configuration and Symfony containerXmlPath. Inspect how the Symfony extension handles ContainerBuilder::has() against the generated container XML, then add a regression test showing that a valid guard does not produce unreachable-code warnings.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I have a simple compiler pass like below:
<?php
declare(strict_types=1);
namespace App\DependencyInjection\Compiler;
use Faker\Generator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class AddCustomFakerGeneratorProvidersPass implements CompilerPassInterface
{
public const TAG = 'app.faker.generator_provider';
public function process(ContainerBuilder $container): void
{
if (!$container->has(Generator::class)) {
return;
}
$svc = $container->findDefinition(Generator::class);
$taggedDeps = $container->findTaggedServiceIds(self::TAG);
foreach ($taggedDeps as $id => $tags) {
$svc->addMethodCall('addProvider', [new Reference($id)]);
}
}
}
PHPStan with Symfony extension reports that has() will always return true:
------ -----------------------------------------------------------------------
Line DependencyInjection/Compiler/AddCustomFakerGeneratorProvidersPass.php
------ -----------------------------------------------------------------------
17 Negated boolean expression is always true.
21 Unreachable statement - code above always terminates.
------ -----------------------------------------------------------------------
This is taken straight from Symfony docs at https://symfony.com/doc/current/service_container/tags.html#create-a-compiler-pass and they even add a separate warning stating "// always first check if the primary service is defined". Thus, I think this is a bug in PHPStan Symfony extension.
Here's my full PHPStan config:
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
level: 7
tmpDir: var/cache/_phpstan
parallel:
jobSize: 20
maximumNumberOfProcesses: 16
minimumNumberOfJobsPerProcess: 2
processTimeout: 30.0
symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
excludePaths:
- %rootDir%/../../../src/DataFixtures/*
- %rootDir%/../../../src/Migrations/*
universalObjectCratesClasses:
- Faker\Generator
ignoreErrors:
- '#^Call to an undefined method Faker\\Generator::#'
tipsOfTheDay: false
polluteScopeWithLoopInitialAssignments: false
polluteScopeWithAlwaysIterableForeach: false
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
checkAlwaysTrueStrictComparison: true
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
reportMaybesInMethodSignatures: true
reportStaticMethodSignatures: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
treatPhpDocTypesAsCertain: false
checkMissingIterableValueType: false # handled by PHPCs with more granularity
- Ngôn ngữ chính
- PHP
- Star
- 806
- Fork
- 104
- Merge trung bình
- 27 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-symfony
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
phpstan/phpstan-symfony#510 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
phpstan/phpstan-symfony#494 · 5 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
phpstan/phpstan-symfony#268 ·
-
Account for `\ErrorException` from `unserialize()` when Symfony’s PHP error conversion is enabledĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
phpstan/phpstan-symfony#514 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
phpstan/phpstan-symfony#509 · 2 bình luận ·
Tất cả issue của phpstan/phpstan-symfony
Issue tương tự
-
sync-en
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Source item status is not saved when stock is deducted on shipment (stays "In Stock" at qty 0)Đang mởIssue: ready for confirmation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
coollabsio/coolify#12274 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Type] Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 4 ngày
-
0.kind: enhancement 9.needs: package (update)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
NixOS/nixpkgs#577156 · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày