1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
/**
4
6
* MIT License
5
7
* For full license information, please view the LICENSE file that was distributed with this source code.
@@ -59,10 +61,10 @@ class Decimal implements JsonSerializable, Stringable
59
61
protected int $ scale = 0 ;
60
62
61
63
/**
62
- * @param static |string|float|int $value
64
+ * @param object |string|float|int $value
63
65
* @param int|null $scale
64
66
*/
65
- public function __construct (self |string |float |int $ value , ?int $ scale = null )
67
+ public function __construct (object |string |float |int $ value , ?int $ scale = null )
66
68
{
67
69
$ value = $ this ->parseValue ($ value );
68
70
$ value = $ this ->normalizeValue ($ value );
@@ -136,12 +138,12 @@ protected function normalizeValue(string $value): string
136
138
* Otherwise, create a new Decimal instance from the given value and return
137
139
* it.
138
140
*
139
- * @param static |string|float|int $value
141
+ * @param object |string|float|int $value
140
142
* @param int|null $scale
141
143
*
142
144
* @return static
143
145
*/
144
- public static function create (self |string |float |int $ value , ?int $ scale = null ): static
146
+ public static function create (object |string |float |int $ value , ?int $ scale = null ): static
145
147
{
146
148
if ($ scale === null && $ value instanceof static) {
147
149
return clone $ value ;
@@ -234,7 +236,7 @@ public function compareTo(self|string|float|int $value): int
234
236
$ decimal = static ::create ($ value );
235
237
$ scale = max ($ this ->scale (), $ decimal ->scale ());
236
238
237
- return bccomp ($ this , $ decimal , $ scale );
239
+ return bccomp (( string ) $ this , ( string ) $ decimal , $ scale );
238
240
}
239
241
240
242
/**
@@ -250,7 +252,7 @@ public function add(self|string|float|int $value, ?int $scale = null): static
250
252
$ decimal = static ::create ($ value );
251
253
$ scale = $ this ->resultScale ($ this , $ decimal , $ scale );
252
254
253
- return new static (bcadd ($ this , $ decimal , $ scale ));
255
+ return new static (bcadd (( string ) $ this , ( string ) $ decimal , $ scale ));
254
256
}
255
257
256
258
/**
@@ -284,7 +286,7 @@ public function subtract(self|string|float|int $value, ?int $scale = null): stat
284
286
$ decimal = static ::create ($ value );
285
287
$ scale = $ this ->resultScale ($ this , $ decimal , $ scale );
286
288
287
- return new static (bcsub ($ this , $ decimal , $ scale ));
289
+ return new static (bcsub (( string ) $ this , ( string ) $ decimal , $ scale ));
288
290
}
289
291
290
292
/**
@@ -394,7 +396,7 @@ public function multiply(self|string|int|float $value, ?int $scale = null): stat
394
396
$ scale = $ this ->scale () + $ decimal ->scale ();
395
397
}
396
398
397
- return new static (bcmul ($ this , $ decimal , $ scale ));
399
+ return new static (bcmul (( string ) $ this , ( string ) $ decimal , $ scale ));
398
400
}
399
401
400
402
/**
@@ -414,7 +416,7 @@ public function divide(self|string|int|float $value, int $scale): static
414
416
throw new DivisionByZeroError ('Cannot divide by zero. Only Chuck Norris can! ' );
415
417
}
416
418
417
- return new static (bcdiv ($ this , $ decimal , $ scale ));
419
+ return new static (bcdiv (( string ) $ this , ( string ) $ decimal , $ scale ));
418
420
}
419
421
420
422
/**
@@ -431,7 +433,7 @@ public function pow(self|string|int $exponent, ?int $scale = null): static
431
433
$ scale = $ this ->scale ();
432
434
}
433
435
434
- return new static (bcpow ($ this , (string )$ exponent , $ scale ));
436
+ return new static (bcpow (( string ) $ this , (string )$ exponent , $ scale ));
435
437
}
436
438
437
439
/**
@@ -447,7 +449,7 @@ public function sqrt(?int $scale = null): static
447
449
$ scale = $ this ->scale ();
448
450
}
449
451
450
- return new static (bcsqrt ($ this , $ scale ));
452
+ return new static (bcsqrt (( string ) $ this , $ scale ));
451
453
}
452
454
453
455
/**
@@ -464,7 +466,7 @@ public function mod(self|string|int $value, ?int $scale = null): static
464
466
$ scale = $ this ->scale ();
465
467
}
466
468
467
- return new static (bcmod ($ this , (string )$ value , $ scale ));
469
+ return new static (bcmod (( string ) $ this , (string )$ value , $ scale ));
468
470
}
469
471
470
472
/**
@@ -480,16 +482,16 @@ public function round(int $scale = 0, int $roundMode = self::ROUND_HALF_UP): sta
480
482
$ e = bcpow ('10 ' , (string )$ exponent );
481
483
switch ($ roundMode ) {
482
484
case static ::ROUND_FLOOR :
483
- $ v = bcdiv (bcadd (bcmul ($ this , $ e , 0 ), $ this ->isNegative () ? '-9 ' : '0 ' ), $ e , 0 );
485
+ $ v = bcdiv (bcadd (bcmul (( string ) $ this , $ e , 0 ), $ this ->isNegative () ? '-9 ' : '0 ' ), $ e , 0 );
484
486
485
487
break ;
486
488
case static ::ROUND_CEIL :
487
- $ v = bcdiv (bcadd (bcmul ($ this , $ e , 0 ), $ this ->isNegative () ? '0 ' : '9 ' ), $ e , 0 );
489
+ $ v = bcdiv (bcadd (bcmul (( string ) $ this , $ e , 0 ), $ this ->isNegative () ? '0 ' : '9 ' ), $ e , 0 );
488
490
489
491
break ;
490
492
case static ::ROUND_HALF_UP :
491
493
default :
492
- $ v = bcdiv (bcadd (bcmul ($ this , $ e , 0 ), $ this ->isNegative () ? '-5 ' : '5 ' ), $ e , $ scale );
494
+ $ v = bcdiv (bcadd (bcmul (( string ) $ this , $ e , 0 ), $ this ->isNegative () ? '-5 ' : '5 ' ), $ e , $ scale );
493
495
}
494
496
495
497
return new static ($ v );
0 commit comments