build: Add mediawiki/mediawiki-phan-config

Replace phan-taint-check-plugin by phan, it is now included

Change-Id: I0e682a83afd30faa8967e3c586431be4ae9a29b3
This commit is contained in:
Umherirrender 2020-06-10 22:20:05 +02:00
parent edba40b1b6
commit 48e860916a
6 changed files with 52 additions and 6 deletions

19
.phan/config.php Normal file
View file

@ -0,0 +1,19 @@
<?php
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
$cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[
'../../extensions/VisualEditor',
]
);
$cfg['exclude_analysis_directory_list'] = array_merge(
$cfg['exclude_analysis_directory_list'],
[
'../../extensions/VisualEditor',
]
);
return $cfg;

View file

@ -1,6 +1,7 @@
{ {
"require-dev": { "require-dev": {
"mediawiki/mediawiki-codesniffer": "31.0.0", "mediawiki/mediawiki-codesniffer": "31.0.0",
"mediawiki/mediawiki-phan-config": "0.10.2",
"mediawiki/minus-x": "1.1.0", "mediawiki/minus-x": "1.1.0",
"php-parallel-lint/php-console-highlighter": "0.5.0", "php-parallel-lint/php-console-highlighter": "0.5.0",
"php-parallel-lint/php-parallel-lint": "1.2.0" "php-parallel-lint/php-parallel-lint": "1.2.0"
@ -15,8 +16,5 @@
"minus-x fix .", "minus-x fix .",
"phpcbf" "phpcbf"
] ]
},
"extra": {
"phan-taint-check-plugin": "2.0.1"
} }
} }

View file

