Review main Merged

78014[FEATURE] Introduce non-magic repository find methods

Alexander Schnitzler CR +2 V +2 Hard +738 −122 updated 03/07/23, 13:34

Commit message

This change introduces alternative methods to magic method
__call() of extbase's Repository class. The magic method
allowed for calling findBy[Property](), findOneBy[Property]()
and countBy[Property](). Those methods are now implemented
with a slightly different method signature but with type
declaration and phpstan support.

The naming follows the one of doctrine/orm which is
implemented exactly the same.

The new methods are:

- findBy(array $criteria, ...): QueryResultInterface
- findOneBy(array $criteria, ...): object|null
- count(array $criteria, ...): int

Using the magic methods is deprecated but will only
trigger an E_USER_DEPRECATED error as of version 13.

Review

  • Code review CR +2 Done
    • Nikita Hovratov +2
    • Oliver Klee +1
    • Markus Klein +1
    • Benni Mack +1
  • Verified V +2 Done
    • Nikita Hovratov +2
    • Oliver Klee +1
    • Markus Klein +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 9

Review log 5569

Show 3344 earlier messages
  1. Alexander Schnitzler uploaded patch set 1 03/03/23, 11:09

  2. Alexander Schnitzler marked it work in progress 03/03/23, 11:09

  3. Alexander Schnitzler wrote 03/03/23, 11:09

    Topic set to extbase
  4. core-ci voted on patch set 1 V -1 03/03/23, 11:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38351

  5. Alexander Schnitzler uploaded patch set 2 V -1 03/03/23, 12:44

  6. core-ci voted on patch set 2 V -1 03/03/23, 13:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38356

  7. Alexander Schnitzler uploaded patch set 3 V -1 03/03/23, 14:06

  8. core-ci voted on patch set 3 V +1 03/03/23, 14:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38361

  9. Alexander Schnitzler uploaded patch set 4 V +1 03/03/23, 14:34

  10. Alexander Schnitzler commented on patch set 4 03/03/23, 14:34

    This change is ready for review.
  11. core-ci voted on patch set 4 V +1 03/03/23, 14:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38363

  12. Oliver Klee commented on patch set 4 03/04/23, 09:40

    I really love this feature! Thanks a lot, Alexander! I've added some minor comments.

    Repository.php:268

    Those array keys probably all should be `non-empty-string` (in all newly-added array annotations).

    Repository.php:269

    For all `array<string,Foo>`, please generally let's have a space after the comma for improved readability: `array<string, Foo>`

    Repository.php:272

    `$limit` and `$offset` should have `@param 0|positive-int|null` annotations.

    Repository.php:281

    This is not a boolean. Please let's make the condition explicit: `if is_array($orderBy)) {`

    Repository.php:285

    This is not a boolean. Please let's make the condition explicit: `if is_int($limit)) {`

    Repository.php:289

    This is not a boolean. Please let's make the condition explicit: `if is_int($offset)) {`

    Repository.php:302

    To reduce code duplication, I this method could call `findBy`.

    Repository.php:309

    This is not a boolean. Please let's make the condition explicit: `if is_array($orderBy)) {`

    Repository.php:322

    @phpstan-return 0|positive-int

    RepositoryTest.php:38

    This should be an intersection type, not a union type.

    RepositoryTest.php:45

    Please let's use native type declarations for all those properties.
  13. Alexander Schnitzler commented on patch set 4 03/04/23, 11:25

    Repository.php:268 Reply

    Ack

    Repository.php:269 Reply

    Ack

    Repository.php:272 Reply

    Ack

    Repository.php:281 Reply

    Ack

    Repository.php:285 Reply

    Ack

    Repository.php:289 Reply

    Ack

    Repository.php:302 Reply

    Ack

    Repository.php:309 Reply

    Ack

    Repository.php:322 Reply

    Ack

    RepositoryTest.php:38 Reply

    This is copy paste code of the same test in namespace Unit instead of UnitDeprecated. This code will be removed in 13.0, so I suggest to simply leave it as is.

    RepositoryTest.php:45 Reply

    This is copy paste code of the same test in namespace Unit instead of UnitDeprecated. This code will be removed in 13.0, so I suggest to simply leave it as is.
  14. Alexander Schnitzler uploaded patch set 5 V +1 03/04/23, 11:48

  15. Alexander Schnitzler commented on patch set 5 03/04/23, 11:49

    Repository.php:268 Reply

    Done

    Repository.php:269 Reply

    Done

    Repository.php:272 Reply

    Done

    Repository.php:281 Reply

    Done

    Repository.php:285 Reply

    Done

    Repository.php:289 Reply

    Done

    Repository.php:302 Reply

    Done

    Repository.php:309 Reply

    Done

    Repository.php:322 Reply

    Done
  16. core-ci voted on patch set 5 V +1 03/04/23, 11:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38435

  17. Oliver Klee commented on patch set 5 03/04/23, 12:03

    RepositoryTest.php:38 Reply

    Ack
  18. Oliver Klee commented on patch set 5 03/04/23, 12:03

    RepositoryTest.php:45 Reply

    Ack
  19. Oliver Klee voted on patch set 5 V +1 CR +1 03/04/23, 12:04

  20. Simon Schaufelberger commented on patch set 5 V +1 CR +1 03/04/23, 13:27

    thank you, love this patch!
  21. Markus Klein commented on patch set 5 03/04/23, 20:40

    Repository.php:321

    Since calling logicalAnd with only one constraint creates some really weird SQL conditions. Maybe we should handle that case here.
  22. Alexander Schnitzler commented on patch set 5 03/05/23, 10:05

    Repository.php:321 Reply

    Good catch, will update a new patch set.
  23. Alexander Schnitzler rebased onto patch set 6 CR +1 V +1 03/05/23, 10:24

  24. Alexander Schnitzler uploaded patch set 7 03/05/23, 10:25

  25. Alexander Schnitzler uploaded patch set 8 03/05/23, 10:27

  26. core-ci voted on patch set 6 V -1 03/05/23, 10:39 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38485

  27. core-ci voted on patch set 8 V +1 03/05/23, 10:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38487

  28. Oliver Klee commented on patch set 8 V +1 CR +1 03/05/23, 11:19

    Repository.php:321 Reply

    Done
  29. core-ci voted on patch set 7 V +1 03/05/23, 11:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38486

  30. Markus Klein voted on patch set 8 V +1 CR +1 03/06/23, 09:27

  31. Alexander Schnitzler commented on patch set 8 CR -1 03/06/23, 09:30

    Benni approached me and we will not deprecate magic methods yet. Will push a new patch set.
  32. Alexander Schnitzler uploaded patch set 9 CR +1 V +1 03/06/23, 09:33

  33. core-ci voted on patch set 9 V +1 03/06/23, 09:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38525

  34. Alexander Schnitzler uploaded patch set 10 V +1 03/06/23, 09:47

  35. Alexander Schnitzler commented on patch set 10 03/06/23, 09:48

    Sorry for the confusion. The idea is to mark magic methods deprecated and to communicate the decision now but only trigger an error as of v13.
  36. Oliver Klee voted on patch set 10 V +1 CR +1 03/06/23, 09:54

  37. Oliver Klee voted on patch set 10 V 0 03/06/23, 09:55

  38. core-ci voted on patch set 10 V +1 03/06/23, 10:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38528

  39. Nikita Hovratov uploaded patch set 11 CR +1 V +1 03/06/23, 10:20

  40. core-ci voted on patch set 11 V +1 03/06/23, 10:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38536

  41. Oliver Klee voted on patch set 11 V +1 CR +1 03/06/23, 10:32

  42. Nikita Hovratov voted on patch set 11 V +1 CR +1 03/06/23, 10:39

  43. Stefan Froemken commented on patch set 11 V +1 CR +1 03/06/23, 17:35

    Thank you. Good work. Tested all new methods with one of my example extension for V12.
  44. Markus Klein commented on patch set 11 03/07/23, 08:10

    Will adjust the rsts

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:22

    IDEs

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:49

    IDEs

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:62

    remove such adjectives, this is subjective to the reader usually
  1. Markus Klein commented on patch set 12 CR +1 V +1 03/07/23, 08:11

    Published edit on patch set 11.
  2. Markus Klein commented on patch set 12 03/07/23, 08:12

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:22 Reply

    Done

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:49 Reply

    Done

    Deprecation-100071-IntroduceNon-magicRepositoryFindMethods.rst:62 Reply

    Done
  3. Markus Klein voted on patch set 12 V +1 CR +1 03/07/23, 08:13

  4. core-ci voted on patch set 12 V +1 03/07/23, 08:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38580

  5. Nikita Hovratov voted on patch set 12 V +1 CR +1 03/07/23, 08:34

  6. JAKOTA Design Group GmbH commented on patch set 12 03/07/23, 08:50

    Repository.php:324

    I know this is just a type save reimplementation. But something I always wondered, isn't it a bit wasteful to retrieve all the data from the db just to count the rows? Or do I get this totally wrong?
  7. Nikita Hovratov commented on patch set 12 03/07/23, 09:07

    Repository.php:324 Reply

    findBy doesn't actually execute a real SQL statement yet. QueryResultInterface is a lazy result object. So by using `count` on it, it will result in something like `SELECT COUNT(*)`.
  8. JAKOTA Design Group GmbH commented on patch set 12 03/07/23, 09:30

    Repository.php:324 Reply

    Ok, Thanks. I thought $query->execute() does exactly that. Good to know.
  9. Oliver Klee voted on patch set 12 V +1 CR +1 03/07/23, 10:23

  10. Benni Mack commented on patch set 12 CR -2 03/07/23, 10:39

    will adapt the RSTs.-..
  11. Stefan Froemken voted on patch set 12 V +1 CR +1 03/07/23, 10:53

  12. Benni Mack uploaded patch set 13 CR +1 V +1 03/07/23, 11:41

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR is:MIN")
  13. Benni Mack voted on patch set 13 V +1 CR +1 03/07/23, 11:41

  14. core-ci voted on patch set 13 V +1 03/07/23, 11:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38591

  15. Oliver Klee voted on patch set 13 V +1 CR +1 03/07/23, 12:00

  16. Nikita Hovratov commented on patch set 13 03/07/23, 12:20

    Deprecation-100071-MagicRepositoryFindByMethods.rst:33

    they will trigger a deprecation notice in v13. This sentence needs rework.
  17. Nikita Hovratov uploaded patch set 14 CR +1 V +1 03/07/23, 12:22

  18. Nikita Hovratov commented on patch set 13 03/07/23, 12:23

    Deprecation-100071-MagicRepositoryFindByMethods.rst:33 Reply

    Done
  19. Nikita Hovratov voted on patch set 14 V +1 CR +1 03/07/23, 12:23

  20. Oliver Klee voted on patch set 14 V +1 CR +1 03/07/23, 12:27

  21. Benni Mack voted on patch set 14 V +1 CR +1 03/07/23, 12:31

  22. Markus Klein voted on patch set 14 V +1 CR +1 03/07/23, 12:40

  23. core-ci voted on patch set 14 V +1 03/07/23, 13:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38594

  24. Nikita Hovratov voted on patch set 14 V +2 CR +2 03/07/23, 13:34

  25. Nikita Hovratov merged patch set 15 03/07/23, 13:34