Skip to content

Commit

Permalink
Avoid using deprecated getCategories
Browse files Browse the repository at this point in the history
Follow-up: I8dc85e76bfbb9ed49a603d990c14b7ee798bd821
Follow-up: I7b8a86f6efbdd86c1f493db6741c37bfb325e9bb
Signed-off-by: xtex <[email protected]>
  • Loading branch information
xtexChooser committed Jul 12, 2024
1 parent dad7124 commit c16bb7e
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,16 @@ private static function executeTag( $input, array $args, Parser $parser, PPFrame

// we can remove the categories by save/restore
if ( $reset['categories'] ?? false ) {
$saveCategories = $parser->getOutput()->getCategories();
$parserOutput = $parser->getOutput();
if ( method_exists( $parserOutput, 'getCategoryNames' ) && method_exists( $parserOutput, 'getCategorySortKey' ) ) {
$saveCategories = array_combine(
$parserOutput->getCategoryNames(),
// @phan-suppress-next-line PhanUndeclaredMethod
array_map( fn ( $value ) => $parserOutput->getCategorySortKey( $value ), $parserOutput->getCategoryNames() )
);
} else {

Check warning

Code scanning / Phpmd (reported by Codacy)

Use return statements instead of else expression Warning

The method executeTag uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
$saveCategories = $parserOutput->getCategories();
}
}

// we can remove the images by save/restore
Expand Down Expand Up @@ -556,9 +565,18 @@ public static function endReset( $parser, $text ) {
if ( !self::$createdLinks['resetdone'] ) {
self::$createdLinks['resetdone'] = true;

foreach ( $parser->getOutput()->getCategories() as $key => $val ) {
if ( array_key_exists( $key, self::$fixedCategories ) ) {
self::$fixedCategories[$key] = $val;
if ( method_exists( $parser->getOutput(), 'getCategoryNames' ) && method_exists( $parser->getOutput(), 'getCategorySortKey' ) ) {
foreach ( $parser->getOutput()->getCategoryNames() as $key ) {
if ( array_key_exists( $key, self::$fixedCategories ) ) {
// @phan-suppress-next-line PhanUndeclaredMethod
self::$fixedCategories[$key] = $parser->getOutput()->getCategorySortKey( $key );
}
}
} else {

Check warning

Code scanning / Phpmd (reported by Codacy)

Use return statements instead of else expression Warning

The method endReset uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
foreach ( $parser->getOutput()->getCategories() as $key => $val ) {
if ( array_key_exists( $key, self::$fixedCategories ) ) {
self::$fixedCategories[$key] = $val;
}
}
}

Expand Down Expand Up @@ -618,7 +636,17 @@ public static function endEliminate( $parser, &$text ) {
}

if ( isset( self::$createdLinks ) && array_key_exists( 2, self::$createdLinks ) ) {
$parser->getOutput()->setCategories( array_diff_assoc( $parser->getOutput()->getCategories(), self::$createdLinks[2] ) );
$parserOutput = $parser->getOutput();
if ( method_exists( $parserOutput, 'getCategoryNames' ) && method_exists( $parserOutput, 'getCategorySortKey' ) ) {
$categories = array_combine(
$parserOutput->getCategoryNames(),
// @phan-suppress-next-line PhanUndeclaredMethod
array_map( fn ( $value ) => $parserOutput->getCategorySortKey( $value ), $parserOutput->getCategoryNames() )
);
$parser->getOutput()->setCategories( array_diff_assoc( $categories, self::$createdLinks[2] ) );
} else {

Check warning

Code scanning / Phpmd (reported by Codacy)

Use return statements instead of else expression Warning

The method endEliminate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
$parser->getOutput()->setCategories( array_diff_assoc( $parserOutput->getCategories(), self::$createdLinks[2] ) );
}
}

if ( isset( self::$createdLinks ) && array_key_exists( 3, self::$createdLinks ) ) {
Expand Down

0 comments on commit c16bb7e

Please sign in to comment.