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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.3, 3.4
    • 3.3.2
    • 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.

    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

            jan.dagefoerde Jan Dageförde
            jan.dagefoerde Jan Dageförde
            Ankit Agarwal Ankit Agarwal
            Jun Pataleta Jun Pataleta
            Mark Nelson Mark Nelson
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11/Sep/17