Skip to content

Commit 2b5381a

Browse files
author
Pantea Marius-ciclistu
committed
POC for laravel/framework#31778 bulletproofing incrementOrDecrement
1 parent 4fbd777 commit 2b5381a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Models/BaseModel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ protected function incrementOrDecrement($column, $amount, $extra, $method): int
475475

476476
$this->{$column} = $this->isClassDeviable($column)
477477
? $this->deviateClassCastableAttribute($method, $column, $amount)
478-
: $this->{$column} + ($method === 'increment' ? $amount : $amount * -1);
478+
: (\extension_loaded('bcmath') ? \bcadd(
479+
$s1 = (string)$this->{$column},
480+
$s2 = (string)($method === 'increment' ? $amount : $amount * -1),
481+
\max(\strlen(\strrchr($s1, '.') ?: ''), \strlen(\strrchr($s2, '.') ?: ''))
482+
) : $this->{$column} + ($method === 'increment' ? $amount : $amount * -1));
479483

480484
$this->forceFill($extra);
481485

0 commit comments

Comments
 (0)