Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 45... Zeile 45...
45
    }
45
    }
Zeile 46... Zeile 46...
46
 
46
 
47
    /**
47
    /**
48
     * Creates a BigDecimal of the given value.
48
     * Creates a BigDecimal of the given value.
49
     *
-
 
50
     * @param BigNumber|int|float|string $value
-
 
51
     *
-
 
52
     * @return BigDecimal
-
 
53
     *
49
     *
54
     * @throws MathException If the value cannot be converted to a BigDecimal.
50
     * @throws MathException If the value cannot be converted to a BigDecimal.
55
     *
51
     *
56
     * @psalm-pure
52
     * @psalm-pure
57
     */
53
     */
58
    public static function of($value) : BigNumber
54
    public static function of(BigNumber|int|float|string $value) : BigDecimal
59
    {
55
    {
60
        return parent::of($value)->toBigDecimal();
56
        return parent::of($value)->toBigDecimal();
Zeile 61... Zeile 57...
61
    }
57
    }
Zeile 66... Zeile 62...
66
     * Example: `(12345, 3)` will result in the BigDecimal `12.345`.
62
     * Example: `(12345, 3)` will result in the BigDecimal `12.345`.
67
     *
63
     *
68
     * @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger.
64
     * @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger.
69
     * @param int                        $scale The scale of the number, positive or zero.
65
     * @param int                        $scale The scale of the number, positive or zero.
70
     *
66
     *
71
     * @return BigDecimal
-
 
72
     *
-
 
73
     * @throws \InvalidArgumentException If the scale is negative.
67
     * @throws \InvalidArgumentException If the scale is negative.
74
     *
68
     *
75
     * @psalm-pure
69
     * @psalm-pure
76
     */
70
     */
77
    public static function ofUnscaledValue($value, int $scale = 0) : BigDecimal
71
    public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0) : BigDecimal
78
    {
72
    {
79
        if ($scale < 0) {
73
        if ($scale < 0) {
80
            throw new \InvalidArgumentException('The scale cannot be negative.');
74
            throw new \InvalidArgumentException('The scale cannot be negative.');
81
        }
75
        }
Zeile 84... Zeile 78...
84
    }
78
    }
Zeile 85... Zeile 79...
85
 
79
 
86
    /**
80
    /**
87
     * Returns a BigDecimal representing zero, with a scale of zero.
81
     * Returns a BigDecimal representing zero, with a scale of zero.
88
     *
-
 
89
     * @return BigDecimal
-
 
90
     *
82
     *
91
     * @psalm-pure
83
     * @psalm-pure
92
     */
84
     */
93
    public static function zero() : BigDecimal
85
    public static function zero() : BigDecimal
94
    {
86
    {
Zeile 106... Zeile 98...
106
    }
98
    }
Zeile 107... Zeile 99...
107
 
99
 
108
    /**
100
    /**
109
     * Returns a BigDecimal representing one, with a scale of zero.
101
     * Returns a BigDecimal representing one, with a scale of zero.
110
     *
-
 
111
     * @return BigDecimal
-
 
112
     *
102
     *
113
     * @psalm-pure
103
     * @psalm-pure
114
     */
104
     */
115
    public static function one() : BigDecimal
105
    public static function one() : BigDecimal
116
    {
106
    {
Zeile 128... Zeile 118...
128
    }
118
    }
Zeile 129... Zeile 119...
129
 
119
 
130
    /**
120
    /**
131
     * Returns a BigDecimal representing ten, with a scale of zero.
121
     * Returns a BigDecimal representing ten, with a scale of zero.
132
     *
-
 
133
     * @return BigDecimal
-
 
134
     *
122
     *
135
     * @psalm-pure
123
     * @psalm-pure
136
     */
124
     */
137
    public static function ten() : BigDecimal
125
    public static function ten() : BigDecimal
