Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59855

PHPDoc type hints in OAuth 2 API are wrong in PHPStorm/IntelliJ

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.3.2
    • 3.3, 3.4
    • Libraries
    • MOODLE_33_STABLE, MOODLE_34_STABLE
    • MOODLE_33_STABLE
    • MDL-59855-master
    • Hide

      1. Start up your preferred IDE (preferrably not IntelliJ/PHPStorm for more validation)
      2. Look at lib/classes/oauth2/api.php and check whether type hints can be resolved.

      Show
      1. Start up your preferred IDE (preferrably not IntelliJ/PHPStorm for more validation) 2. Look at lib/classes/oauth2/api.php and check whether type hints can be resolved.

      In IntelliJ, the class resolution rules for type hints are identical to that of PHP compilation / execution. That means

      • if the using class is not in a namespace, relative and absolute namespace resolution is identical.
      • If the using class is in a namespace, all namespaces/classes are considered relative paths, starting at the current namespace,
      • unless the to-be-resolved namespace starts with a backslash () (we've all been there, pondering about bugs because \stdClass is not the same as stdClass, unless, of course, it is, because we are outside a namespace... ugh.  )

      IntelliJ assumes the same rules for interpreting types in PHPDoc as well. This causes problems in the new OAuth core libs. core\oauth2\api is namespaced (https://github.com/moodle/moodle/blob/1c6106e8a8dbeb95ce158e7013c226e033d0cb11/lib/classes/oauth2/api.php#L24) and provides type hints for its methods (parameter and return types), for example get_user_oauth_client(), https://github.com/moodle/moodle/blob/1c6106e8a8dbeb95ce158e7013c226e033d0cb11/lib/classes/oauth2/api.php#L317. The paths in those type hints (core\oauth2\client), however, are interpreted as relative paths, resulting effectively in e.g. \core\oauth2\core\oauth2\client.

      Steps to reproduce:
      Open lib/classes/oauth2/api.php in IntelliJ/PHPStorm and, after the full index is built, hover over the types. You will see the message "Undefined namespace oauth2".

        1. namespace-fixed.png
          77 kB
          Jan Dageförde
        2. namespace-undefined.png
          80 kB
          Jan Dageförde

            jan.dagefoerde Jan Dageförde
            jan.dagefoerde Jan Dageförde
            Ankit Agarwal Ankit Agarwal
            Jun Pataleta Jun Pataleta
            Mark Nelson Mark Nelson
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.