@@ -32,34 +32,34 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | use Traits_Optionable; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var integer |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var integer |
|
| 37 | + */ |
|
| 38 | 38 | private $amountCols = 0; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var integer |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var integer |
|
| 42 | + */ |
|
| 43 | 43 | private $maxTotal = 100; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var Column[] |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var Column[] |
|
| 47 | + */ |
|
| 48 | 48 | private $columns = array(); |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var integer |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var integer |
|
| 52 | + */ |
|
| 53 | 53 | private $missing = 0; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var boolean |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var boolean |
|
| 57 | + */ |
|
| 58 | 58 | private $calculated = false; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string[]number $columnValues |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @param string[]number $columnValues |
|
| 62 | + */ |
|
| 63 | 63 | private function __construct(array $columnValues) |
| 64 | 64 | { |
| 65 | 65 | foreach($columnValues as $name => $value) |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | return $this; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Sets the minimum width to enforce for columns, |
|
| 95 | - * when there already are other columns that take |
|
| 96 | - * up all the available width. |
|
| 97 | - * |
|
| 98 | - * @param float $width |
|
| 99 | - * @return Calculator |
|
| 100 | - */ |
|
| 93 | + /** |
|
| 94 | + * Sets the minimum width to enforce for columns, |
|
| 95 | + * when there already are other columns that take |
|
| 96 | + * up all the available width. |
|
| 97 | + * |
|
| 98 | + * @param float $width |
|
| 99 | + * @return Calculator |
|
| 100 | + */ |
|
| 101 | 101 | public function setMinWidth(float $width) : Calculator |
| 102 | 102 | { |
| 103 | 103 | $max = $this->getMaxMinWidth(); |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | $this->columns[] = $col; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Retrieves the minimum width for columns, in percent. |
|
| 142 | - * @return float |
|
| 143 | - */ |
|
| 140 | + /** |
|
| 141 | + * Retrieves the minimum width for columns, in percent. |
|
| 142 | + * @return float |
|
| 143 | + */ |
|
| 144 | 144 | public function getMinWidth() : float |
| 145 | 145 | { |
| 146 | 146 | return floatval($this->getOption('minPerCol')); |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | $this->calculated = true; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Retrieves the updated list of column values, |
|
| 170 | - * retaining the original keys. |
|
| 171 | - * |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 168 | + /** |
|
| 169 | + * Retrieves the updated list of column values, |
|
| 170 | + * retaining the original keys. |
|
| 171 | + * |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | 174 | public function getValues() : array |
| 175 | 175 | { |
| 176 | 176 | $this->calculate(); |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | return $total; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Detects any leftover percentages that still need |
|
| 269 | - * to be filled, in case we are not at 100% yet. It |
|
| 270 | - * distributes the missing percentages evenly over the |
|
| 271 | - * available columns, from the last one upwards. |
|
| 272 | - */ |
|
| 267 | + /** |
|
| 268 | + * Detects any leftover percentages that still need |
|
| 269 | + * to be filled, in case we are not at 100% yet. It |
|
| 270 | + * distributes the missing percentages evenly over the |
|
| 271 | + * available columns, from the last one upwards. |
|
| 272 | + */ |
|
| 273 | 273 | private function fillLeftover() : void |
| 274 | 274 | { |
| 275 | 275 | $this->adjustLeftoverValues(); |
@@ -299,11 +299,11 @@ discard block |
||
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Adjusts the individual column values to match |
|
| 304 | - * the expected output format, for example ensuring |
|
| 305 | - * integer values if we are in integer mode. |
|
| 306 | - */ |
|
| 302 | + /** |
|
| 303 | + * Adjusts the individual column values to match |
|
| 304 | + * the expected output format, for example ensuring |
|
| 305 | + * integer values if we are in integer mode. |
|
| 306 | + */ |
|
| 307 | 307 | private function adjustLeftoverValues() : void |
| 308 | 308 | { |
| 309 | 309 | // convert all columns to integer values as required |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @see Mistralys\WidthsCalculator\Calculator |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -declare (strict_types=1); |
|
| 9 | +declare(strict_types=1); |
|
| 10 | 10 | |
| 11 | 11 | namespace Mistralys\WidthsCalculator; |
| 12 | 12 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | private function __construct(array $columnValues) |
| 64 | 64 | { |
| 65 | - foreach($columnValues as $name => $value) |
|
| 65 | + foreach ($columnValues as $name => $value) |
|
| 66 | 66 | { |
| 67 | 67 | $this->addColumn( |
| 68 | 68 | (string)$name, |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function setFloatValues(bool $enable=true) : Calculator |
|
| 87 | + public function setFloatValues(bool $enable = true) : Calculator |
|
| 88 | 88 | { |
| 89 | 89 | $this->setOption('integerValues', !$enable); |
| 90 | 90 | return $this; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $max = $this->getMaxMinWidth(); |
| 104 | 104 | |
| 105 | - if($width > $max) |
|
| 105 | + if ($width > $max) |
|
| 106 | 106 | { |
| 107 | 107 | throw new \Exception( |
| 108 | 108 | sprintf('Minimum width cannot be set above %s.', number_format($max, 4)), |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $value |
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | - if($col->isMissing()) |
|
| 130 | + if ($col->isMissing()) |
|
| 131 | 131 | { |
| 132 | 132 | $this->missing++; |
| 133 | 133 | } |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | private function calculate() : void |
| 150 | 150 | { |
| 151 | - if($this->calculated) |
|
| 151 | + if ($this->calculated) |
|
| 152 | 152 | { |
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if($this->calcTotal() > $this->maxTotal) |
|
| 156 | + if ($this->calcTotal() > $this->maxTotal) |
|
| 157 | 157 | { |
| 158 | 158 | $this->fixOverflow(); |
| 159 | 159 | } |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $result = array(); |
| 179 | 179 | |
| 180 | - foreach($this->columns as $col) |
|
| 180 | + foreach ($this->columns as $col) |
|
| 181 | 181 | { |
| 182 | 182 | $val = $col->getValue(); |
| 183 | 183 | |
| 184 | - if($this->getBoolOption('integerValues')) |
|
| 184 | + if ($this->getBoolOption('integerValues')) |
|
| 185 | 185 | { |
| 186 | 186 | $val = intval($val); |
| 187 | 187 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | $total = 0; |
| 198 | 198 | |
| 199 | - foreach($this->columns as $col) |
|
| 199 | + foreach ($this->columns as $col) |
|
| 200 | 200 | { |
| 201 | 201 | $total += $col->getValue(); |
| 202 | 202 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | { |
| 209 | 209 | $leftover = $this->maxTotal - $this->calcTotal(); |
| 210 | 210 | |
| 211 | - if($leftover >= 0) |
|
| 211 | + if ($leftover >= 0) |
|
| 212 | 212 | { |
| 213 | 213 | return; |
| 214 | 214 | } |
@@ -217,14 +217,14 @@ discard block |
||
| 217 | 217 | $baseTotal = $this->calcTotalNotMissing(); |
| 218 | 218 | $min = $this->getMinWidth(); |
| 219 | 219 | |
| 220 | - foreach($this->columns as $col) |
|
| 220 | + foreach ($this->columns as $col) |
|
| 221 | 221 | { |
| 222 | - if($col->isMissing()) |
|
| 222 | + if ($col->isMissing()) |
|
| 223 | 223 | { |
| 224 | 224 | continue; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if($leftover <= 0) |
|
| 227 | + if ($leftover <= 0) |
|
| 228 | 228 | { |
| 229 | 229 | break; |
| 230 | 230 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $amount = round($leftover * $percent / 100); |
| 234 | 234 | $val = $col->getValue() - $amount; |
| 235 | 235 | |
| 236 | - if($val < $min) |
|
| 236 | + if ($val < $min) |
|
| 237 | 237 | { |
| 238 | 238 | continue; |
| 239 | 239 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $col->setValue($val); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if($leftover > 0) |
|
| 246 | + if ($leftover > 0) |
|
| 247 | 247 | { |
| 248 | 248 | $this->removeSurplus(); |
| 249 | 249 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | $total = 0; |
| 255 | 255 | |
| 256 | - foreach($this->columns as $col) |
|
| 256 | + foreach ($this->columns as $col) |
|
| 257 | 257 | { |
| 258 | - if(!$col->isMissing()) |
|
| 258 | + if (!$col->isMissing()) |
|
| 259 | 259 | { |
| 260 | 260 | $total += $col->getValue(); |
| 261 | 261 | } |
@@ -277,14 +277,14 @@ discard block |
||
| 277 | 277 | $leftover = $this->maxTotal - $this->calcTotal(); |
| 278 | 278 | $perCol = $leftover / $this->amountCols; |
| 279 | 279 | |
| 280 | - if($this->getBoolOption('integerValues')) |
|
| 280 | + if ($this->getBoolOption('integerValues')) |
|
| 281 | 281 | { |
| 282 | 282 | $perCol = (int)ceil($perCol); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - for($i=($this->amountCols-1); $i >=0; $i--) |
|
| 285 | + for ($i = ($this->amountCols - 1); $i >= 0; $i--) |
|
| 286 | 286 | { |
| 287 | - if($leftover <= 0) |
|
| 287 | + if ($leftover <= 0) |
|
| 288 | 288 | { |
| 289 | 289 | break; |
| 290 | 290 | } |
@@ -307,9 +307,9 @@ discard block |
||
| 307 | 307 | private function adjustLeftoverValues() : void |
| 308 | 308 | { |
| 309 | 309 | // convert all columns to integer values as required |
| 310 | - if($this->getBoolOption('integerValues')) |
|
| 310 | + if ($this->getBoolOption('integerValues')) |
|
| 311 | 311 | { |
| 312 | - foreach($this->columns as $col) |
|
| 312 | + foreach ($this->columns as $col) |
|
| 313 | 313 | { |
| 314 | 314 | $val = intval(floor($col->getValue())); |
| 315 | 315 | $col->setValue(floatval($val)); |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | private function fillMissing() : void |
| 321 | 321 | { |
| 322 | - if($this->missing === 0) |
|
| 322 | + if ($this->missing === 0) |
|
| 323 | 323 | { |
| 324 | 324 | return; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | $toDistribute = $this->maxTotal - $this->calcTotal(); |
| 328 | 328 | |
| 329 | - if($toDistribute <= 0) |
|
| 329 | + if ($toDistribute <= 0) |
|
| 330 | 330 | { |
| 331 | 331 | $toDistribute = $this->getMinWidth() * $this->missing; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | $perMissingCol = $toDistribute / $this->missing; |
| 335 | 335 | |
| 336 | - foreach($this->columns as $col) |
|
| 336 | + foreach ($this->columns as $col) |
|
| 337 | 337 | { |
| 338 | - if($col->isMissing()) |
|
| 338 | + if ($col->isMissing()) |
|
| 339 | 339 | { |
| 340 | 340 | $col->setValue($perMissingCol); |
| 341 | 341 | } |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | // are not missing. |
| 352 | 352 | $maxTotal = $this->maxTotal / ($this->amountCols - $this->missing); |
| 353 | 353 | |
| 354 | - foreach($this->columns as $col) |
|
| 354 | + foreach ($this->columns as $col) |
|
| 355 | 355 | { |
| 356 | 356 | // no change for missing columns, they get filled later |
| 357 | - if($col->isMissing()) |
|
| 357 | + if ($col->isMissing()) |
|
| 358 | 358 | { |
| 359 | 359 | continue; |
| 360 | 360 | } |
@@ -20,24 +20,24 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Column |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var Calculator |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var Calculator |
|
| 25 | + */ |
|
| 26 | 26 | private $calculator; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | private $name; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var float |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var float |
|
| 35 | + */ |
|
| 36 | 36 | private $value; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var boolean |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var boolean |
|
| 40 | + */ |
|
| 41 | 41 | private $missing = false; |
| 42 | 42 | |
| 43 | 43 | public function __construct(Calculator $calculator, string $name, float $value) |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | * @see Mistralys\WidthsCalculator\Calculator\Column |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -declare (strict_types=1); |
|
| 9 | +declare(strict_types=1); |
|
| 10 | 10 | |
| 11 | 11 | namespace Mistralys\WidthsCalculator\Calculator; |
| 12 | 12 | |