Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
PHPStan baseline is currently skipping multiple Access to an undefined property
errors.
Proposed resolution
Fix the errors, clean up the baseline.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#58 | interdiff_MR2129-MR2758.txt | 49.11 KB | Spokje |
Issue fork drupal-3274474
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mondrakeIn PHP 8.2, dynamic property creation is deprecated, https://php.watch/versions/8.2/dynamic-properties-deprecated
Comment #6
mondrakePlease review. There are a few left, but they impact the entity system which is heavily relying on dynamic properties and it would be tricky to address, better in a separate issue. Here I tackled the view plugin ones which was a jungle itself - it's green so it would be good to start fixing these.
Comment #7
mondrakeComment #8
mondrakererolled
Comment #9
mondrakererolled
Comment #10
mondrakeI'd rather postpone on #3280882: KernelTestBase::tearDown() cleanup prevents good typehinting practices.
Comment #11
mallezie#3280882: KernelTestBase::tearDown() cleanup prevents good typehinting practices is in.
Planning to review tomorrow, if nobody beats me to it.
Comment #12
mondrakeThanks in advance @mallezie, #3280882: KernelTestBase::tearDown() cleanup prevents good typehinting practices gives the opportunity for a bit more optimization.
Comment #13
mallezieGoing through the changes here.
In the baseline changes, only thing removed are 'Acces to undefined property' mentions, so nothing 'out of scope touched.
Going through the code changes: 80% of changes are indeed just adding the property as a class property.
Noticing here that in some cases those are typehinted, and in some cases they are not explicitly typehinted, but only with a comment. (I don't think that's really a problem for now, and phpstan on higher level will point that out.) But was this now on purpose, or more random inconsistency? (nothing to blame off course in this huge MR)
One thing i'm thinking about here, since this issue is also about php8.2 compatibility (with the dynamic property deprecation). Is how far adding those typehints, makes this also committable for D9 (with the lower php requirement, and less typehinting possibility) which we would also be php8.2 compatible (probably not php9). So not sure if we should remove the typehinting here for now, and add that again for D10 only?
Nice changes BTW, by cleaning up some small stuff. (Removing the property, when not using, and introducing the admin_user adminUser cleanup).
Other thing i'm seeing is that in some tests we use a UserInterface and sometimes the User class. Not sure we can make this consistent (i think that needs to be solved on the createUser function level (and thus in an other issue)).
I do see in the baseline 34 lines left of undefined properties. Do we want those fixed as well? (Checking some of them they are also straightforward). On the other hand, this MR is already massive and fixes almost 25% of the baseline, so might be good to get this in, and cleanup further. So only blocking thing IMO is the typehinting question.
Comment #14
mondrakeThanks @mallezie for the review.
IMHO we should somehow split this monster. This is a 2nd try already (see the other MR, now hidden), and I had to stay away from e.g. all the entity code as I got burned there.
How about converting this to a meta and spinning out a first patch with the fixes to tests code only. There we can be more strict in typehinting than in runtime code (to match you concerns on D9 compat), and in case work on a 'strict' MR for D10 and a 'loose' one for D9 - while keeping size manageable.
Comment #15
mondrakePostponed on #3281535: Fix 'Access to an undefined property' PHPStan L0 errors in test code
Comment #16
mondrakeComment #17
Gábor HojtsyParenting to #3275851: [META] Fix PHP 8.2 dynamic property deprecations, hopefully that is correct?
Comment #18
mondrake#3281535: Fix 'Access to an undefined property' PHPStan L0 errors in test code was committed.
Comment #19
mondrakerebased and regenerated the baseline
Comment #20
daffie CreditAttribution: daffie commentedNeeds to be rebased again.
Comment #22
longwaveMerged in 10.0.x.
Comment #23
mondrakeI thik we need to discuss if we want to make an extra effort and typehint as many properties as possible like in #3281535: Fix 'Access to an undefined property' PHPStan L0 errors in test code.
Comment #24
longwave@mondrake is there a [policy, no patch] issue for typed properties, or should we open one?
Comment #25
mondrakeI do not think there’s one, maybe ask in Slack?
Comment #26
longwaveOpened #3291517: [policy, no patch] Use type declarations for new class properties
Comment #27
mondrakeComment #28
mondrakeMade changes according to #23 and #3291517: [policy, no patch] Use type declarations for new class properties.
Comment #29
mondrakeThere are only three entries left in baseline now.
One refers to the
$value
property inTypedData
, and two to entities code. Both cases require some issue of its own, because adding the definition has side effects that require code refactoring that goes beyond the scope here.Comment #30
longwaveTwo little notes and one actual question.
Comment #31
mondrakeComment #32
longwaveThanks, this all looks good to me now.
Comment #33
mondrakerebased
Comment #34
mondrakerebased
Comment #35
alexpottCan we can this one in two parts. Can we can one where all the public properties are added and then another issue where you are proposing to not use a public property. Because the non public properties require much more consideration.
Comment #36
mondrakeOK, let's start with the public ones then.
Comment #37
mondrakeFiled #3295157: Fix 'Access to an undefined property' PHPStan L0 errors - public properties.
Comment #38
mondrakeRerolled after commit of #3295157: Fix 'Access to an undefined property' PHPStan L0 errors - public properties
Comment #39
andypost+1 to RTBC, it will be helpful to minimize amount of failures at CI
Related somehow is not caught by this #3295813: ViewsEntitySchemaSubscriber access undefined property of View
Comment #40
andypostProbably it makes sense to split the issue further - many properties are added without descriptions and not clear are they required or not
For example - it makes sense as separate issue
Comment #41
andypostPHP 8.2 reveals 3 the most common reasons for failed tests https://dispatcher.drupalci.org/job/drupal_patches/138678/testReport/jun...
Comment #42
catchStill needs more review for Berdir's comments, and added a couple on the MR too.
Comment #43
andypostThere's a lot more revealed via #3295821: Ignore: patch testing issue for PHP 8.2 attributes and it looks like makes sense to split the issue, at least for migrations, view and tests
Comment #44
mondrakeI see @catch already filed a DiffEngine replacement issue, #3299678: Deprecate DiffEngine and replace with sebastian/diff.
Comment #45
xjmComment #46
Spokje@mondrake: If you're willing to do one more reroll, I'm willing to do a review and by what I've seen so far in the MR that would almost certainly lead to an RTBC from me.
Comment #47
mondrakedone
Comment #48
mondrakeComment #49
Spokje@mondrake:
Damn, you're quick :)
Left three (per usual slightly(?) annoying) nitpicks about comments. You can ignore them if you want, they are most definitely not blocking this otherwise very nice clean-up.
I would suggest either changing them or closing them, afterwards put it back on NR, and if TestBot agrees, this is RTBC for me.
Comment #50
mondrakeThanks a lot @Spokje, no annoyance.
Comment #51
SpokjeAll my (feeble) nitpicks were addressed. For me this is RTBC if TestBot also agrees.
Comment #52
andypostThank you!
It will have collision with #3308744: Fix magic connection property access from \Drupal\Core\FileTransfer\FileTransfer::__get() but nitpicks could be polished later
Comment #54
catchCommitted/pushed to 10.1.x and cherry-picked to 10.0.x.
Moving to 9.5.x for backport, but not sure what to do about the type hints here - @alexpott suggested specifying the properties without the type hints, maybe that's the best we can do?
Comment #56
SpokjeComment #58
SpokjeWell, that was a "bit of a grind"...
Attached interdiff between 10.0/10.1 MR and the 9.5 MR.
Comment #59
SpokjeComment #60
longwaveThis part of the interdiff looks weird, not sure what happened here. Everything in the MR and everything else in the interdiff looks correct so this is RTBC.
Comment #61
SpokjeThanks @longwave, noticed that "weirdness" in the interdiff as well, but, after comparing the visual representations of the changes in both MRs, I couldn't see a problem. Good to hear that confirmed.
Comment #63
catchWell that was quick.
Committed/pushed to 9.5.x, thanks!
Comment #64
Spokje(Thanks @mondrake for kicking off a PHP7.3 test. Should have thought of that myself)
Comment #67
cilefen CreditAttribution: cilefen commentedWe have a report in #3321338: Multiple deprecation notices on installing Drupal 9.5 on php 8.2 and mysql 8 about Role.php not being fixed in 9.5.x.