Index: trunk/extensions/CodeReview/ui/WordCloud.php |
— | — | @@ -34,6 +34,15 @@ |
35 | 35 | */ |
36 | 36 | private $callback; |
37 | 37 | |
| 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 | + |
38 | 47 | /* |
39 | 48 | * Constructor |
40 | 49 | * |
— | — | @@ -119,27 +128,11 @@ |
120 | 129 | * @return Int |
121 | 130 | */ |
122 | 131 | 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 | + } |
143 | 136 | } |
144 | | - return $class; |
| 137 | + return 0; |
145 | 138 | } |
146 | 139 | } |