Review main Merged

77846[TASK] Make extbase persistence generic (phpstan-wise)

Alexander Schnitzler CR +2 V +2 Normal +91 −13 updated 03/01/23, 09:40

Commit message

After extbase's repository interface and classes received support
for phpstan generics, the rest of the persistence related classes
also support phpstan generics:

- QueryInterface and Query
- QueryResultInterface and QueryResult
- Otherwise involved classes like factories and data mappers

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Oliver Klee +1
    • Markus Klein +1
    • Torben Hansen +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Oliver Klee +1
    • Markus Klein +1
    • Torben Hansen +1
    • core-ci +1 CI

Issues 1

Files 14

Review log 2528

Show 3 earlier messages
  1. Alexander Schnitzler uploaded patch set 1 02/13/23, 21:22

  2. Alexander Schnitzler marked it work in progress 02/13/23, 21:23

  3. Oliver Klee commented on patch set 1 02/13/23, 21:31

    DataMapper.php:92

    This should be more precise: T of object

    DataMapper.php:94

    more precise (to communicate that the array has subsequent indices starting at 0): list<T>

    Query.php:64

    class-string<T>

    Query.php:229

    Could we make T[] more specific as list<T> here?

    QueryResult.php:50

    Do we know anything about the array keys here?

    QueryResult.php:136

    Do we know anything about the array keys here?

    QueryInterface.php:115

    Do we know anything about the array keys here?

    QueryResultInterface.php:54

    Do we know anything about the array keys here?
  1. core-ci voted on patch set 1 V -1 02/13/23, 22:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37664

  2. Alexander Schnitzler uploaded patch set 2 V -1 02/14/23, 11:33

  3. Alexander Schnitzler commented on patch set 2 02/14/23, 11:36

    DataMapper.php:92 Reply

    Ack

    DataMapper.php:94 Reply

    Done

    Query.php:64 Reply

    Done

    Query.php:229 Reply

    Done

    QueryResult.php:50 Reply

    Done

    QueryResult.php:136 Reply

    Done

    QueryInterface.php:115 Reply

    Done

    QueryResultInterface.php:54 Reply

    Done
  4. Oliver Klee commented on patch set 2 02/14/23, 11:41

    DataMapper.php:157

    I propose having a method_exists check here. This will actually solve the problem (as a short-term solution), and it will also make PHPStan (rightfully) happy.
  5. core-ci voted on patch set 2 V +1 02/14/23, 11:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37684

  6. Alexander Schnitzler commented on patch set 2 02/14/23, 11:46

    QueryResult.php:29

    One question remains here. Technically, we do receive a `list<TValue>` from the datamapper, hence, `$queryResult` is an `\Iterator` and `\ArrayAccess` with `TKey` being `int`. Question is, if we want to narrow down the type for phpstan without being able to do so via type declarations. `\ArrayAccess::offsetSet()` e.g., has a `mixed` type declaration in the php core we cannot override. But our usage of `offsetSet()` inside the extbase persistence is limited to `TKey` being `int`. Only thing we can do (breaking), is to limit the accepted type inside those methods and throw `\InvalidArgumentException`'s in case `offsetSet()` is called with a `string` as `key` for instance. IMHO, we should try to narrow the type down to `int`, first of all with phpstan annotations and furthermore with `\InvalidArgumentException`'s. Another idea: Limit key to `int|numeric-string` and also allow the external api `findByUid()` behave the same.
  7. Alexander Schnitzler commented on patch set 2 02/14/23, 11:51

    DataMapper.php:157 Reply

    I'd opt for `is_callable` instead but I get the gist. I'd still argue against if because we'd be calling this inside a loop for each database row that is converted to an object. Might be a small impact in cpu time but we know this code works because of how the framework around is built. I'd rather solve this properly because we already have more ignored phpstan errors surrounding this and similar issues. There are a couple of methods on AbstractDomainObject which are not part of the DomainObjectInterface contract.
  8. Alexander Schnitzler commented on patch set 2 02/14/23, 11:51

    This change is ready for review.
  9. Oliver Klee commented on patch set 2 02/18/23, 14:45

    DataMapper.php:157 Reply

    I'd be fine either way (method_exists, is_callable or solving this properly) and would prefer the "solving this properly" option. What would that entail? Have DomainObjectInterface extend ObjectMonitoringInterface?

    QueryResult.php:29 Reply

    I'd prefer to have this as narrow as possible (int), but would suggest to do this in a separate change to keep the changes relatively small and reduce the impact of each change.
  10. Alexander Schnitzler commented on patch set 2 02/19/23, 08:29

    DataMapper.php:157 Reply

    Yes, that's the easiest way to achieve this. But, can we do it in a separate patch? I will prepare it.

    QueryResult.php:29 Reply

    Ack
  11. Oliver Klee commented on patch set 2 02/19/23, 11:05

    DataMapper.php:157 Reply

    Yes, that would be perfectly fine with me. Thanks!
  12. Markus Klein voted on patch set 2 V +1 CR +1 02/24/23, 14:36

  13. Oliver Klee voted on patch set 2 CR +1 02/24/23, 14:58

  14. Oliver Klee voted on patch set 2 V +1 02/24/23, 14:58

  15. Torben Hansen voted on patch set 2 V +1 CR +1 02/28/23, 18:13

  16. Christian Kuhn commented on patch set 2 03/01/23, 08:01

    DataMapper.php:153

    @todo
  17. Christian Kuhn uploaded patch set 3 CR +1 V +1 03/01/23, 08:34

  18. Christian Kuhn commented on patch set 2 03/01/23, 08:34

    DataMapper.php:153 Reply

    Done
  19. Christian Kuhn voted on patch set 3 V +1 CR +1 03/01/23, 08:34

  20. Markus Klein voted on patch set 3 V +1 CR +1 03/01/23, 08:39

  21. Torben Hansen voted on patch set 3 V +1 CR +1 03/01/23, 08:40

  22. Oliver Klee voted on patch set 3 V +1 CR +1 03/01/23, 08:55

  23. core-ci voted on patch set 3 V +1 03/01/23, 09:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38249

  24. Christian Kuhn voted on patch set 3 V +2 CR +2 03/01/23, 09:40

  25. Christian Kuhn merged patch set 4 03/01/23, 09:40