@@ -24,9 +24,9 @@ |
||
| 24 | 24 | private int $amountCols; |
| 25 | 25 | private int $missing = 0; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var Column[] |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var Column[] |
|
| 29 | + */ |
|
| 30 | 30 | private array $columns; |
| 31 | 31 | |
| 32 | 32 | public function __construct(Calculator $calculator) |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | private Calculator $calculator; |
| 24 | 24 | private Operations $operations; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var Column[] |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var Column[] |
|
| 28 | + */ |
|
| 29 | 29 | private array $columns; |
| 30 | 30 | |
| 31 | 31 | public function __construct(Calculator $calculator) |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | $this->cleanUp($leftover); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * In integer mode, after filling all items, because of rounding |
|
| 69 | - * the amount of column up, we may have added a bit too much. We |
|
| 70 | - * fix this here, by removing it from the last column. |
|
| 71 | - * |
|
| 72 | - * @param float $leftover |
|
| 73 | - */ |
|
| 67 | + /** |
|
| 68 | + * In integer mode, after filling all items, because of rounding |
|
| 69 | + * the amount of column up, we may have added a bit too much. We |
|
| 70 | + * fix this here, by removing it from the last column. |
|
| 71 | + * |
|
| 72 | + * @param float $leftover |
|
| 73 | + */ |
|
| 74 | 74 | private function cleanUp(float $leftover) : void |
| 75 | 75 | { |
| 76 | 76 | if($leftover >= 0 || empty($this->columns)) |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @see Mistralys\WidthsCalculator\Calculator\LeftoverFiller |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -declare (strict_types=1); |
|
| 9 | +declare(strict_types=1); |
|
| 10 | 10 | |
| 11 | 11 | namespace Mistralys\WidthsCalculator\Calculator; |
| 12 | 12 | |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | $leftover = $this->calculator->getMaxTotal() - $this->operations->calcTotal(); |
| 41 | 41 | $perCol = $leftover / $this->operations->countColumns(); |
| 42 | 42 | |
| 43 | - if($this->calculator->isIntegerMode()) |
|
| 43 | + if ($this->calculator->isIntegerMode()) |
|
| 44 | 44 | { |
| 45 | 45 | $perCol = (int)ceil($perCol); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - for($i=($this->operations->countColumns()-1); $i >=0; $i--) |
|
| 48 | + for ($i = ($this->operations->countColumns() - 1); $i >= 0; $i--) |
|
| 49 | 49 | { |
| 50 | - if($leftover <= 0) |
|
| 50 | + if ($leftover <= 0) |
|
| 51 | 51 | { |
| 52 | 52 | break; |
| 53 | 53 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | private function cleanUp(float $leftover) : void |
| 75 | 75 | { |
| 76 | - if($leftover >= 0 || empty($this->columns)) |
|
| 76 | + if ($leftover >= 0 || empty($this->columns)) |
|
| 77 | 77 | { |
| 78 | 78 | return; |
| 79 | 79 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | use Traits_Optionable; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var Column[] |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var Column[] |
|
| 42 | + */ |
|
| 43 | 43 | private $columns = array(); |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var boolean |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var boolean |
|
| 47 | + */ |
|
| 48 | 48 | private $calculated = false; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var Operations |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var Operations |
|
| 52 | + */ |
|
| 53 | 53 | private $operations; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param array<string,float> $columnValues |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @param array<string,float> $columnValues |
|
| 57 | + */ |
|
| 58 | 58 | private function __construct(array $columnValues) |
| 59 | 59 | { |
| 60 | 60 | foreach($columnValues as $name => $value) |
@@ -68,20 +68,20 @@ discard block |
||
| 68 | 68 | $this->operations = new Operations($this); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Creates an instance of the calculator. |
|
| 73 | - * |
|
| 74 | - * @param array<string,float> $columnValues |
|
| 75 | - * @return Calculator |
|
| 76 | - */ |
|
| 71 | + /** |
|
| 72 | + * Creates an instance of the calculator. |
|
| 73 | + * |
|
| 74 | + * @param array<string,float> $columnValues |
|
| 75 | + * @return Calculator |
|
| 76 | + */ |
|
| 77 | 77 | public static function create(array $columnValues) : Calculator |
| 78 | 78 | { |
| 79 | 79 | return new Calculator($columnValues); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return array<string,mixed> |
|
| 84 | - */ |
|
| 82 | + /** |
|
| 83 | + * @return array<string,mixed> |
|
| 84 | + */ |
|
| 85 | 85 | public function getDefaultOptions(): array |
| 86 | 86 | { |
| 87 | 87 | return array( |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | return $this; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Sets the minimum width to enforce for columns, |
|
| 118 | - * when there already are other columns that take |
|
| 119 | - * up all the available width. |
|
| 120 | - * |
|
| 121 | - * @param float $width |
|
| 122 | - * @return Calculator |
|
| 123 | - */ |
|
| 116 | + /** |
|
| 117 | + * Sets the minimum width to enforce for columns, |
|
| 118 | + * when there already are other columns that take |
|
| 119 | + * up all the available width. |
|
| 120 | + * |
|
| 121 | + * @param float $width |
|
| 122 | + * @return Calculator |
|
| 123 | + */ |
|
| 124 | 124 | public function setMinWidth(float $width) : Calculator |
| 125 | 125 | { |
| 126 | 126 | $max = $this->getMaxMinWidth(); |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | $this->columns[] = $col; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Retrieves the minimum width for columns, in percent. |
|
| 157 | - * @return float |
|
| 158 | - */ |
|
| 155 | + /** |
|
| 156 | + * Retrieves the minimum width for columns, in percent. |
|
| 157 | + * @return float |
|
| 158 | + */ |
|
| 159 | 159 | public function getMinWidth() : float |
| 160 | 160 | { |
| 161 | 161 | return floatval($this->getOption('minPerCol')); |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | $this->calculated = true; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Adjusts the individual column values to match |
|
| 186 | - * the expected output format, for example ensuring |
|
| 187 | - * integer values if we are in integer mode. |
|
| 188 | - */ |
|
| 184 | + /** |
|
| 185 | + * Adjusts the individual column values to match |
|
| 186 | + * the expected output format, for example ensuring |
|
| 187 | + * integer values if we are in integer mode. |
|
| 188 | + */ |
|
| 189 | 189 | private function convertToInteger() : void |
| 190 | 190 | { |
| 191 | 191 | // convert all columns to integer values as required |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Retrieves the updated list of column values, |
|
| 204 | - * retaining the original keys. |
|
| 205 | - * |
|
| 206 | - * @return array<string,int|float> |
|
| 207 | - */ |
|
| 202 | + /** |
|
| 203 | + * Retrieves the updated list of column values, |
|
| 204 | + * retaining the original keys. |
|
| 205 | + * |
|
| 206 | + * @return array<string,int|float> |
|
| 207 | + */ |
|
| 208 | 208 | public function getValues() : array |
| 209 | 209 | { |
| 210 | 210 | $this->calculate(); |
@@ -231,13 +231,13 @@ discard block |
||
| 231 | 231 | return $this->getBoolOption('integerValues'); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Retrieves the column values as pixel values, based on |
|
| 236 | - * the target available pixel width. |
|
| 237 | - * |
|
| 238 | - * @param int $targetWidth |
|
| 239 | - * @return array<string,int> |
|
| 240 | - */ |
|
| 234 | + /** |
|
| 235 | + * Retrieves the column values as pixel values, based on |
|
| 236 | + * the target available pixel width. |
|
| 237 | + * |
|
| 238 | + * @param int $targetWidth |
|
| 239 | + * @return array<string,int> |
|
| 240 | + */ |
|
| 241 | 241 | public function getPixelValues(int $targetWidth) : array |
| 242 | 242 | { |
| 243 | 243 | $calc = self::create($this->getValues()); |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | return $result; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * @return Column[] |
|
| 258 | - */ |
|
| 256 | + /** |
|
| 257 | + * @return Column[] |
|
| 258 | + */ |
|
| 259 | 259 | public function getColumns() : array |
| 260 | 260 | { |
| 261 | 261 | return $this->columns; |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | $surplus->remove(); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Detects any leftover percentages that still need |
|
| 272 | - * to be filled, in case we are not at 100% yet. It |
|
| 273 | - * distributes the missing percentages evenly over the |
|
| 274 | - * available columns, from the last one upwards. |
|
| 275 | - */ |
|
| 270 | + /** |
|
| 271 | + * Detects any leftover percentages that still need |
|
| 272 | + * to be filled, in case we are not at 100% yet. It |
|
| 273 | + * distributes the missing percentages evenly over the |
|
| 274 | + * available columns, from the last one upwards. |
|
| 275 | + */ |
|
| 276 | 276 | private function fillLeftover() : void |
| 277 | 277 | { |
| 278 | 278 | $filler = new LeftoverFiller($this); |
@@ -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 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | private function __construct(array $columnValues) |
| 59 | 59 | { |
| 60 | - foreach($columnValues as $name => $value) |
|
| 60 | + foreach ($columnValues as $name => $value) |
|
| 61 | 61 | { |
| 62 | 62 | $this->addColumn( |
| 63 | 63 | (string)$name, |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | return $this->operations; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function setFloatValues(bool $enable=true) : Calculator |
|
| 110 | + public function setFloatValues(bool $enable = true) : Calculator |
|
| 111 | 111 | { |
| 112 | 112 | $this->setOption('integerValues', !$enable); |
| 113 | 113 | return $this; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | { |
| 126 | 126 | $max = $this->getMaxMinWidth(); |
| 127 | 127 | |
| 128 | - if($width > $max) |
|
| 128 | + if ($width > $max) |
|
| 129 | 129 | { |
| 130 | 130 | throw new \Exception( |
| 131 | 131 | sprintf('Minimum width cannot be set above %s.', number_format($max, 4)), |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | private function calculate() : void |
| 165 | 165 | { |
| 166 | - if($this->calculated) |
|
| 166 | + if ($this->calculated) |
|
| 167 | 167 | { |
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if($this->operations->calcTotal() > $this->getMaxTotal()) |
|
| 171 | + if ($this->operations->calcTotal() > $this->getMaxTotal()) |
|
| 172 | 172 | { |
| 173 | 173 | $this->fixOverflow(); |
| 174 | 174 | } |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | private function convertToInteger() : void |
| 190 | 190 | { |
| 191 | 191 | // convert all columns to integer values as required |
| 192 | - if($this->isIntegerMode()) |
|
| 192 | + if ($this->isIntegerMode()) |
|
| 193 | 193 | { |
| 194 | - foreach($this->columns as $col) |
|
| 194 | + foreach ($this->columns as $col) |
|
| 195 | 195 | { |
| 196 | 196 | $val = intval(floor($col->getValue())); |
| 197 | 197 | $col->setValue(floatval($val)); |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | $result = array(); |
| 213 | 213 | |
| 214 | - foreach($this->columns as $col) |
|
| 214 | + foreach ($this->columns as $col) |
|
| 215 | 215 | { |
| 216 | 216 | $val = $col->getValue(); |
| 217 | 217 | |
| 218 | - if($this->isIntegerMode()) |
|
| 218 | + if ($this->isIntegerMode()) |
|
| 219 | 219 | { |
| 220 | 220 | $val = intval($val); |
| 221 | 221 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $values = $calc->getValues(); |
| 246 | 246 | |
| 247 | 247 | $result = array(); |
| 248 | - foreach($values as $name => $value) |
|
| 248 | + foreach ($values as $name => $value) |
|
| 249 | 249 | { |
| 250 | 250 | $result[$name] = (int)$value; |
| 251 | 251 | } |