Various code quality tweaks

(suggested by PhpStorm)

composer.json:
* Document required PHP extensions

Parser.js:
* Remove incorrect param documentation
* Fix some typos in comments (missing parentheses)

CommentParser.php:
* Fix some typos in comments (missing parentheses)

ImmutableRange.php:
* Remove unused property
* Add a `throw` to indicate that code path is unreachable

SubscribedNewCommentPresentationModel.php:
* Add missing `return false`

CommentParserTest.php:
* Remove unnecessary pass-by-reference

CommentModifierTest.php:
* Remove unused variable

CommentParserTest.php:
* Don't construct Element objects directly. PHP's DOMElement allows
  it, but Parsoid/Dodo's doesn't, and we use the latter for static
  analysis. This generates all kinds of confusing warnings.

Change-Id: Ia9598ebea0e99830dd485296e94a9d96acc4b258
This commit is contained in:
Bartosz Dziewoński 2022-02-19 00:36:20 +01:00
parent 77034e77c2
commit ae9f26a9e5
7 changed files with 38 additions and 24 deletions

View file

@ -23,5 +23,9 @@
],
"phan": "phan -d . --long-progress-bar",
"phpcs": "phpcs -sp --cache"
},
"require": {
"ext-json": "*",
"ext-dom": "*"
}
}

View file

@ -1031,15 +1031,15 @@ class CommentParser {
* CommentItem( { level: 1, range: (p: B), replies: [
* CommentItem( { level: 2, range: (li: C, li: C), replies: [
* CommentItem( { level: 3, range: (li: D), replies: [
* CommentItem( { level: 4, range: (li: E), replies: [] },
* CommentItem( { level: 4, range: (li: F), replies: [] },
* ] },
* ] },
* CommentItem( { level: 2, range: (li: G), replies: [] },
* ] },
* CommentItem( { level: 4, range: (li: E), replies: [] } ),
* CommentItem( { level: 4, range: (li: F), replies: [] } ),
* ] } ),
* ] } ),
* CommentItem( { level: 2, range: (li: G), replies: [] } ),
* ] } ),
* CommentItem( { level: 1, range: (p: H), replies: [
* CommentItem( { level: 2, range: (li: I), replies: [] },
* ] },
* CommentItem( { level: 2, range: (li: I), replies: [] } ),
* ] } ),
* ] } )
* ]
*

View file

@ -20,7 +20,6 @@ use Wikimedia\Parsoid\DOM\Text;
* setStart and setEnd are still available but return a cloned range.
*/
class ImmutableRange {
private $mCollapsed;
private $mCommonAncestorContainer;
private $mEndContainer;
private $mEndOffset;
@ -544,6 +543,9 @@ class ImmutableRange {
case 'after':
return 1;
default:
throw new Error();
}
}
}

View file

@ -118,6 +118,7 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel {
if ( !$this->isBundled() ) {
return new RawMessage( '$1', [ Message::plaintextParam( $this->getContentSnippet() ) ] );
}
return false;
}
/**

View file

@ -720,7 +720,6 @@ Parser.prototype.nextInterestingLeafNode = function ( node ) {
* CommentItem( { level: 2, range: (li: I) } )
* ]
*
* @param {HTMLElement} rootNode
* @return {ThreadItem[]} Thread items
*/
Parser.prototype.getThreadItems = function () {
@ -976,15 +975,15 @@ Parser.prototype.buildThreadItems = function () {
* CommentItem( { level: 1, range: (p: B), replies: [
* CommentItem( { level: 2, range: (li: C, li: C), replies: [
* CommentItem( { level: 3, range: (li: D), replies: [
* CommentItem( { level: 4, range: (li: E), replies: [] },
* CommentItem( { level: 4, range: (li: F), replies: [] },
* ] },
* ] },
* CommentItem( { level: 2, range: (li: G), replies: [] },
* ] },
* CommentItem( { level: 4, range: (li: E), replies: [] } ),
* CommentItem( { level: 4, range: (li: F), replies: [] } ),
* ] } ),
* ] } ),
* CommentItem( { level: 2, range: (li: G), replies: [] } ),
* ] } ),
* CommentItem( { level: 1, range: (p: H), replies: [
* CommentItem( { level: 2, range: (li: I), replies: [] },
* ] },
* CommentItem( { level: 2, range: (li: I), replies: [] } ),
* ] } ),
* ] } )
* ]
*

View file

@ -39,11 +39,9 @@ class CommentModifierTest extends IntegrationTestCase {
$parser = self::createParser( $container, $title, $data );
$comments = $parser->getCommentItems();
$nodes = [];
foreach ( $comments as $comment ) {
$node = CommentModifier::addListItem( $comment, $replyIndentation );
$node->textContent = 'Reply to ' . $comment->getId();
$nodes[] = $node;
}
$expectedDoc = self::createDocument( $expected );

View file

@ -15,6 +15,7 @@ use Title;
use Wikimedia\Parsoid\DOM\Element;
use Wikimedia\Parsoid\DOM\Node;
use Wikimedia\Parsoid\Utils\DOMCompat;
use Wikimedia\Parsoid\Utils\DOMUtils;
use Wikimedia\TestingAccessWrapper;
/**
@ -55,7 +56,7 @@ class CommentParserTest extends IntegrationTestCase {
return implode( '/', $path );
}
private static function serializeComments( ThreadItem &$threadItem, Element $root ): stdClass {
private static function serializeComments( ThreadItem $threadItem, Element $root ): stdClass {
$serialized = new stdClass();
if ( $threadItem instanceof HeadingItem ) {
@ -113,7 +114,10 @@ class CommentParserTest extends IntegrationTestCase {
string $format, string $expected, string $message
): void {
$parser = TestingAccessWrapper::newFromObject(
CommentParser::newFromGlobalState( new Element( 'div' ), Title::newFromText( 'Dummy' ) )
CommentParser::newFromGlobalState(
DOMCompat::getBody( DOMUtils::parseHTML( '' ) ),
Title::newFromText( 'Dummy' )
)
);
// HACK: Fix differences between JS & PHP regexes
@ -138,7 +142,10 @@ class CommentParserTest extends IntegrationTestCase {
string $format, array $data, string $expected, string $message
): void {
$parser = TestingAccessWrapper::newFromObject(
CommentParser::newFromGlobalState( new Element( 'div' ), Title::newFromText( 'Dummy' ) )
CommentParser::newFromGlobalState(
DOMCompat::getBody( DOMUtils::parseHTML( '' ) ),
Title::newFromText( 'Dummy' )
)
);
$expected = new DateTimeImmutable( $expected );
@ -160,7 +167,10 @@ class CommentParserTest extends IntegrationTestCase {
string $timezone, array $timezoneAbbrs, string $message
): void {
$parser = TestingAccessWrapper::newFromObject(
CommentParser::newFromGlobalState( new Element( 'div' ), Title::newFromText( 'Dummy' ) )
CommentParser::newFromGlobalState(
DOMCompat::getBody( DOMUtils::parseHTML( '' ) ),
Title::newFromText( 'Dummy' )
)
);
$regexp = $parser->getTimestampRegexp( 'en', $format, '\\d', $timezoneAbbrs );