Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize generated code for Hydrators #2665

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jul 1, 2024

Q A
Type improvement
BC Break no
Fixed issues -
  • Add use function statement for compiler-optimized functions
  • Using null coalescence and short array syntax
  • Adding property type with CPP.

lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php Outdated Show resolved Hide resolved
Comment on lines +373 to +375
use function array_key_exists;
use function gettype;
use function is_array;
Copy link
Member Author

Choose a reason for hiding this comment

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

This functions are compiler-optimized.

\$this->dm = \$dm;
\$this->class = \$class;
}
public function __construct(private DocumentManager \$dm, private ClassMetadata \$class) {}
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the property type.

Comment on lines +384 to +386
public function hydrate(object \$document, array \$data, array \$hints = []): array
{
\$hydratedData = array();
\$hydratedData = [];
Copy link
Member Author

Choose a reason for hiding this comment

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

Short-array syntax.

@@ -167,8 +167,8 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
$code .= sprintf(
<<<EOF

/** @AlsoLoad("$name") */
if (!array_key_exists('%1\$s', \$data) && array_key_exists('$name', \$data)) {
// AlsoLoad("$name")
Copy link
Member Author

Choose a reason for hiding this comment

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

Reference to doctrine annotations is outdated.

@GromNaN GromNaN marked this pull request as ready for review July 1, 2024 13:36
@GromNaN GromNaN requested a review from alcaeus July 1, 2024 13:36
@malarzm malarzm added this to the 2.9.0 milestone Jul 1, 2024
@GromNaN GromNaN merged commit f57fcc3 into doctrine:2.9.x Jul 1, 2024
16 of 17 checks passed
@GromNaN GromNaN deleted the hydrator-factory branch July 1, 2024 19:54
alcaeus added a commit that referenced this pull request Sep 6, 2024
* 2.9.x: (24 commits)
  Fix typo in code example (#2670)
  Label PRs about GH actions with "CI" (#2632)
  Review basic mapping (#2668)
  Fix wording (#2667)
  Add native type to private properties and final classes (#2666)
  Review and add tests on `ResolveTargetDocumentListener` (#2660)
  Remove soft-delete-cookbook (#2657)
  doc: Remove wakeup and clone cookbook (#2663)
  Modernize generated code for Hydrators (#2665)
  Add tests for introduction (#2664)
  doc: Review mapping ORM and ODM cookbook (#2658)
  doc: Review cookbook on blending ORM and ODM (#2656)
  doc: Review and test validation cookbook (#2662)
  Update custom mapping example (#2654)
  doc: Review Simple Search Engine Cookbook (#2659)
  doc: Add cookbook about embedding referenced documents using $lookup (#2655)
  doc: Add type to properties (#2652)
  doc: Review custom collections and repository docs (#2653)
  doc: Review Getting Started (#2650)
  Move annotations-reference to attributes-reference (#2651)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants