Review main Merged

78551[TASK] Enable strict typing for Icon::class and add title

Benjamin Kott CR +2 V +2 Normal +62 −81 updated 04/11/23, 09:44

Commit message

This patch enables strict types for the Icon:class.

We are also introducing a fluent setter object pattern
for and introducing a title property that can set
to be rendered directly on the icon.

This will avoid unnessesary <span title="...">...</span>
wraps around rendered icons, since it can now be added
directly to the icon.

..  code-block:: php

    // Before
    $iconMarkup = '
        <span title="title">
            ' . $this->iconFactory->getIcon('actions-open')->render() . '
        </span>
    ';

    // After
    $iconMarkup = $this->iconFactory->getIcon('actions-open')
        ->setTitle('title')
        ->render();

Review

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

Issues 1

Files 1

Review log 1418

  1. Benjamin Kott uploaded patch set 1 04/10/23, 11:35

  2. Benjamin Kott updated the commit message in patch set 2 04/10/23, 11:36

  3. core-ci voted on patch set 2 V -1 04/10/23, 12:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/40406

  4. core-ci voted on patch set 1 V -1 04/10/23, 12:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/40405

  5. Oliver Klee commented on patch set 2 04/10/23, 12:51

    Icon.php:113

    For the added fluent interface, we can should this annotation to let PHPStan know that the same instance will be returned (instead of only an instance of the same class): ```php /** * @return $this */ ```
  6. Benjamin Kott uploaded patch set 3 V -1 04/10/23, 16:13

  7. Benjamin Kott commented on patch set 3 04/10/23, 16:19

    Icon.php:113 Reply

    That would only make sense if we intend to let people extend it right? I think we should we should avoid phpstan only annotations if possible. I see no case that would make it necessary to extend this class, and would prefer to have it final at some point
  8. core-ci voted on patch set 3 V +1 04/10/23, 16:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/40414

  9. Oliver Klee commented on patch set 3 04/10/23, 17:16

    Icon.php:113 Reply

    No, this also helps us find/avoid bugs in the Core (as PHPStan then can analyze the Core code better).
  10. Oliver Klee commented on patch set 3 04/10/23, 17:32

    Icon.php:113 Reply

    And concerning the PHPStan-only annotations: As we also have the native `self` type declaration, even IDEs that do not recognize the `@return $this` annotation at least know the returned class. So we're not blocking/losing anything with the added annotation, but are gaining additional type safety by analysis.
  11. Oliver Klee commented on patch set 3 04/10/23, 17:32

    Icon.php:113 Reply

    And it also helps people who are using this class.
  12. Benjamin Kott commented on patch set 3 04/10/23, 21:04

    Icon.php:113 Reply

    I get your point, but it´s only relevant of you are EXTENDING this class - otherwise also phpstan will understand the native return type. As it should not be extended anyways and be final in the best case, there is no benefit in adding the annotation. It will always return an instance of Icon::class and nothing else.
  13. Oliver Klee uploaded patch set 4 V +1 04/11/23, 09:19

  14. Oliver Klee commented on patch set 4 CR +1 04/11/23, 09:19

    Icon.php:113 Reply

    Done (after a short discussion).
  15. core-ci voted on patch set 4 V +1 04/11/23, 09:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/40446

  16. Oliver Klee voted on patch set 4 V +1 04/11/23, 09:42

  17. Benni Mack voted on patch set 4 V +2 CR +2 04/11/23, 09:44

  18. Benni Mack merged patch set 5 04/11/23, 09:44