Skip to content

Commit

Permalink
MDL-67035 tags: fix nested ternary operators to be php74 compliant
Browse files Browse the repository at this point in the history
Nesting ternary operators without explicit parentheses is deprecated:

    // Code like
    $a ? $b : $c ? $d : $e
    // should be replaced by (current interpretation)
    ($a ? $b : $c) ? $d : $e
    // or (likely intended interpretation)
    $a ? $b : ($c ? $d : $e)
  • Loading branch information
stronk7 committed Nov 16, 2019
1 parent d547735 commit 6783adc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function block_blog_tags_sort($a, $b) {
}

if (is_numeric($a->$tagsort)) {
return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
return (($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort)) ? 1 : -1;
} elseif (is_string($a->$tagsort)) {
return strcmp($a->$tagsort, $b->$tagsort); //TODO: this is not compatible with UTF-8!!
} else {
Expand Down
4 changes: 2 additions & 2 deletions tag/classes/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ public static function cloud_sort($a, $b) {
$tagsort = self::$cloudsortfield ?: 'name';

if (is_numeric($a->$tagsort)) {
return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
return (($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort)) ? 1 : -1;
} else if (is_string($a->$tagsort)) {
return strcmp($a->$tagsort, $b->$tagsort);
} else {
return 0;
}
}
}
}

0 comments on commit 6783adc

Please sign in to comment.