Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

issue #118 - optional typed php 7.4 properties are raising engine errors #119

Closed

Conversation

pounard
Copy link
Contributor

@pounard pounard commented Jan 13, 2020

Fixes #118.

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

A few details are questionable:

  • addition of the ObjectProperty class: the code could have been less verbose, but it moves out a few responsibilities outside of the generator class,

  • same ObjectProperty class, I usually don't write the constructor when I use static factory methods, but anyway, I would have written an empty static constructor otherwise, it's just a matter of taste,

  • rewrite of code and factorisation into generatePropertyHydrateCall() that's subjective, I just find this variant more readable.

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Psalm is quite aggressive or I am too lazy ?

@Ocramius
Copy link
Owner

Psalm is quite aggressive or I am too lazy ?

It is very aggressive, which is good, since every tiny detail has major implications in OSS packages, even niche ones like this one (which BTW has ~500 installs/day)

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

It is very aggressive, which is good

Yes, it was sarcasm. It's actually quite drastic, I'll fix most errors I can.

@Ocramius
Copy link
Owner

I'll fix most errors I can.

Please only fix what's raised by your patch: I can work on the rest myself, while merging

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Please only fix what's raised by your patch

Yes of course.

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

I have to admit that fixing those kind of errors from phpcs:

  • Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
  • Expected 1 space(s) after NOT operator; 0 found

is quite annoying, are those part of your conventions for this package ?

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Same question for "Variable "$propertyName" not allowed in double quoted string; use sprintf() or concatenation instead", what's your preference between:

  • "foo " . $bar . " bar",
  • "foo {$bar} bar",
  • \sprintf("foo %s bar", $bar)

I mostly use the \sprintf() variant personally, except when generating code in a template fashion, where I prefer the "{$bar}" variant (it avoids having multiple dangling ' or " in the same line, which makes the whole more readable, once again, it's probably a matter of taste), especially when using the heredoc syntax, but I'll comply to your preference.

@Ocramius
Copy link
Owner

The first and the last are acceptable, string interpolation is to be avoided.

Don't overthink it BTW: if you need to auto-fix things, there's vendor/bin/phpcbf

@Ocramius
Copy link
Owner

are those part of your conventions for this package ?

Yes, this package relies on doctrine/coding-standard

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

The first and the last are acceptable, string interpolation is to be avoided.

Is there a technical reason for this ? From a code reader perspective, it seems much more fluent to read.

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Don't overthink it BTW: if you need to auto-fix things, there's vendor/bin/phpcbf

OK, I think it's your job then, seeing the commit history :) For the rest, if there's anything more structural or important to change, please tell me.

@Ocramius
Copy link
Owner

The first and the last are acceptable, string interpolation is to be avoided.

Is there a technical reason for this ? From a code reader perspective, it seems much more fluent to read.

Yes, I much prefer to avoid variable interpolation in strings: explicit concatenation is preferable.

I'll review again and take over for merge, if there's nothing left 👍

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Thanks a lot !

@pounard
Copy link
Contributor Author

pounard commented Jan 13, 2020

Yes, I much prefer to avoid variable interpolation in strings: explicit concatenation is preferable.

OK, I see that the technical reason is mostly taste :) If that's auto-fixable using phpcbf I'll leave it to you then !

@pounard
Copy link
Contributor Author

pounard commented Jan 21, 2020

What's the status of this PR ? Should I fix any other things ?

@Ocramius
Copy link
Owner

Didn't get to look at it, sorry

@pounard
Copy link
Contributor Author

pounard commented Jan 21, 2020

Don't worry, I'm just asking, we are actually starting a PHP 7.4 project where I'd like to use this component. We can still patch it locally but I'd very much prefer to use a vanilla stable version :)

@pounard
Copy link
Contributor Author

pounard commented Feb 21, 2020

Any news on this ? @Ocramius if you anything bothers you on how I did it I would pleased to fix or do another MR.

@Ocramius
Copy link
Owner

@pounard I'm checking this out locally: sorry, it simply slipped out of my TODOs. Thanks for the ping!

@Ocramius Ocramius self-assigned this Feb 21, 2020
@Ocramius Ocramius added the bug label Feb 21, 2020
@Ocramius Ocramius added this to the 3.1.0 milestone Feb 21, 2020
Ocramius added a commit that referenced this pull request Feb 21, 2020
@Ocramius Ocramius closed this in 7fd2f56 Feb 21, 2020
@Ocramius
Copy link
Owner

@pounard I've bumped to PHP 7.4, brought mutation test coverage back to 100% and applied CS fixes on top of your patch.

Turns out that verifying if ($property->allowsNull && ! $property->hasDefault) { was sufficient for our purposes! 👍

Thanks!

@pounard
Copy link
Contributor Author

pounard commented Feb 21, 2020

Thank you !

@pounard pounard deleted the issue-118-php74-hydrate-fails branch March 25, 2020 15:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With PHP 7.4, the hydrator breaks with required typed property
2 participants