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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.3, 3.4
    • Fix Version/s: 3.3.2
    • Component/s: Libraries
    • Labels:
    • Testing Instructions:
      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.
    • Affected Branches:
      MOODLE_33_STABLE, MOODLE_34_STABLE
    • Fixed Branches:
      MOODLE_33_STABLE
    • Pull Master Branch:
      MDL-59855-master

      Description

      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".

        Attachments

          Activity

            People

            • Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Sep/17