Overview
In ClientServerConversionTrait we're currently doing this
$props_prepared_for_saving = [];
foreach ($props as $component_instance_uuid => $component_instance_props) {
foreach ($component_instance_props as $prop_name => $prop_source) {
$props_prepared_for_saving[$component_instance_uuid][$prop_name] = json_decode((string) $prop_source, TRUE);
}
}
This relies on the `__toString` method of propsources which transforms the value into JSON and then we immediately `json_decode` it.
Proposed resolution
Add a normalize method to each of the prop source classes and use that instead of casting to and from JSON to get an array representation
User interface changes
Comments
Comment #2
akhil babuComment #4
akhil babuAs suggested by @larowan, I have added a new method toArray() to the prop source classes
Comment #5
larowlanThis looks good to me, thanks @akhil babu
Comment #7
longwaveMade some improvements:
toArray()is abstract on the base class (we don't have an interface)__toString()is moved to the base class to avoid repetitionComment #8
larowlanNice improvement 🙌 - merge on green, re-ran the failing e2e 🤞
Comment #9
tedbowLooks good, I can't merge it until @wim leers or @f.mazeikis approves the merge request
Comment #10
wim leersMissing https://phpstan.org/writing-php-code/phpdoc-types#array-shapes.
Comment #11
wim leersTitle did not match actual MR.
Also: +1, this is long overdue!
Comment #12
wim leersCan't run phpstan locally while testing what I'm doing, due to:
Fix: remove the first one, because it's obsolete. Make the second one optional.
This must be the new PHPStan version that Drupal
11.xHEAD is installing — CI is pinning to11.1.xsince that is the current minor, and hence it's not spotting this problem. Doing that here is a distraction, so opened #3497866: CI: also test against next minor: 11.2.x aka Drupal 11.x HEAD to do that.Comment #13
wim leersFortunately, the PHPStan shape work was already done — I'd forgotten about that!
I did also find one more place where we can use the new method 🥳
Comment #15
wim leersComment #16
larowlan@wim w.r.t phpstan locally, I've got a `phpstan.larowlan.neon` and inside it I have
I've added this to .git/info/exclude so it doesn't get checked in.
In my pre-commit hooks I've got this (the ../../../bin/phpstan is the path in my setup to the phpstan binary)
This lets me tweak the phpstan setup without impacting the checked in version.
I've got similar things for phpcs and cspell too, also in my pre-commit
Happy to share if they're useful