Page MenuHomePhabricator

mediawiki/mediawiki-phan-config:0.4.0 does not process files at root of the repository
Closed, DeclinedPublic

Description

I encountered an issue with MediaWiki-extensions-LdapAuthentication and took that as an excuse to finally have a look at phan.

I have thus cloned mediawiki/extensions/LdapAuthentication and followed the wiki tutorial https://www.mediawiki.org/wiki/Continuous_integration/Tutorials/Add_phan_to_a_MediaWiki_extension

The various php files at the root of the repository are not processed when using phan -d . -p and have .phan/config.php using vendor/mediawiki/mediawiki-phan-config/src/config.php.

https://www.mediawiki.org/wiki/Continuous_integration/Phan mentions:

  • -d . tells it to analyze the current directory

That is misleading. From phan 1.2.4 help:

-d, --project-root-directory </path/to/project>
Hunt for a directory named .phan in the provided directory and read configuration file .phan/config.php from that path.

Hence -d seems to be solely to find the config file.

I had to use:

-l, --directory <directory>
A directory that should be parsed for class and method information. After excluding the directories defined in --exclude-directory-list, the remaining files will be statically analyzed for errors.

Thus, both first-party and third-party code being used by your application should be included in this list.

You may include multiple `--directory DIR` options.

So for LdapAuthentication I had to run phan with:

phan -p -d . -l .

That gets me results for the php files at the root of the repository.

Event Timeline

hashar created this task.Mar 6 2019, 7:02 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 6 2019, 7:02 PM

Seems to work by patching up to use '.' as the directory to look at (instead of relative includes, src and maintenance), then excluding vendor in case one installs phan via composer from the extension directory:

--- config.php.orig	2019-03-08 13:34:46.127531690 +0100
+++ config.php	2019-03-08 13:34:48.563551818 +0100
@@ -68,9 +68,7 @@
 	 * your application should be included in this list.
 	 */
 	'directory_list' => [
-		'includes/',
-		'src/',
-		'maintenance/',
+		'.',
 		'tests/phan/stubs/',
 		$IP . '/includes',
 		$IP . '/languages',
@@ -96,6 +94,7 @@
 	 */
 	"exclude_analysis_directory_list" => [
 		'tests/phan/stubs/',
+		'vendor',
 		$IP . '/includes',
 		$IP . '/languages',
 		$IP . '/maintenance',

Which, for LdapAuthentication installation gives me:

RecursiveDirectoryIterator::__construct(tests/phan/stubs/): failed to open dir: No such file or directory
LdapAuthentication.php:78 PhanUndeclaredVariableDim Variable $wgPasswordResetRoutes was undeclared, but array fields are being added to it.
LdapAuthentication.php:87 PhanUndeclaredVariableDim Variable $wgExtensionCredits was undeclared, but array fields are being added to it.
LdapAuthentication.php:97 PhanUndeclaredVariableDim Variable $wgAutoloadClasses was undeclared, but array fields are being added to it.
LdapAuthentication.php:101 PhanUndeclaredVariableDim Variable $wgMessagesDirs was undeclared, but array fields are being added to it.
LdapAuthentication.php:104 PhanUndeclaredVariableDim Variable $wgHooks was undeclared, but array fields are being added to it.
LdapAuthenticationPlugin.php:860 PhanUndeclaredVariableDim Variable $values was undeclared, but array fields are being added to it.
LdapAuthenticationPlugin.php:1077 PhanUndeclaredVariableDim Variable $values was undeclared, but array fields are being added to it.
LdapAuthenticationPlugin.php:1698 PhanTypeMismatchProperty Assigning bool to property but \LdapAuthenticationPlugin->userLDAPGroups is array<string,array<int,string>>|array<string,array{}>
LdapAuthenticationPlugin.php:1750 PhanTypeMismatchReturn Returning type array{dn:array{},short:array{}} but searchNestedGroups() is declared to return bool
LdapAuthenticationPlugin.php:1750 PhanTypeMismatchReturn Returning type array|array<string,array{}> but searchNestedGroups() is declared to return bool
LdapPrimaryAuthenticationProvider.php:167 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:168 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:182 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:192 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:197 PhanTypeMismatchArgument Argument 1 (req) is \MediaWiki\Auth\AuthenticationRequest but \LdapPrimaryAuthenticationProvider::failResponse() takes \MediaWiki\Auth\PasswordAuthenticationRequest defined at /home/hashar/projects/mediawiki/core/includes/auth/AbstractPasswordPrimaryAuthenticationProvider.php:85
LdapPrimaryAuthenticationProvider.php:304 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:312 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:325 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:328 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:336 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:337 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:337 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->retype
LdapPrimaryAuthenticationProvider.php:340 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:359 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:364 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:366 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:394 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password
LdapPrimaryAuthenticationProvider.php:395 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:406 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->domain
LdapPrimaryAuthenticationProvider.php:408 PhanUndeclaredProperty Reference to undeclared property \MediaWiki\Auth\AuthenticationRequest->password

Which seems about right.

Legoktm closed this task as Declined.Mar 8 2019, 8:37 PM

This is on purpose, extensions should be migrating to use the standard filesystem layout (src/, includes/, maintenance/) since we want that in other places too. I've documented this explicitly at https://www.mediawiki.org/w/index.php?diff=3128978&oldid=3128078&title=Continuous_integration%2FTutorials%2FAdd_phan_to_a_MediaWiki_extension&type=revision

Most of the stuff in the root (legacy PHP entry point and i18n files) don't really need or benefit from static analysis.

This is just the default configuration, and extension maintainers can override it if they have a good reason (I doubt it though).

That makes total sense. Thank you!