@ -46,6 +46,7 @@ class CommentModifier {
*/ */
private static function isBlockElement( DOMNode $node ) : bool { private static function isBlockElement( DOMNode $node ) : bool {
return $node->nodeType === XML_ELEMENT_NODE && return $node->nodeType === XML_ELEMENT_NODE &&
// @phan-suppress-next-line PhanUndeclaredProperty
in_array( strtolower( $node->tagName ), self::$blockElementTypes ); in_array( strtolower( $node->tagName ), self::$blockElementTypes );
} }
@ -131,6 +132,7 @@ class CommentModifier {
// parent is a list item or paragraph (hopefully) // parent is a list item or paragraph (hopefully)
// target is an inline node within it // target is an inline node within it
$item = null;
if ( $curLevel < $desiredLevel ) { if ( $curLevel < $desiredLevel ) {
// Insert more lists after the target to increase nesting. // Insert more lists after the target to increase nesting.
@ -206,6 +208,10 @@ class CommentModifier {
$parent->insertBefore( $item, $target->nextSibling ); $parent->insertBefore( $item, $target->nextSibling );
} }
if ( $item === null ) {
throw new \LogicException( __METHOD__ . ' no item found' );
}
return $item; return $item;
} }
@ -272,7 +278,7 @@ class CommentModifier {
* @return DOMElement * @return DOMElement
*/ */
public static function addSiblingListItem( DOMElement $previousItem ) : DOMElement { public static function addSiblingListItem( DOMElement $previousItem ) : DOMElement {
$listItem = $previousItem->ownerDocument->createElement( $previousItem->tagName->toLowerCase() ); $listItem = $previousItem->ownerDocument->createElement( strtolower( $previousItem->tagName ) );
self::whitespaceParsoidHack( $listItem ); self::whitespaceParsoidHack( $listItem );
$previousItem->parentNode->insertBefore( $listItem, $previousItem->nextSibling ); $previousItem->parentNode->insertBefore( $listItem, $previousItem->nextSibling );
return $listItem; return $listItem;

View file

@ -27,6 +27,19 @@ use Title;
class CommentParser { class CommentParser {
private const SIGNATURE_SCAN_LIMIT = 100; private const SIGNATURE_SCAN_LIMIT = 100;
/** @var Language */
private $language;
/** @var Config */
private $config;
private $dateFormat;
private $digits;
/** @var string[] */
private $contLangMessages;
private $localTimezone;
private $timezones;
/** /**
* @param Language $language Content language * @param Language $language Content language
* @param Config $config * @param Config $config
@ -292,7 +305,7 @@ class CommentParser {
return preg_replace_callback( return preg_replace_callback(
'/[' . $digits . ']/', '/[' . $digits . ']/',
function ( array $m ) use ( $digits ) { function ( array $m ) use ( $digits ) {
return strpos( $digits, $m[0] ); return (string)strpos( $digits, $m[0] );
}, },
$text $text
); );
@ -440,6 +453,7 @@ class CommentParser {
$date->setTimezone( new DateTimeZone( 'UTC' ) ); $date->setTimezone( new DateTimeZone( 'UTC' ) );
$date = DateTimeImmutable::createFromMutable( $date ); $date = DateTimeImmutable::createFromMutable( $date );
if ( isset( $discussionToolsWarning ) ) { if ( isset( $discussionToolsWarning ) ) {
// @phan-suppress-next-line PhanUndeclaredProperty
$date->discussionToolsWarning = $discussionToolsWarning; $date->discussionToolsWarning = $discussionToolsWarning;
} }
@ -554,6 +568,7 @@ class CommentParser {
// text formatting) can just wrap it in a <span> to fix that. // text formatting) can just wrap it in a <span> to fix that.
// "Ten Pound Hammer • (What did I screw up now?)" // "Ten Pound Hammer • (What did I screw up now?)"
// "« Saper // dyskusja »" // "« Saper // dyskusja »"
// @phan-suppress-next-line PhanUndeclaredMethod
$links = $node->getElementsByTagName( 'a' ); $links = $node->getElementsByTagName( 'a' );
} }
if ( !count( $links ) ) { if ( !count( $links ) ) {
@ -563,6 +578,7 @@ class CommentParser {
// Find the earliest link that links to the user's user page // Find the earliest link that links to the user's user page
foreach ( $links as $link ) { foreach ( $links as $link ) {
$username = null; $username = null;
// @phan-suppress-next-line PhanUndeclaredMethod
$title = $this->getTitleFromUrl( $link->getAttribute( 'href' ) ); $title = $this->getTitleFromUrl( $link->getAttribute( 'href' ) );
if ( !$title ) { if ( !$title ) {
continue; continue;
@ -771,6 +787,7 @@ class CommentParser {
CommentUtils::childIndexOf( $lastSigNode ) + 1; CommentUtils::childIndexOf( $lastSigNode ) + 1;
$range = new ImmutableRange( $range = new ImmutableRange(
$startNode->parentNode, $startNode->parentNode,
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
CommentUtils::childIndexOf( $startNode ), CommentUtils::childIndexOf( $startNode ),
$lastSigNode === $node ? $node : $lastSigNode->parentNode, $lastSigNode === $node ? $node : $lastSigNode->parentNode,
$offset $offset
@ -782,6 +799,7 @@ class CommentParser {
$offset $offset
); );
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
$startLevel = $this->getIndentLevel( $startNode, $rootNode ) + 1; $startLevel = $this->getIndentLevel( $startNode, $rootNode ) + 1;
$endLevel = $this->getIndentLevel( $node, $rootNode ) + 1; $endLevel = $this->getIndentLevel( $node, $rootNode ) + 1;
if ( $startLevel !== $endLevel ) { if ( $startLevel !== $endLevel ) {
@ -1008,7 +1026,7 @@ class CommentParser {
$dataMw = json_decode( $node->getAttribute( 'data-mw' ), true ); $dataMw = json_decode( $node->getAttribute( 'data-mw' ), true );
// Only return a page name if this is a simple single-template transclusion. // Only return a page name if this is a simple single-template transclusion.
if ( if ( $dataMw &&
$dataMw['parts'] && $dataMw['parts'] &&
count( $dataMw['parts'] ) === 1 && count( $dataMw['parts'] ) === 1 &&
$dataMw['parts'][0]['template'] && $dataMw['parts'][0]['template'] &&

View file

@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools;
use DOMElement; use DOMElement;
use DOMNode; use DOMNode;
use DOMXPath; use DOMXPath;
use stdClass;
class CommentUtils { class CommentUtils {
private function __construct() { private function __construct() {
@ -69,6 +70,7 @@ class CommentUtils {
* *
* @param DOMNode $node * @param DOMNode $node
* @return DOMElement|null Translcusion node, null if not found * @return DOMElement|null Translcusion node, null if not found
* @suppress PhanUndeclaredMethod
*/ */
public static function getTranscludedFromElement( DOMNode $node ) : ?DOMElement { public static function getTranscludedFromElement( DOMNode $node ) : ?DOMElement {
while ( $node ) { while ( $node ) {

View file

@ -3,6 +3,8 @@
namespace MediaWiki\Extension\DiscussionTools; namespace MediaWiki\Extension\DiscussionTools;
use DOMNode; use DOMNode;
use Error;
use Exception;
/** /**
* ImmutableRange has a similar API to the DOM Range class. * ImmutableRange has a similar API to the DOM Range class.
@ -39,6 +41,7 @@ class ImmutableRange {
} while ( ( $b = $b->parentNode ) ); } while ( ( $b = $b->parentNode ) );
$node = null; $node = null;
// @phan-suppress-next-line PhanRedundantConditionInLoop
while ( $ancestorsA && $ancestorsB && end( $ancestorsA ) === end( $ancestorsB ) ) { while ( $ancestorsA && $ancestorsB && end( $ancestorsA ) === end( $ancestorsB ) ) {
$node = end( $ancestorsA ); $node = end( $ancestorsA );
array_pop( $ancestorsA ); array_pop( $ancestorsA );