Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] More bullet-proof expression evaluation#59976

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Wirone wants to merge4 commits intosymfony:6.4
base:6.4
Choose a base branch
Loading
fromWirone:codito/full-bulletproof-for-evaluating-expression

Conversation

Wirone
Copy link
Contributor

@WironeWirone commentedMar 14, 2025
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
Issuesn/a
LicenseMIT

As askedhere, we faced weird issue recently. I was able to reproduce it with minimal DI setup inCheckTypeDeclarationsPassTest.

@carsonbot

This comment was marked as outdated.

@WironeWironeforce-pushed thecodito/full-bulletproof-for-evaluating-expression branch from4266c4a to1a7bf06CompareMarch 14, 2025 14:21
@WironeWirone marked this pull request as ready for reviewMarch 14, 2025 14:36
@carsonbotcarsonbot added this to the7.2 milestoneMar 14, 2025
@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.2" but it seems your PR description refers to branch "6.4, 7.2".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@WironeWironeforce-pushed thecodito/full-bulletproof-for-evaluating-expression branch fromf22ebf9 to0dcb2e6CompareMarch 14, 2025 14:38
In some scenarios evaluating expression can lead to TypeError (unresolved DI params being strings, not expected integers etc).
@WironeWironeforce-pushed thecodito/full-bulletproof-for-evaluating-expression branch from0dcb2e6 to247f0f9CompareMarch 14, 2025 14:52
@WironeWirone changed the base branch from7.2 to6.4March 14, 2025 14:52
@OskarStarkOskarStark modified the milestones:7.2,6.4Mar 14, 2025
`composer.json`'s requirement for PHP is `PHP >= 8.1`, so even though GH Actions does not contain PHP 8.1 in the matrix (which is wrong IMHO), let's stick with `readonly` on property level.
@Wirone
Copy link
ContributorAuthor

I've additionally fixed PHP 8.1 compatibility (readonly on fixture class level, I have this as a default in IDE and just today saw the red underline in files 😉). What's interesting is whyprevious CI run did not run tests on PHP 8.1, andlatest one did 😅.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So, the error you describe on Twitter happens before env vars are unresolved, while running the expression.
I feel like the solution that's proposed at the moment is way to much. What if the error is a parse error or anything else that'd better be caught at linting time?
Sorry I don't have a proposal, that's just the question that comes up at the moment :)

@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

to be replaced by the licence header (same below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

also in fixture file?
if so, we could run the Fixer to apply this for other fixture files

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the thing is we'd like the licence header in fixtures (because why not), but then, no need to enforce other rules I'd say (at least we'll get many false-positives if we do)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

and PHP-CS-Fixer only allows to exclude files entirely, not to override the config being applied to some files to apply only some of the rules.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, we definitely need to introduce skipping rules like ECS has, I like it a lot.

But you can also have a separate ruleset for fixtures and run Fixer twice, pointing to the config file.

@Wirone
Copy link
ContributorAuthor

I feel like the solution that's proposed at the moment is way to much. What if the error is a parse error or anything else that'd better be caught at linting time?

@nicolas-grekas I've been thinking about your question last 2 days and my initial opinion did not change -lint:container is IMHOnot a place for spotting syntax errors. These should be caught in a separate job (php -l or parallel lint), the last moment for it could becache:clear. I thinklint:container should focus only on DI definition and skip all the errors related to initialising services. Ideally it shouldn't initialise them in the first place, but I get that in order to match signature's expected type with other service's type or expression' return type it has to be done. Anyway, I think my fix is valid, as it aligns with the comment that is right there:

If a service from the expression cannot be fetched from the container, we skip the validation.

In our case it's runtime issue, but for other scenarios it can be actually language-level issue - none of them should break the DI linting (maybe flag for this would be a good idea, so you could runlint:container --stop-on-error or something like that).

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedMar 20, 2025
edited
Loading

What about checking the error message and ignoring only the ones we know we want to ignore?
I don't agree with you about linting not being the place to spot parse errors: any opportunity to spot mistakes as early as possible is a win. False-positives are what is bad, and I would care about them one by one.

OskarStark reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

Up to follow my last suggestion@Wirone?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@OskarStarkOskarStarkOskarStark left review comments

@keraduskeraduskeradus left review comments

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

6 participants
@Wirone@carsonbot@nicolas-grekas@stof@OskarStark@keradus

[8]ページ先頭

©2009-2025 Movatter.jp