Review main Merged

74517[TASK] Introduce string fragment extraction

Oliver Hader CR +2 V +2 Hard +538 −0 updated 12/07/22, 13:28

Commit message

When working with variable interpolation and similar scenarios, in
most cases variables, constants, expressions, ... are embedded in
a solid string and can only be identified and extracted by the
corresponding "reader" or "parser".

This string fragment splitter aims to introduce a simpler way for
extracting and working with these embedded fragments.

Example:
    $pattern = new StringFragmentPattern(
      StringFragmentSplitter::TYPE_EXPRESSION,
      '%[^%]+%'
    );
    $splitter = new StringFragmentSplitter($pattern);
    $collection = $splitter->split(
      'Hello %variable% World!'
      FLAG_UNMATCHED_AS_NULL
    );

    // results in having
    // + StringFragment(type: 'raw', value: 'Hello ')
    // + StringFragment(type: 'expression', value: '%variable%')
    // + StringFragment(type: 'raw', value: ' World!')

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Andreas Kienast +1
    • Benni Mack +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Andreas Kienast +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 6

Review log 3038

Show 813 earlier messages
  1. Oliver Hader uploaded patch set 1 05/04/22, 13:17

  2. core-ci voted on patch set 1 V +1 05/04/22, 13:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26820

  3. Oliver Hader uploaded patch set 2 05/04/22, 13:47

  4. core-ci voted on patch set 2 V -1 05/04/22, 13:58 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26822

  5. Oliver Hader uploaded patch set 3 05/04/22, 19:14

  6. core-ci voted on patch set 3 V -1 05/04/22, 19:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26834

  7. Oliver Hader uploaded patch set 4 05/05/22, 06:53

  8. core-ci voted on patch set 4 V +1 05/05/22, 07:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26870

  9. crell commented on patch set 4 05/17/22, 17:21

    StringFragmentCollection.php:55

    withOnlyType() reads better, I think.

    StringFragmentCollection.php:86

    Why not just diff(), since that's what the PHP functions it's mimicking used? That would be more self-documenting.

    StringFragmentSplitter.php:29

    These can all be enums now. That would make the various mentions of "type" more self-evident elsewhere in the patch.

    StringFragmentSplitterTest.php:31

    Using a series of yield statements for this kind of provider tends to make them much easier to read and more maintainable. cf: https://peakd.com/hive-168588/@crell/fun-with-phpunit-data-providers (skip down to "do you yield?")
  10. Oliver Hader commented on patch set 4 06/01/22, 11:30

    StringFragmentCollection.php:55 Reply

    Done

    StringFragmentCollection.php:86 Reply

    Done "differentiate" would be the imperative message to that instance - however, I don't care much, thus "diff" it is...

    StringFragmentSplitter.php:29 Reply

    This change is targeted for TYPO3 v10 - no PHP 8.1 - no enums here

    StringFragmentSplitterTest.php:31 Reply

    For that particular test here I don't see it would be "much easier to read". The key of tests is to understand the application logic that actually should be asserted.
  11. Oliver Hader uploaded patch set 5 06/01/22, 11:30

  12. core-ci voted on patch set 5 V -1 06/01/22, 11:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27617

  13. Simon Schaufelberger commented on patch set 5 06/01/22, 12:48

    StringFragment.php:38

    please put the contructor first

    StringFragmentSplitter.php:29 Reply

    if this patch targets v10, then more backports need to be done like line 58
  1. Oliver Hader commented on patch set 5 06/01/22, 12:51

    StringFragment.php:38 Reply

    Why?

    StringFragmentSplitter.php:29 Reply

    The patch IS targeted for v10, and sure property types need to be adjusted...
  2. Oliver Klee commented on patch set 5 06/01/22, 12:55

    StringFragment.php:38 Reply

    By convention, the constructor always comes as the first method (so human readers have an easier time understanding the class). (This is not codified in any PSR standard, though, AFAIK.)
  3. Oliver Hader commented on patch set 5 06/01/22, 13:07

    StringFragment.php:38 Reply

    Never heard about that convention - do you have any links/resources for that?
  4. Oliver Klee commented on patch set 5 06/01/22, 13:34

    StringFragment.php:38 Reply

    a) Robert C. Martin: Clean Code, chapter 5, page 84, on vertical ordering: Methods should be roughly ordered by dependency, i.e., if A calls B, A should come first. (And related is the idea that methods should be in "reading order", i.e. mostly in the order in they are usually called.) There's a StackExchange thread on this: https://softwareengineering.stackexchange.com/questions/199311/most-human-friendly-way-to-order-class-method-definitions b) The Flow CGL: https://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartV/CodingGuideLines/PHP.html#php-in-general
  5. Oliver Hader commented on patch set 5 06/01/22, 17:02

    StringFragment.php:38 Reply

    Quoting Bob Martin completely > In general we want function call dependencies to point in the downward direction. That is, a function that is called should be below a function that does the calling. This creates a nice flow down the source code module from high level to low level. → and that basically the case here, since both static functions are factory methods, invoking the constructor when creating a new instance The other two references are rather opinionated and/or not strictly followed - e.g. the Flow reference mentions `__destruct` to be declared at the end of a class, which I think does not reflect reality. I'm going to keep the ordering of this change as is. Besides having these valuable discussions about code style and format, I'm also looking forward to seeing feedback on the actual application and functionality of this change.
  6. core-ci voted on patch set 5 V +1 06/02/22, 06:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27617

  7. Simon Schaufelberger commented on patch set 5 06/02/22, 11:32

    StringFragment.php:38 Reply

    so if the constructor should not be called directly but only via the static methods above, wouldn't it make sense to make the constructor protected?
  8. Simon Schaufelberger commented on patch set 5 06/02/22, 11:33

    StringFragmentSplitter.php:29 Reply

    That was exactly my question. Wouldn't it make sense to use PHP8.1 features here and then backport them differently?
  9. Oliver Hader commented on patch set 5 06/02/22, 11:33

    StringFragment.php:38 Reply

    > so if the constructor should not be called directly but only via the static methods above, wouldn't it make sense to make the constructor protected? The constructor still can be called directly
  10. Simon Schaufelberger commented on patch set 5 06/02/22, 11:38

    StringFragment.php:38 Reply

    Does it make sense to call it?
  11. Oliver Hader commented on patch set 5 06/02/22, 11:40

    Thanks for all of your feedback on this change... I'm giving up here and probably will pick it up at a later point.
  12. Oliver Hader abandoned the change 06/02/22, 11:40

  13. Oliver Hader restored the change 12/06/22, 12:33

  14. Oliver Hader commented on patch set 5 12/06/22, 12:35

    I'm giving this another try...

    StringFragment.php:38 Reply

    Done

    StringFragmentSplitter.php:29 Reply

    No
  15. Oliver Hader rebased onto patch set 6 V +1 12/06/22, 12:35

  16. core-ci voted on patch set 6 V +1 12/06/22, 12:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34718

  17. Oliver Klee wrote 12/06/22, 12:54

    Removed cc Oliver Klee.
  18. Oliver Hader uploaded patch set 7 V +1 12/06/22, 13:34

  19. Oliver Hader commented on patch set 7 12/06/22, 13:35

    StringFragmentSplitterTest.php:31 Reply

    It's not easier now, but I changed it to use `yield`
  20. core-ci voted on patch set 7 V +1 12/06/22, 13:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34721

  21. crell wrote 12/06/22, 20:09

    Removed cc crell.
  22. Benni Mack voted on patch set 7 V +1 CR +1 12/06/22, 22:39

  23. Andreas Kienast voted on patch set 7 V +1 CR +1 12/07/22, 08:59

  24. Oliver Hader voted on patch set 7 V +2 CR +2 12/07/22, 13:28

  25. Oliver Hader merged patch set 8 12/07/22, 13:28