Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcs: enable: Generic.Files.LineLength.TooLong #150

Merged
merged 33 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fe7610d
phpcs: enable: `Generic.Files.LineLength.TooLong`
Universal-Omega Mar 22, 2022
fa78fe9
Update createTemplate.php
Universal-Omega Mar 22, 2022
46d1114
Update Parse.php
Universal-Omega Mar 22, 2022
a7f8ae9
Update Parse.php
Universal-Omega Mar 22, 2022
e6efee7
Update Parse.php
Universal-Omega Mar 22, 2022
c835088
CI: lint code to MediaWiki standards
Mar 22, 2022
8c8f04e
Update Parse.php
Universal-Omega Mar 22, 2022
ca4ba68
Merge branch 'master' into Universal-Omega-patch-2
Universal-Omega Jan 14, 2023
d900250
Update createTemplate.php
Universal-Omega Jan 14, 2023
a6f0fa8
name
Universal-Omega Feb 8, 2025
60695b4
Merge branch 'master' into Universal-Omega-patch-2
Universal-Omega Feb 8, 2025
4bc1847
Split line
Universal-Omega Feb 8, 2025
e628e44
Split line
Universal-Omega Feb 8, 2025
bb3b7ba
Split line
Universal-Omega Feb 8, 2025
b653893
Split line
Universal-Omega Feb 8, 2025
8f84d05
Split line
Universal-Omega Feb 8, 2025
3ddbc20
Split lines
Universal-Omega Feb 8, 2025
9bc2553
Split lines
Universal-Omega Feb 8, 2025
25e9a1a
CI: lint code to MediaWiki standards
Feb 8, 2025
e31204f
Split lines
Universal-Omega Feb 8, 2025
e0eef4b
Split lines
Universal-Omega Feb 8, 2025
bce1004
Split lines
Universal-Omega Feb 8, 2025
4ce2927
Split lines
Universal-Omega Feb 8, 2025
1bf160f
Split line
Universal-Omega Feb 8, 2025
a699909
Split lines
Universal-Omega Feb 8, 2025
69ab30a
Split lines
Universal-Omega Feb 8, 2025
a558bbc
Split lines
Universal-Omega Feb 8, 2025
8de32a0
Split lines
Universal-Omega Feb 8, 2025
e64fa43
CI: lint code to MediaWiki standards
Feb 8, 2025
af337bf
Split line
Universal-Omega Feb 8, 2025
c7a6af3
Split lines
Universal-Omega Feb 8, 2025
106e29d
Split lines
Universal-Omega Feb 8, 2025
c8822d1
Split lines
Universal-Omega Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<ruleset>
<file>.</file>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
</rule>
Expand Down
69 changes: 47 additions & 22 deletions includes/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,21 @@ public static function newFromRow(
}

