Jump to content

Continuous integration/Phan/Plugins

From mediawiki.org
These plugins are part of mediawiki/mediawiki-phan-config and run automatically when you run Phan with the standard MediaWiki configuration. For the separate security/taint plugin, see Phan-taint-check-plugin.

In addition to Phan's built-in checks, the MediaWiki configuration adds several project-specific plugins (in the src/Plugin directory of mediawiki/mediawiki-phan-config). Each emits its own issue type, listed below. As with any Phan issue, individual instances can be suppressed.

NoBaseExceptionPlugin

[edit]
MediaWikiNoBaseException
Emitted when code instantiates the base \Exception class directly (new Exception( ... )), which is disallowed by MediaWiki code conventions. See Manual:Coding conventions/PHP#Exception handling for advice on what to do instead.

RedundantExistenceChecksPlugin

[edit]
MediaWikiNoIssetIfDefined
Emitted when isset() is used on an expression that appears to be always set. isset() should only be used to suppress "undefined" errors; check whether the expression is null instead. See Manual:Coding conventions/PHP#isset().
MediaWikiNoEmptyIfDefined
Emitted when empty() is used on an expression that appears to be always set. empty() should only be used to suppress "undefined" errors. See Manual:Coding conventions/PHP#empty().

FirstClassCallableRecommendPlugin

[edit]
MediaWikiUseFirstClassCallable
MediaWikiUseFirstClassCallableInternalFunc
Emitted when a callable is written as a string or array (e.g. 'foo' or [ $obj, 'method' ]) where the first-class callable syntax (foo(...), $obj->method(...)) could be used instead. The ...InternalFunc variant is for built-in PHP functions. Supports --automatic-fix.

CrossComponentInternalPlugin

[edit]
MediaWikiCrossComponentInternalAccess
Emitted when code accesses a class member marked @internal from a different component than the one that declares it; see Stable interface policy#Remove guarantees. A component is identified as the directory containing the nearest extension.json, skin.json, or composer.json, so each extension, skin, repository, and library under vendor/ are considered separate components. The check covers method calls, property reads/writes, class-constant references, and new instantiation; a class-level @internal annotation implicitly marks every method, property, and constant declared in that class. It replaces Phan's built-in, namespace-scoped @internal checks (PhanAccessMethodInternal, PhanAccessPropertyInternal, PhanAccessClassConstantInternal, etc.), which are disabled in the MediaWiki configuration.
MediaWikiInternalNoComponent
A low-severity diagnostic emitted once per file when no extension.json, skin.json, or composer.json can be found above it, which means we can not confidently identify the component for the MediaWikiCrossComponentInternalAccess check; the file's own directory is then treated as a singleton "component".

RequireInternalPlugin

[edit]
MediaWikiMissingInternalAnnotation
Emitted when a non-anonymous class, interface, trait, or enum declared in a configured "internal" namespace is missing an @internal annotation. This helps enforce access conventions in a given package. This is opt-in per package: list the internal namespaces under plugin_config in your .phan/config.php (the default is none, so the check does nothing by default):
return [
    // ... rest of config ...
    'plugin_config' => [
        'require_internal_namespaces' => [
            'Wikimedia\\Parsoid\\Wt2Html',   // exact namespace
            'Wikimedia\\Parsoid\\*',          // and all sub-namespaces
        ],
    ],
];
A trailing \* matches sub-namespaces only, so Wikimedia\Parsoid\* matches Wikimedia\Parsoid\Wt2Html but not Wikimedia\Parsoid itself (list both if an inclusive match is wanted). Suppress the issue on an individual class to keep it part of the public API despite its namespace. Supports --automatic-fix (which adds the missing @internal tag).

See also

[edit]