r76083 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76082‎ | r76083 | r76084 >
Date:12:33, 5 November 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Followup r76001, use less elseif
Modified paths:
  • /trunk/extensions/CodeReview/ui/WordCloud.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/WordCloud.php
@@ -34,6 +34,15 @@
3535 */
3636 private $callback;
3737
 38+ /**
 39+ * Mapping of percentage limits to their CSS classes
 40+ */
 41+ private $classPercentages = array(
 42+ 1 => 99, 2 => 70, 3 => 60,
 43+ 4 => 50, 5 => 40, 6 => 30,
 44+ 7 => 20, 8 => 10, 9 => 5
 45+ );
 46+
3847 /*
3948 * Constructor
4049 *
@@ -119,27 +128,11 @@
120129 * @return Int
121130 */
122131 private function getClassFromPercent( $percent ) {
123 - if ( $percent >= 99 ) {
124 - $class = 1;
125 - } elseif( $percent >= 70 ) {
126 - $class = 2;
127 - } elseif( $percent >= 60 ) {
128 - $class = 3;
129 - } elseif( $percent >= 50 ) {
130 - $class = 4;
131 - } elseif( $percent >= 40 ) {
132 - $class = 5;
133 - } elseif( $percent >= 30 ) {
134 - $class = 6;
135 - } elseif( $percent >= 20 ) {
136 - $class = 7;
137 - } elseif( $percent >= 10 ) {
138 - $class = 8;
139 - } elseif( $percent >= 5 ) {
140 - $class = 9;
141 - } else {
142 - $class = 0;
 132+ foreach( $this->classPercentages as $class => $limit ) {
 133+ if( $percent >= $limit ) {
 134+ return $class;
 135+ }
143136 }
144 - return $class;
 137+ return 0;
145138 }
146139 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76001Add tag cloud thingie to the tag listing. Ranks by number of uses of each key...demon13:33, 4 November 2010

Comments

#Comment by Hashar (talk | contribs)   17:33, 5 November 2010

That is another fun way to handle this :)

Status & tagging log