// Chop off title if longer than the 'titlemaxlen' parameter.
if ( $parameters->getParameter( 'titlemaxlen' ) !== null && strlen( $titleText ) > $parameters->getParameter( 'titlemaxlen' ) ) {
if (
$parameters->getParameter( 'titlemaxlen' ) !== null &&
strlen( $titleText ) > $parameters->getParameter( 'titlemaxlen' )
) {
$titleText = substr( $titleText, 0, $parameters->getParameter( 'titlemaxlen' ) ) . '...';
}

if ( $parameters->getParameter( 'showcurid' ) === true && isset( $row->page_id ) ) {
$articleLink = '[' . $title->getFullURL( [ 'curid' => $row->page_id ] ) . ' ' . htmlspecialchars( $titleText ) . ']';
$articleLink = '[' . $title->getFullURL( [ 'curid' => $row->page_id ] ) . ' ' .
htmlspecialchars( $titleText ) . ']';
} else {
$articleLink = '[[' . ( $parameters->getParameter( 'escapelinks' ) && ( $pageNamespace == NS_CATEGORY || $pageNamespace == NS_FILE ) ? ':' : '' ) . $title->getFullText() . '|' . htmlspecialchars( $titleText ) . ']]';
$articleLink = '[[' . (
$parameters->getParameter( 'escapelinks' ) &&
( $pageNamespace == NS_CATEGORY || $pageNamespace == NS_FILE ) ? ':' : ''
) . $title->getFullText() . '|' . htmlspecialchars( $titleText ) . ']]';
}

$article->mLink = $articleLink;
Expand Down Expand Up @@ -266,8 +273,14 @@ public static function newFromRow(

// STORE initially selected PAGE
if (
( is_array( $parameters->getParameter( 'linksto' ) ) && count( $parameters->getParameter( 'linksto' ) ) ) ||
( is_array( $parameters->getParameter( 'linksfrom' ) ) && count( $parameters->getParameter( 'linksfrom' ) ) )
(
is_array( $parameters->getParameter( 'linksto' ) ) &&
count( $parameters->getParameter( 'linksto' ) )
) ||
(
is_array( $parameters->getParameter( 'linksfrom' ) ) &&
count( $parameters->getParameter( 'linksfrom' ) )
)
) {
if ( !isset( $row->sel_title ) ) {
$article->mSelTitle = 'unknown page';
Expand All @@ -279,17 +292,21 @@ public static function newFromRow(
}

// STORE selected image
if ( is_array( $parameters->getParameter( 'imageused' ) ) && count( $parameters->getParameter( 'imageused' ) ) > 0 ) {
if ( !isset( $row->image_sel_title ) ) {
$article->mImageSelTitle = 'unknown image';
} else {
$article->mImageSelTitle = $row->image_sel_title;
}
if (
is_array( $parameters->getParameter( 'imageused' ) ) &&
count( $parameters->getParameter( 'imageused' ) ) > 0
) {
$article->mImageSelTitle = $row->image_sel_title ?? 'unknown image';
}

if ( $parameters->getParameter( 'goal' ) != 'categories' ) {
// REVISION SPECIFIED
if ( $parameters->getParameter( 'lastrevisionbefore' ) || $parameters->getParameter( 'allrevisionsbefore' ) || $parameters->getParameter( 'firstrevisionsince' ) || $parameters->getParameter( 'allrevisionssince' ) ) {
if (
$parameters->getParameter( 'lastrevisionbefore' ) ||
$parameters->getParameter( 'allrevisionsbefore' ) ||
$parameters->getParameter( 'firstrevisionsince' ) ||
$parameters->getParameter( 'allrevisionssince' )
) {
$article->mRevision = $row->rev_id;
$article->mUser = $revActorName;
$article->mDate = $row->rev_timestamp;
Expand All @@ -311,13 +328,15 @@ public static function newFromRow(
// Time zone adjustment
if ( $article->mDate ) {
$lang = RequestContext::getMain()->getLanguage();

$article->mDate = $lang->userAdjust( $article->mDate );
}

if ( $article->mDate && $parameters->getParameter( 'userdateformat' ) ) {
// Apply the userdateformat
$article->myDate = gmdate( $parameters->getParameter( 'userdateformat' ), (int)wfTimestamp( TS_UNIX, $article->mDate ) );
$article->myDate = gmdate(
$parameters->getParameter( 'userdateformat' ),
(int)wfTimestamp( TS_UNIX, $article->mDate )
);
}

// CONTRIBUTION, CONTRIBUTOR
Expand All @@ -332,7 +351,11 @@ public static function newFromRow(
// USER/AUTHOR(S)
// because we are going to do a recursive parse at the end of the output phase
// we have to generate wiki syntax for linking to a user´s homepage
if ( $parameters->getParameter( 'adduser' ) || $parameters->getParameter( 'addauthor' ) || $parameters->getParameter( 'addlasteditor' ) ) {
if (
$parameters->getParameter( 'adduser' ) ||
$parameters->getParameter( 'addauthor' ) ||
$parameters->getParameter( 'addlasteditor' )
) {
$article->mUserLink = '[[User:' . $revActorName . '|' . $revActorName . ']]';
$article->mUser = $revActorName;
}
Expand All @@ -341,7 +364,8 @@ public static function newFromRow(
if ( $parameters->getParameter( 'addcategories' ) && ( $row->cats ) ) {
$artCatNames = explode( ' | ', $row->cats );
foreach ( $artCatNames as $artCatName ) {
$article->mCategoryLinks[] = '[[:Category:' . $artCatName . '|' . str_replace( '_', ' ', $artCatName ) . ']]';
$article->mCategoryLinks[] = '[[:Category:' . $artCatName . '|' .
str_replace( '_', ' ', $artCatName ) . ']]';
$article->mCategoryTexts[] = str_replace( '_', ' ', $artCatName );
}
}
Expand All @@ -351,19 +375,20 @@ public static function newFromRow(
switch ( $parameters->getParameter( 'ordermethod' )[0] ) {
case 'category':
// Count one more page in this heading
self::$headings[$row->cl_to] = ( isset( self::$headings[$row->cl_to] ) ? self::$headings[$row->cl_to] + 1 : 1 );
self::$headings[$row->cl_to] = ( self::$headings[$row->cl_to] ?? 0 ) + 1;
if ( $row->cl_to == '' ) {
// uncategorized page (used if ordermethod=category,...)
$article->mParentHLink = '[[:Special:Uncategorizedpages|' . wfMessage( 'uncategorizedpages' ) . ']]';
// Uncategorized page (used if ordermethod=category,...)
$article->mParentHLink = '[[:Special:Uncategorizedpages|' .
wfMessage( 'uncategorizedpages' ) . ']]';
} else {
$article->mParentHLink = '[[:Category:' . $row->cl_to . '|' . str_replace( '_', ' ', $row->cl_to ) . ']]';
$article->mParentHLink = '[[:Category:' . $row->cl_to . '|' .
str_replace( '_', ' ', $row->cl_to ) . ']]';
}

break;
case 'user':
if ( $revActorName && $revActorName !== ActorStore::UNKNOWN_USER_NAME ) {
self::$headings[$revActorName] = ( isset( self::$headings[$revActorName] ) ? self::$headings[$revActorName] + 1 : 1 );

self::$headings[$revActorName] = ( self::$headings[$revActorName] ?? 0 ) + 1;
$article->mParentHLink = '[[User:' . $revActorName . '|' . $revActorName . ']]';
}

Expand Down
6 changes: 5 additions & 1 deletion includes/Heading/DefinitionHeading.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public function formatItem( $headingStart, $headingCount, $headingLink, $article
}

$item .= $this->headListEnd;
$item .= $this->getItemStart() . $lister->formatList( $articles, $headingStart, $headingCount ) . $this->getItemEnd();
$item .= $this->getItemStart() . $lister->formatList(
$articles,
$headingStart,
$headingCount
) . $this->getItemEnd();

return $item;
}
Expand Down
49 changes: 41 additions & 8 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@
public static function onParserFirstCallInit( Parser $parser ) {
self::init();

// DPL offers the same functionality as Intersection. So we register the <DynamicPageList> tag in case LabeledSection Extension is not installed so that the section markers are removed.
// DPL offers the same functionality as Intersection.
// So we register the <DynamicPageList> tag in case
// LabeledSection Extension is not installed so that the
// section markers are removed.
if ( Config::getSetting( 'handleSectionTag' ) ) {
$parser->setHook( 'section', [ __CLASS__, 'dplTag' ] );
}
Expand Down Expand Up @@ -223,7 +226,10 @@
if ( $reset['categories'] ?? false ) {
$saveCategories = array_combine(
$parserOutput->getCategoryNames(),
array_map( static fn ( $value ) => $parserOutput->getCategorySortKey( $value ), $parserOutput->getCategoryNames() )
array_map( static fn ( $value ) =>
$parserOutput->getCategorySortKey( $value ),
$parserOutput->getCategoryNames()
)
);
}

Expand Down Expand Up @@ -290,7 +296,10 @@

/**
* The #dplnum parser tag entry point.
* From the old documentation: "Tries to guess a number that is buried in the text. Uses a set of heuristic rules which may work or not. The idea is to extract the number so that it can be used as a sorting value in the column of a DPL table output."
*
* From the old documentation: "Tries to guess a number that is buried in the text.
* Uses a set of heuristic rules which may work or not. The idea is to extract the
* number so that it can be used as a sorting value in the column of a DPL table output."
*
* @param Parser $parser
* @param string $text
Expand Down Expand Up @@ -401,9 +410,20 @@
* @param bool $trim
* @return string
*/
public static function dplChapterParserFunction( &$parser, $text = '', $heading = ' ', $maxLength = -1, $page = '?page?', $link = 'default', $trim = false ) {
public static function dplChapterParserFunction(
&$parser,
$text = '',
$heading = ' ',
$maxLength = -1,
$page = '?page?',
$link = 'default',
$trim = false

Check warning

Code scanning / Phpmd (reported by Codacy)

You can fix this problem by extracting the logic in the boolean flag into its own class or method Warning

The method dplChapterParserFunction has a boolean flag argument $trim, which is a certain sign of a Single Responsibility Principle violation.
) {
$parser->addTrackingCategory( 'dplchapter-parserfunc-tracking-category' );
$output = LST::extractHeadingFromText( $parser, $page, '?title?', $text, $heading, '', $sectionHeading, true, $maxLength, $link, $trim );
$output = LST::extractHeadingFromText(

Check warning

Code scanning / Phpmd (reported by Codacy)

Static access leads to hard to test code Warning

Avoid using static access to class 'MediaWiki\Extension\DynamicPageList3\LST' in method 'dplChapterParserFunction'.
$parser, $page, '?title?', $text, $heading, '',
$sectionHeading, true, $maxLength, $link, $trim

Check warning

Code scanning / Phpmd (reported by Codacy)

Detects when a variable is used that has not been defined before Warning

Avoid using undefined variables such as '$sectionHeading' which will lead to PHP notices.

Check notice

Code scanning / Phpmd (reported by Codacy)

Prohibit the definition or assignment of unused local variables Note

Avoid unused local variables such as '$sectionHeading'.
);
return $output[0];
}

Expand All @@ -416,7 +436,14 @@
* @param string $matrix
* @return string
*/
public static function dplMatrixParserFunction( &$parser, $name = '', $yes = '', $no = '', $flip = '', $matrix = '' ) {
public static function dplMatrixParserFunction(

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports methods with high cyclomatic complexity Note

The method dplMatrixParserFunction() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports methods with a large number of possible paths Note

The method dplMatrixParserFunction() has an NPath complexity of 13056. The configured NPath complexity threshold is 200.

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports excessively long methods. Note

The method dplMatrixParserFunction() has 114 lines of code. Current threshold is set to 100. Avoid really long methods.
&$parser,
$name = '',
$yes = '',
$no = '',

Check warning

Code scanning / Phpmd (reported by Codacy)

Detects when a field, local, or parameter has a very short name. Warning

Avoid variables with short names like $no. Configured minimum length is 3.
$flip = '',
$matrix = ''
) {
$parser->addTrackingCategory( 'dplmatrix-parserfunc-tracking-category' );
$lines = explode( "\n", $matrix );
$m = [];
Expand Down Expand Up @@ -601,7 +628,10 @@
continue;
}

$parser->getOutput()->mLinks[$nsp] = array_diff_assoc( $parserLinks[$nsp], self::$createdLinks[0][$nsp] );
$parser->getOutput()->mLinks[$nsp] = array_diff_assoc(
$parserLinks[$nsp],
self::$createdLinks[0][$nsp]
);

if ( count( $parserLinks[$nsp] ) == 0 ) {
unset( $parser->getOutput()->mLinks[$nsp] );
Expand All @@ -616,7 +646,10 @@
continue;
}

$parser->getOutput()->mTemplates[$nsp] = array_diff_assoc( $parserTemplates[$nsp], self::$createdLinks[1][$nsp] );
$parser->getOutput()->mTemplates[$nsp] = array_diff_assoc(
$parserTemplates[$nsp],
self::$createdLinks[1][$nsp]
);

if ( count( $parserTemplates[$nsp] ) == 0 ) {
unset( $parser->getOutput()->mTemplates[$nsp] );
Expand Down
Loading
Loading