Review main Merged

65464[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:frontend

Alexander Schnitzler CR +2 V +2 Hard +197 −156 updated 09/23/20, 16:39

Commit message

This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Review

  • Code review CR +2 Done
    • Daniel Goerz +2
    • Christian Kuhn +1
  • Verified V +2 Done
    • Daniel Goerz +2
    • Christian Kuhn +1
    • TYPO3com +1 CI

Issues 1

Files 24

Show 4 more files

Review log 3954

Show 1829 earlier messages
  1. Alexander Schnitzler uploaded patch set 1 08/26/20, 13:22

  2. Alexander Schnitzler wrote 08/26/20, 13:28

    Topic set to phpstan
  3. TYPO3com voted on patch set 1 V -1 08/26/20, 14:16 Completed build in 38m 42s on Wed, 26 Aug, 02:16 PM Test Summary: 48 of 71605 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4985

  4. TYPO3com commented on patch set 1 08/27/20, 08:34 Completed build in 19h 35m 02s on Thu, 27 Aug, 08:34 AM Test Summary: 32 of 73577 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4985

  5. Alexander Schnitzler uploaded patch set 2 08/28/20, 07:52

  6. TYPO3com voted on patch set 2 V -1 08/28/20, 08:04 Completed build in 12m 01s on Fri, 28 Aug, 08:04 AM Test Summary: 72763 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5024

  7. TYPO3com voted on patch set 2 V +1 08/28/20, 08:11 Completed build in 31m 30s on Fri, 28 Aug, 08:11 AM Test Summary: 73092 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5024

  8. Oliver Klee voted on patch set 2 CR +1 08/28/20, 10:37

  9. Jörg Bösche commented on patch set 2 V +1 CR +1 08/28/20, 13:21

    Verified on v11-dev (master) with EXT:bootstrap (11.1.0-dev) and EXT:introduction (4.2.0). Frontend works for me.
  10. Alexander Schnitzler updated the commit message in patch set 3 09/03/20, 15:50

  11. TYPO3com voted on patch set 3 V +1 09/03/20, 16:40 Completed build in 43m 08s on Thu, 3 Sep, 04:40 PM Test Summary: 73182 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5194

  12. Oliver Klee voted on patch set 3 CR +1 09/04/20, 07:49

  13. Alexander Schnitzler uploaded patch set 4 09/07/20, 12:14

  14. Alexander Schnitzler commented on patch set 4 09/07/20, 12:15

    I had to rebase this patch and add a lot of type casts due to previously merged patches which introduced a lot of new errors.
  15. TYPO3com voted on patch set 4 V -1 09/07/20, 12:28 Completed build in 13m 19s on Mon, 7 Sep, 12:28 PM Test Summary: 73227 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5322

  16. Alexander Schnitzler uploaded patch set 5 09/07/20, 13:07

  17. TYPO3com voted on patch set 5 V +1 09/07/20, 13:19 Completed build in 11m 40s on Mon, 7 Sep, 01:19 PM Test Summary: 73227 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5324

  18. Oliver Klee voted on patch set 5 CR +1 09/07/20, 13:24

  19. Alexander Schnitzler uploaded patch set 6 09/08/20, 09:33

  20. Alexander Schnitzler wrote 09/08/20, 09:34

    Description set to "rebase"
  21. Oliver Klee voted on patch set 6 CR +1 09/08/20, 09:46

  22. TYPO3com voted on patch set 6 V -1 09/08/20, 09:46 Completed build in 12m 37s on Tue, 8 Sep, 09:46 AM Test Summary: 1 of 73712 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5358

  23. TYPO3com voted on patch set 6 V +1 09/08/20, 09:55 Completed build in 34m 44s on Tue, 8 Sep, 09:55 AM Test Summary: 73227 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5358

  24. Daniel Goerz commented on patch set 6 CR -1 09/09/20, 11:31

    on it
  25. Daniel Goerz uploaded patch set 7 09/09/20, 12:28

  26. Daniel Goerz uploaded patch set 8 09/09/20, 12:35

  27. TYPO3com voted on patch set 7 V +1 09/09/20, 12:39 Completed build in 10m 55s on Wed, 9 Sep, 12:39 PM Test Summary: 73173 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5411

  28. TYPO3com voted on patch set 8 V +1 09/09/20, 12:48 Completed build in 12m 25s on Wed, 9 Sep, 12:48 PM Test Summary: 73173 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5412

  29. Daniel Goerz commented on patch set 8 09/09/20, 12:57

    ContentObjectRenderer.php:1004 Unresolved

    $imageFile can be instanceof File and instanceof FileReference which would cause problems here and on multiple different places in this function where it is treated as a string.
  1. Daniel Goerz voted on patch set 8 V +1 CR +1 09/09/20, 12:59

  2. Sascha Egerer commented on patch set 8 CR -1 09/09/20, 13:07

    I'm open for comments - please don't feel offended :) I may also be wrong at some places

    ContentObjectRenderer.php:1004

    File and FileReference do not have a toString method so this will fail, right? But i wonder why phpstan does not catch this issue

    ContentObjectRenderer.php:1257

    I would do the cast in line 1253 instead. $functionType = (string)($this->stdWrapOrder[$functionName] ?? '');

    ContentObjectRenderer.php:1306 Unresolved

    I think we could use scalar|null as type as float would also be possible

    ContentObjectRenderer.php:1368

    I would now use "trim($tags) !== ''" instead but this would change the behavior a bit but IMO it would fix a bug as the value "0" would not work with the current implementation. Opinions?

    ContentObjectRenderer.php:1898

    I would also change the type here as we expect a float

    ContentObjectRenderer.php:1902

    Default value for content could be 0 now as we are casting it to float anyways

    ContentObjectRenderer.php:2006

    type should be adjusted to int

    ContentObjectRenderer.php:2010

    default value should be changed to 0 as we cast it to int anyways

    ContentObjectRenderer.php:2640

    I think we can return early if $temp is empty. "?:" should IMO be prevented as it does some internal castings again and could end up in unexspacted behavior in some cases. $temp = explode($char, $content); if (empty($temp)) { return ''; }

    ContentObjectRenderer.php:2949

    This is a good place where some logging could be added as if preg_split is false we are sure that something went wrong. IMO ignoring the false value does hide an existing issue. Opinions?

    ContentObjectRenderer.php:3132

    value "0" will now return true but did not before that change. So the behavior is changed

    ContentObjectRenderer.php:3204

    Should be cast be done in line 3172? The value is also used at 3195 and 3213 but without a cast. Not sure about the code flow but don't really see a reason to not cast the value in general. By the way $typoScriptService->explodeConfigurationForOptionSplit can only handle strings and arrays anyway so changing this would also change behavior but i think is a change that will end up in an expected behavior

    ContentObjectRenderer.php:3436

    Good place to add some logging if return value is "null". This may happen not only if the regex is wrong but also other things happen like backtrack-limit is reached. https://www.php.net/manual/en/pcre.configuration.php#ini.pcre.backtrack-limit

    ContentObjectRenderer.php:3798

    I would use null coalesce here as it's more explicit $linkUrl = $this->processUrl(UrlProcessorInterface::CONTEXT_COMMON, $scheme . $parts[0], $conf) ?? '';

    ContentObjectRenderer.php:3851

    I would cast $conf to an array at the beginning of the method as it's expected to be an array also at other places

    ContentObjectRenderer.php:4990

    If preg_replace does not return a string i would add some logging instead of just casting it to string

    ContentObjectRenderer.php:5191

    Instead of casting i would do an early return here. $listArr = preg_split('/[,;' . LF . ']/', $content); if ($listArr === false) { return ''; }

    ContentObjectRenderer.php:6504

    we can remove "?? []", right?

    ContentObjectRenderer.php:6524

    we can remove "?? []", right?

    ContentObjectRenderer.php:6537

    we can remove "?? []", right?
  3. Daniel Goerz commented on patch set 8 09/09/20, 13:41

    ContentObjectRenderer.php:1004 Reply

    yes, see my comment. This probably needs to be tackled in a master only patch because this method is @internal only in master. This method is "broken" not only here

    ContentObjectRenderer.php:1257 Reply

    Done

    ContentObjectRenderer.php:1368 Reply Unresolved

    Lets not change behavior here if we can avoid it

    ContentObjectRenderer.php:1898 Reply

    the stdWrap_ functions will always receive strings see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::stdWrap, so I would not change that as we would introduce even more problems

    ContentObjectRenderer.php:1902 Reply

    the stdWrap_ functions will always receive strings see above

    ContentObjectRenderer.php:2006 Reply

    the stdWrap_ functions will always receive strings see above

    ContentObjectRenderer.php:2010 Reply

    the stdWrap_ functions will always receive strings see above

    ContentObjectRenderer.php:2640 Reply

    I thought about this as well but wanted to change as little as possible but you are probably right.

    ContentObjectRenderer.php:2949 Reply

    Lets not add logging in phpstan patches :) You are welcome to open an issue where we can track such things

    ContentObjectRenderer.php:3132 Reply

    Ack

    ContentObjectRenderer.php:3204 Reply

    Done

    ContentObjectRenderer.php:3436 Reply

    see above

    ContentObjectRenderer.php:3798 Reply

    Done

    ContentObjectRenderer.php:3851 Reply

    That was not part of this patch

    ContentObjectRenderer.php:5191 Reply

    Done
  4. Daniel Goerz uploaded patch set 9 09/09/20, 13:42

  5. Daniel Goerz commented on patch set 9 V +1 CR +1 09/09/20, 13:42

    ContentObjectRenderer.php:6504 Reply

    Done

    ContentObjectRenderer.php:6524 Reply

    Done

    ContentObjectRenderer.php:6537 Reply

    Done
  6. TYPO3com voted on patch set 9 V +1 09/09/20, 13:55 Completed build in 12m 50s on Wed, 9 Sep, 01:55 PM Test Summary: 73173 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5416

  7. Oliver Klee voted on patch set 9 CR +1 09/09/20, 15:07

  8. Alexander Schnitzler commented on patch set 9 CR -1 09/09/20, 16:41

    ContentObjectRenderer.php:6507

    The now removed ?? [] has been introduced a few days ago because something broke Bennis frontend. See https://review.typo3.org/c/Packages/TYPO3.CMS/+/65618 please. I don't have any stakes in this, just wanted to point to that very recent change. We should double check what solution is right.
  9. Daniel Goerz commented on patch set 9 09/09/20, 16:47

    ContentObjectRenderer.php:6507 Reply

    How can $configuration be null here?
  10. Daniel Goerz commented on patch set 9 09/09/20, 16:49

    ContentObjectRenderer.php:6507 Reply

    Only the three places are adapted that have $configuration always defined as an array, all other places are not touched
  11. Daniel Goerz commented on patch set 9 09/09/20, 17:27

    ContentObjectRenderer.php:6507 Reply Unresolved

    Having those null checks are phpstan errors by itself Line ContentObjectRenderer.php 6507 Variable $configuration on left side of ?? always exists and is not nullable. You can check this by turning the nullCoalesce toggle on parameters: featureToggles: nullCoalesce: true
  12. Alexander Schnitzler voted on patch set 9 CR 0 09/09/20, 17:34

  13. Sascha Egerer commented on patch set 9 CR -1 09/10/20, 04:57

    ContentObjectRenderer.php:1004 Reply

    Ok so should this be done i a difference patch set, first?

    ContentObjectRenderer.php:1004

    My previous comment is still valid. $imageFile can be a File or FileReference which do not have a toString method as far as i can see. So this will fail if $imageFile is not already a scalar value, right? Check should be adjusted to if (isset($conf['file.'] && is_scalar($imageFile))) {

    ContentObjectRenderer.php:1898 Reply

    Ack

    ContentObjectRenderer.php:1902 Reply

    Ack

    ContentObjectRenderer.php:2006 Reply

    Ack

    ContentObjectRenderer.php:2010 Reply

    Ack

    ContentObjectRenderer.php:2640 Reply

    As it would prevent access to non existing array keys and therefore prevent a php info message i would vote for this change. Running the code with an empty $temp does not make sense at all...

    ContentObjectRenderer.php:2949 Reply

    But phpstan points exactly to those points. If we do now "fix" those issues we won't find them anymore. This is exactly why i'm a bit unhappy if those patches are merged. I'm fine with not adding the log message in this patch but then we should add the logging at least in a separate patch before merging this patch. Opinions?

    ContentObjectRenderer.php:3436 Reply

    IMO logging should be added first in a different patch

    ContentObjectRenderer.php:3851 Reply

    But if we merge that patch we won't find those places anymore. So we should first fix that issue before merging this patch.

    ContentObjectRenderer.php:4990 Reply

    Logging should be addd before merging this patch.
  14. Daniel Goerz uploaded patch set 10 09/23/20, 14:03

  15. Daniel Goerz commented on patch set 10 09/23/20, 14:07

    ContentObjectRenderer.php:1004 Reply Unresolved

    does not need to go first, IMHO, lets, keep this as is for now (first line of stdWrap($content, $config) is $content = (string)$content; btw) So this does not introduce a new problem. Lets come back to this in a dedicated patch and get this one in so we can move on.

    ContentObjectRenderer.php:1004 Reply

    Done

    ContentObjectRenderer.php:2640 Reply

    Done

    ContentObjectRenderer.php:2949 Reply

    Done

    ContentObjectRenderer.php:3436 Reply

    Done

    ContentObjectRenderer.php:3851 Reply

    Done

    ContentObjectRenderer.php:4990 Reply

    Done
  16. TYPO3com voted on patch set 10 V +1 09/23/20, 14:15 Completed build in 11m 34s on Wed, 23 Sep, 02:15 PM Test Summary: 73682 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5863

  17. Oliver Klee voted on patch set 10 CR +1 09/23/20, 14:49

  18. Daniel Goerz uploaded patch set 11 09/23/20, 15:36

  19. Daniel Goerz uploaded patch set 12 09/23/20, 15:37

  20. TYPO3com voted on patch set 11 V -1 09/23/20, 15:50 Completed build in 14m 42s on Wed, 23 Sep, 03:50 PM Test Summary: 72869 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5876

  21. TYPO3com voted on patch set 12 V +1 09/23/20, 15:57 Completed build in 18m 15s on Wed, 23 Sep, 03:57 PM Test Summary: 73681 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-5877

  22. Christian Kuhn voted on patch set 12 V +1 CR +1 09/23/20, 16:01

  23. Daniel Goerz voted on patch set 12 V +1 CR +1 09/23/20, 16:13

  24. Daniel Goerz voted on patch set 12 V +2 CR +2 09/23/20, 16:38

  25. Daniel Goerz merged patch set 13 09/23/20, 16:39