138
    {
126
    {
Zeile 154... Zeile 142...
154
     *
142
     *
155
     * The result has a scale of `max($this->scale, $that->scale)`.
143
     * The result has a scale of `max($this->scale, $that->scale)`.
156
     *
144
     *
157
     * @param BigNumber|int|float|string $that The number to add. Must be convertible to a BigDecimal.
145
     * @param BigNumber|int|float|string $that The number to add. Must be convertible to a BigDecimal.
158
     *
146
     *
159
     * @return BigDecimal The result.
-
 
160
     *
-
 
161
     * @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
147
     * @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
162
     */
148
     */
163
    public function plus($that) : BigDecimal
149
    public function plus(BigNumber|int|float|string $that) : BigDecimal
164
    {
150
    {
165
        $that = BigDecimal::of($that);
151
        $that = BigDecimal::of($that);
Zeile 166... Zeile 152...
166
 
152
 
167
        if ($that->value === '0' && $that->scale <= $this->scale) {
153
        if ($that->value === '0' && $that->scale <= $this->scale) {
Zeile 185... Zeile 171...
185
     *
171
     *
186
     * The result has a scale of `max($this->scale, $that->scale)`.
172
     * The result has a scale of `max($this->scale, $that->scale)`.
187
     *
173
     *
188
     * @param BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigDecimal.
174
     * @param BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigDecimal.
189
     *
175
     *
190
     * @return BigDecimal The result.
-
 
191
     *
-
 
192
     * @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
176
     * @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
193
     */
177
     */
194
    public function minus($that) : BigDecimal
178
    public function minus(BigNumber|int|float|string $that) : BigDecimal
195
    {
179
    {
196
        $that = BigDecimal::of($that);
180
        $that = BigDecimal::of($that);
Zeile 197... Zeile 181...
197
 
181
 
198
        if ($that->value === '0' && $that->scale <= $this->scale) {
182
        if ($that->value === '0' && $that->scale <= $this->scale) {
Zeile 212... Zeile 196...
212
     *
196
     *
213
     * The result has a scale of `$this->scale + $that->scale`.
197
     * The result has a scale of `$this->scale + $that->scale`.
214
     *
198
     *
215
     * @param BigNumber|int|float|string $that The multiplier. Must be convertible to a BigDecimal.
199
     * @param BigNumber|int|float|string $that The multiplier. Must be convertible to a BigDecimal.
216
     *
200
     *
217
     * @return BigDecimal The result.
-
 
218
     *
-
 
219
     * @throws MathException If the multiplier is not a valid number, or is not convertible to a BigDecimal.
201
     * @throws MathException If the multiplier is not a valid number, or is not convertible to a BigDecimal.
220
     */
202
     */
221
    public function multipliedBy($that) : BigDecimal
203
    public function multipliedBy(BigNumber|int|float|string $that) : BigDecimal
222
    {
204
    {
223
        $that = BigDecimal::of($that);
205
        $that = BigDecimal::of($that);
Zeile 224... Zeile 206...
224
 
206
 
225
        if ($that->value === '1' && $that->scale === 0) {
207
        if ($that->value === '1' && $that->scale === 0) {
Zeile 241... Zeile 223...
241
     *
223
     *
242
     * @param BigNumber|int|float|string $that         The divisor.
224
     * @param BigNumber|int|float|string $that         The divisor.
243
     * @param int|null                   $scale        The desired scale, or null to use the scale of this number.
225
     * @param int|null                   $scale        The desired scale, or null to use the scale of this number.
244
     * @param int                        $roundingMode An optional rounding mode.
226
     * @param int                        $roundingMode An optional rounding mode.
245
     *
227
     *
246
     * @return BigDecimal
-
 
247
     *
-
 
248
     * @throws \InvalidArgumentException If the scale or rounding mode is invalid.
228
     * @throws \InvalidArgumentException If the scale or rounding mode is invalid.
249
     * @throws MathException             If the number is invalid, is zero, or rounding was necessary.
229
     * @throws MathException             If the number is invalid, is zero, or rounding was necessary.
250
     */
230
     */
251
    public function dividedBy($that, ?int $scale = null, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
231
    public function dividedBy(BigNumber|int|float|string $that, ?int $scale = null, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
252
    {
232
    {
253
        $that = BigDecimal::of($that);
233
        $that = BigDecimal::of($that);
Zeile 254... Zeile 234...
254
 
234
 
255
        if ($that->isZero()) {
235
        if ($that->isZero()) {
Zeile 279... Zeile 259...
279
     *
259
     *
280
     * The scale of the result is automatically calculated to fit all the fraction digits.
260
     * The scale of the result is automatically calculated to fit all the fraction digits.
281
     *
261
     *
282
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
262
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
283
     *
263
     *
284
     * @return BigDecimal The result.
-
 
285
     *
-
 
286
     * @throws MathException If the divisor is not a valid number, is not convertible to a BigDecimal, is zero,
264
     * @throws MathException If the divisor is not a valid number, is not convertible to a BigDecimal, is zero,
287
     *                       or the result yields an infinite number of digits.
265
     *                       or the result yields an infinite number of digits.
288
     */
266
     */
289
    public function exactlyDividedBy($that) : BigDecimal
267
    public function exactlyDividedBy(BigNumber|int|float|string $that) : BigDecimal
290
    {
268
    {
291
        $that = BigDecimal::of($that);
269
        $that = BigDecimal::of($that);
Zeile 292... Zeile 270...
292
 
270
 
293
        if ($that->value === '0') {
271
        if ($that->value === '0') {
Zeile 320... Zeile 298...
320
    /**
298
    /**
321
     * Returns this number exponentiated to the given value.
299
     * Returns this number exponentiated to the given value.
322
     *
300
     *
323
     * The result has a scale of `$this->scale * $exponent`.
301
     * The result has a scale of `$this->scale * $exponent`.
324
     *
302
     *
325
     * @param int $exponent The exponent.
-
 
326
     *
-
 
327
     * @return BigDecimal The result.
-
 
328
     *
-
 
329
     * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
303
     * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
330
     */
304
     */
331
    public function power(int $exponent) : BigDecimal
305
    public function power(int $exponent) : BigDecimal
332
    {
306
    {
333
        if ($exponent === 0) {
307
        if ($exponent === 0) {
Zeile 354... Zeile 328...
354
     *
328
     *
355
     * The quotient has a scale of `0`.
329
     * The quotient has a scale of `0`.
356
     *
330
     *
357
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
331
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
358
     *
332
     *
359
     * @return BigDecimal The quotient.
-
 
360
     *
-
 
361
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
333
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
362
     */
334
     */
363
    public function quotient($that) : BigDecimal
335
    public function quotient(BigNumber|int|float|string $that) : BigDecimal
364
    {
336
    {
365
        $that = BigDecimal::of($that);
337
        $that = BigDecimal::of($that);
Zeile 366... Zeile 338...
366
 
338
 
367
        if ($that->isZero()) {
339
        if ($that->isZero()) {
Zeile 381... Zeile 353...
381
     *
353
     *
382
     * The remainder has a scale of `max($this->scale, $that->scale)`.
354
     * The remainder has a scale of `max($this->scale, $that->scale)`.
383
     *
355
     *
384
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
356
     * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
385
     *
357
     *
386
     * @return BigDecimal The remainder.
-
 
387
     *
-
 
388
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
358
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
389
     */
359
     */
390
    public function remainder($that) : BigDecimal
360
    public function remainder(BigNumber|int|float|string $that) : BigDecimal
391
    {
361
    {
392
        $that = BigDecimal::of($that);
362
        $that = BigDecimal::of($that);
Zeile 393... Zeile 363...
393
 
363
 
394
        if ($that->isZero()) {
364
        if ($that->isZero()) {
Zeile 414... Zeile 384...
414
     *
384
     *
415
     * @return BigDecimal[] An array containing the quotient and the remainder.
385
     * @return BigDecimal[] An array containing the quotient and the remainder.
416
     *
386
     *
417
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
387
     * @throws MathException If the divisor is not a valid decimal number, or is zero.
418
     */
388
     */
419
    public function quotientAndRemainder($that) : array
389
    public function quotientAndRemainder(BigNumber|int|float|string $that) : array
420
    {
390
    {
421
        $that = BigDecimal::of($that);
391
        $that = BigDecimal::of($that);
Zeile 422... Zeile 392...
422
 
392
 
423
        if ($that->isZero()) {
393
        if ($that->isZero()) {
Zeile 438... Zeile 408...
438
    }
408
    }
Zeile 439... Zeile 409...
439
 
409
 
440
    /**
410
    /**
441
     * Returns the square root of this number, rounded down to the given number of decimals.
411
     * Returns the square root of this number, rounded down to the given number of decimals.
442
     *
-
 
443
     * @param int $scale
-
 
444
     *
-
 
445
     * @return BigDecimal
-
 
446
     *
412
     *
447
     * @throws \InvalidArgumentException If the scale is negative.
413
     * @throws \InvalidArgumentException If the scale is negative.
448
     * @throws NegativeNumberException If this number is negative.
414
     * @throws NegativeNumberException If this number is negative.
449
     */
415
     */
450
    public function sqrt(int $scale) : BigDecimal
416
    public function sqrt(int $scale) : BigDecimal
Zeile 482... Zeile 448...
482
        return new BigDecimal($value, $scale);
448
        return new BigDecimal($value, $scale);
483
    }
449
    }
Zeile 484... Zeile 450...
484
 
450
 
485
    /**
451
    /**
486
     * Returns a copy of this BigDecimal with the decimal point moved $n places to the left.
-
 
487
     *
-
 
488
     * @param int $n
-
 
489
     *
-
 
490
     * @return BigDecimal
452
     * Returns a copy of this BigDecimal with the decimal point moved $n places to the left.
491
     */
453
     */
492
    public function withPointMovedLeft(int $n) : BigDecimal
454
    public function withPointMovedLeft(int $n) : BigDecimal
493
    {
455
    {
494
        if ($n === 0) {
456
        if ($n === 0) {
Zeile 502... Zeile 464...
502
        return new BigDecimal($this->value, $this->scale + $n);
464
        return new BigDecimal($this->value, $this->scale + $n);
503
    }
465
    }
Zeile 504... Zeile 466...
504
 
466
 
505
    /**
467
    /**
506
     * Returns a copy of this BigDecimal with the decimal point moved $n places to the right.
-
 
507
     *
-
 
508
     * @param int $n
-
 
509
     *
-
 
510
     * @return BigDecimal
468
     * Returns a copy of this BigDecimal with the decimal point moved $n places to the right.
511
     */
469
     */
512
    public function withPointMovedRight(int $n) : BigDecimal
470
    public function withPointMovedRight(int $n) : BigDecimal
513
    {
471
    {
514
        if ($n === 0) {
472
        if ($n === 0) {
Zeile 532... Zeile 490...
532
        return new BigDecimal($value, $scale);
490
        return new BigDecimal($value, $scale);
533
    }
491
    }
Zeile 534... Zeile 492...
534
 
492
 
535
    /**
493
    /**
536
     * Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part.
-
 
537
     *
-
 
538
     * @return BigDecimal
494
     * Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part.
539
     */
495
     */
540
    public function stripTrailingZeros() : BigDecimal
496
    public function stripTrailingZeros() : BigDecimal
541
    {
497
    {
542
        if ($this->scale === 0) {
498
        if ($this->scale === 0) {
Zeile 565... Zeile 521...
565
        return new BigDecimal($value, $scale);
521
        return new BigDecimal($value, $scale);
566
    }
522
    }
Zeile 567... Zeile 523...
567
 
523
 
568
    /**
524
    /**
569
     * Returns the absolute value of this number.
-
 
570
     *
-
 
571
     * @return BigDecimal
525
     * Returns the absolute value of this number.
572
     */
526
     */
573
    public function abs() : BigDecimal
527
    public function abs() : BigDecimal
574
    {
528
    {
575
        return $this->isNegative() ? $this->negated() : $this;
529
        return $this->isNegative() ? $this->negated() : $this;
Zeile 576... Zeile 530...
576
    }
530
    }
577
 
531
 
578
    /**
-
 
579
     * Returns the negated value of this number.
-
 
580
     *
532
    /**
581
     * @return BigDecimal
533
     * Returns the negated value of this number.
582
     */
534
     */
583
    public function negated() : BigDecimal
535
    public function negated() : BigDecimal
584
    {
536
    {
Zeile 585... Zeile -...
585
        return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
-
 
586
    }
-
 
587
 
-
 
588
    /**
537
        return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
589
     * {@inheritdoc}
538
    }
590
     */
539
 
Zeile 591... Zeile 540...
591
    public function compareTo($that) : int
540
    public function compareTo(BigNumber|int|float|string $that) : int
592
    {
541
    {
Zeile 603... Zeile 552...
603
        }
552
        }
Zeile 604... Zeile 553...
604
 
553
 
605
        return - $that->compareTo($this);
554
        return - $that->compareTo($this);
Zeile 606... Zeile -...
606
    }
-
 
607
 
-
 
608
    /**
-
 
609
     * {@inheritdoc}
555
    }
610
     */
556
 
611
    public function getSign() : int
557
    public function getSign() : int
612
    {
558
    {
Zeile 613... Zeile -...
613
        return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
-
 
614
    }
-
 
615
 
-
 
616
    /**
559
        return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
617
     * @return BigInteger
560
    }
618
     */
561
 
619
    public function getUnscaledValue() : BigInteger
562
    public function getUnscaledValue() : BigInteger
Zeile 620... Zeile -...
620
    {
-
 
621
        return BigInteger::create($this->value);
-
 
622
    }
-
 
623
 
563
    {
624
    /**
564
        return self::newBigInteger($this->value);
625
     * @return int
565
    }
626
     */
566
 
Zeile 627... Zeile 567...
627
    public function getScale() : int
567
    public function getScale() : int
628
    {
568
    {
629
        return $this->scale;
569
        return $this->scale;
630
    }
570
    }
631
 
-
 
632
    /**
-
 
633
     * Returns a string representing the integral part of this decimal number.
571
 
634
     *
572
    /**
635
     * Example: `-123.456` => `-123`.
573
     * Returns a string representing the integral part of this decimal number.
636
     *
574
     *
637
     * @return string
575
     * Example: `-123.456` => `-123`.
Zeile 651... Zeile 589...
651
     * Returns a string representing the fractional part of this decimal number.
589
     * Returns a string representing the fractional part of this decimal number.
652
     *
590
     *
653
     * If the scale is zero, an empty string is returned.
591
     * If the scale is zero, an empty string is returned.
654
     *
592
     *
655
     * Examples: `-123.456` => '456', `123` => ''.
593
     * Examples: `-123.456` => '456', `123` => ''.
656
     *
-
 
657
     * @return string
-
 
658
     */
594
     */
659
    public function getFractionalPart() : string
595
    public function getFractionalPart() : string
660
    {
596
    {
661
        if ($this->scale === 0) {
597
        if ($this->scale === 0) {
662
            return '';
598
            return '';
Zeile 667... Zeile 603...
667
        return \substr($value, -$this->scale);
603
        return \substr($value, -$this->scale);
668
    }
604
    }
Zeile 669... Zeile 605...
669
 
605
 
670
    /**
606
    /**
671
     * Returns whether this decimal number has a non-zero fractional part.
-
 
672
     *
-
 
673
     * @return bool
607
     * Returns whether this decimal number has a non-zero fractional part.
674
     */
608
     */
675
    public function hasNonZeroFractionalPart() : bool
609
    public function hasNonZeroFractionalPart() : bool
676
    {
610
    {
677
        return $this->getFractionalPart() !== \str_repeat('0', $this->scale);
611
        return $this->getFractionalPart() !== \str_repeat('0', $this->scale);
Zeile 678... Zeile -...
678
    }
-
 
679
 
-
 
680
    /**
-
 
681
     * {@inheritdoc}
612
    }
682
     */
613
 
683
    public function toBigInteger() : BigInteger
614
    public function toBigInteger() : BigInteger
Zeile 684... Zeile 615...
684
    {
615
    {
685
        $zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
616
        $zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
Zeile 686... Zeile -...
686
 
-
 
687
        return BigInteger::create($zeroScaleDecimal->value);
-
 
688
    }
-
 
689
 
617
 
690
    /**
618
        return self::newBigInteger($zeroScaleDecimal->value);
691
     * {@inheritdoc}
619
    }
692
     */
620
 
Zeile 693... Zeile -...
693
    public function toBigDecimal() : BigDecimal
-
 
694
    {
-
 
695
        return $this;
-
 
696
    }
621
    public function toBigDecimal() : BigDecimal
697
 
622
    {
698
    /**
623
        return $this;
699
     * {@inheritdoc}
624
    }
Zeile 700... Zeile 625...
700
     */
625
 
701
    public function toBigRational() : BigRational
626
    public function toBigRational() : BigRational
Zeile 702... Zeile -...
702
    {
-
 
703
        $numerator = BigInteger::create($this->value);
-
 
704
        $denominator = BigInteger::create('1' . \str_repeat('0', $this->scale));
-
 
705
 
627
    {
706
        return BigRational::create($numerator, $denominator, false);
628
        $numerator = self::newBigInteger($this->value);
707
    }
629
        $denominator = self::newBigInteger('1' . \str_repeat('0', $this->scale));
708
 
630
 
709
    /**
631
        return self::newBigRational($numerator, $denominator, false);
Zeile 710... Zeile 632...
710
     * {@inheritdoc}
632
    }
711
     */
633
 
Zeile 712... Zeile -...
712
    public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
-
 
713
    {
-
 
714
        if ($scale === $this->scale) {
-
 
715
            return $this;
634
    public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
716
        }
635
    {
717
 
636
        if ($scale === $this->scale) {
718
        return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode);
637
            return $this;
Zeile 719... Zeile -...
719
    }
-
 
720
 
-
 
721
    /**
-
 
722
     * {@inheritdoc}
638
        }
723
     */
639
 
724
    public function toInt() : int
640
        return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode);
725
    {
641
    }
Zeile 726... Zeile -...
726
        return $this->toBigInteger()->toInt();
-
 
727
    }
-
 
728
 
-
 
729
    /**
642
 
730
     * {@inheritdoc}
643
    public function toInt() : int
731
     */
644
    {
732
    public function toFloat() : float
645
        return $this->toBigInteger()->toInt();
733
    {
646
    }
Zeile 766... Zeile 679...
766
     * @internal
679
     * @internal
767
     * @psalm-suppress RedundantPropertyInitializationCheck
680
     * @psalm-suppress RedundantPropertyInitializationCheck
768
     *
681
     *
769
     * @param array{value: string, scale: int} $data
682
     * @param array{value: string, scale: int} $data
770
     *
683
     *
771
     * @return void
-
 
772
     *
-
 
773
     * @throws \LogicException
684
     * @throws \LogicException
774
     */
685
     */
775
    public function __unserialize(array $data): void
686
    public function __unserialize(array $data): void
776
    {
687
    {
777
        if (isset($this->value)) {
688
        if (isset($this->value)) {
Zeile 784... Zeile 695...
784
 
695
 
785
    /**
696
    /**
786
     * This method is required by interface Serializable and SHOULD NOT be accessed directly.
697
     * This method is required by interface Serializable and SHOULD NOT be accessed directly.
787
     *
698
     *
788
     * @internal
-
 
789
     *
-
 
790
     * @return string
699
     * @internal
791
     */
700
     */
792
    public function serialize() : string
701
    public function serialize() : string
793
    {
702
    {
794
        return $this->value . ':' . $this->scale;
703
        return $this->value . ':' . $this->scale;
Zeile 798... Zeile 707...
798
     * This method is only here to implement interface Serializable and cannot be accessed directly.
707
     * This method is only here to implement interface Serializable and cannot be accessed directly.
799
     *
708
     *
800
     * @internal
709
     * @internal
801
     * @psalm-suppress RedundantPropertyInitializationCheck
710
     * @psalm-suppress RedundantPropertyInitializationCheck
802
     *
711
     *
803
     * @param string $value
-
 
804
     *
-
 
805
     * @return void
-
 
806
     *
-
 
807
     * @throws \LogicException
712
     * @throws \LogicException
808
     */
713
     */
809
    public function unserialize($value) : void
714
    public function unserialize($value) : void
810
    {
715
    {
811
        if (isset($this->value)) {
716
        if (isset($this->value)) {
Zeile 819... Zeile 724...
819
    }
724
    }
Zeile 820... Zeile 725...
820
 
725
 
821
    /**
726
    /**
822
     * Puts the internal values of the given decimal numbers on the same scale.
727
     * Puts the internal values of the given decimal numbers on the same scale.
823
     *
-
 
824
     * @param BigDecimal $x The first decimal number.
-
 
825
     * @param BigDecimal $y The second decimal number.
-
 
826
     *
728
     *
827
     * @return array{string, string} The scaled integer values of $x and $y.
729
     * @return array{string, string} The scaled integer values of $x and $y.
828
     */
730
     */
829
    private function scaleValues(BigDecimal $x, BigDecimal $y) : array
731
    private function scaleValues(BigDecimal $x, BigDecimal $y) : array
830
    {
732
    {
Zeile 838... Zeile 740...
838
        }
740
        }
Zeile 839... Zeile 741...
839
 
741
 
840
        return [$a, $b];
742
        return [$a, $b];
Zeile 841... Zeile -...
841
    }
-
 
842
 
-
 
843
    /**
-
 
844
     * @param int $scale
-
 
845
     *
-
 
846
     * @return string
743
    }
847
     */
744
 
848
    private function valueWithMinScale(int $scale) : string
745
    private function valueWithMinScale(int $scale) : string
Zeile 849... Zeile 746...
849
    {
746
    {
Zeile 856... Zeile 753...
856
        return $value;
753
        return $value;
857
    }
754
    }
Zeile 858... Zeile 755...
858
 
755
 
859
    /**
756
    /**
860
     * Adds leading zeros if necessary to the unscaled value to represent the full decimal number.
-
 
861
     *
-
 
862
     * @return string
757
     * Adds leading zeros if necessary to the unscaled value to represent the full decimal number.
863
     */
758
     */
864
    private function getUnscaledValueWithLeadingZeros() : string
759
    private function getUnscaledValueWithLeadingZeros() : string
865
    {
760
    {
866
        $value = $this->value;
761
        $value = $this->value;