Code Duplication    Length = 45-45 lines in 3 locations

src/PhpSpreadsheet/Shared/JAMA/Matrix.php 3 locations

@@ 504-548 (lines=45) @@
501
     *
502
     * @return Matrix Sum
503
     */
504
    public function plusEquals(...$args)
505
    {
506
        if (count($args) > 0) {
507
            $match = implode(',', array_map('gettype', $args));
508
509
            switch ($match) {
510
                case 'object':
511
                    if ($args[0] instanceof self) {
512
                        $M = $args[0];
513
                    } else {
514
                        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION);
515
                    }
516
                    break;
517
                case 'array':
518
                    $M = new self($args[0]);
519
                    break;
520
                default:
521
                    throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
522
                    break;
523
            }
524
            $this->checkMatrixDimensions($M);
525
            for ($i = 0; $i < $this->m; ++$i) {
526
                for ($j = 0; $j < $this->n; ++$j) {
527
                    $validValues = true;
528
                    $value = $M->get($i, $j);
529
                    if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
530
                        $this->A[$i][$j] = trim($this->A[$i][$j], '"');
531
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]);
532
                    }
533
                    if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
534
                        $value = trim($value, '"');
535
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value);
536
                    }
537
                    if ($validValues) {
538
                        $this->A[$i][$j] += $value;
539
                    } else {
540
                        $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN();
541
                    }
542
                }
543
            }
544
545
            return $this;
546
        }
547
        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
548
    }
549
550
    /**
551
     * minus.
@@ 600-644 (lines=45) @@
597
     *
598
     * @return Matrix Sum
599
     */
600
    public function minusEquals(...$args)
601
    {
602
        if (count($args) > 0) {
603
            $match = implode(',', array_map('gettype', $args));
604
605
            switch ($match) {
606
                case 'object':
607
                    if ($args[0] instanceof self) {
608
                        $M = $args[0];
609
                    } else {
610
                        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION);
611
                    }
612
                    break;
613
                case 'array':
614
                    $M = new self($args[0]);
615
                    break;
616
                default:
617
                    throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
618
                    break;
619
            }
620
            $this->checkMatrixDimensions($M);
621
            for ($i = 0; $i < $this->m; ++$i) {
622
                for ($j = 0; $j < $this->n; ++$j) {
623
                    $validValues = true;
624
                    $value = $M->get($i, $j);
625
                    if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
626
                        $this->A[$i][$j] = trim($this->A[$i][$j], '"');
627
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]);
628
                    }
629
                    if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
630
                        $value = trim($value, '"');
631
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value);
632
                    }
633
                    if ($validValues) {
634
                        $this->A[$i][$j] -= $value;
635
                    } else {
636
                        $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN();
637
                    }
638
                }
639
            }
640
641
            return $this;
642
        }
643
        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
644
    }
645
646
    /**
647
     * arrayTimes.
@@ 698-742 (lines=45) @@
695
     *
696
     * @return Matrix Matrix Aij
697
     */
698
    public function arrayTimesEquals(...$args)
699
    {
700
        if (count($args) > 0) {
701
            $match = implode(',', array_map('gettype', $args));
702
703
            switch ($match) {
704
                case 'object':
705
                    if ($args[0] instanceof self) {
706
                        $M = $args[0];
707
                    } else {
708
                        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION);
709
                    }
710
                    break;
711
                case 'array':
712
                    $M = new self($args[0]);
713
                    break;
714
                default:
715
                    throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
716
                    break;
717
            }
718
            $this->checkMatrixDimensions($M);
719
            for ($i = 0; $i < $this->m; ++$i) {
720
                for ($j = 0; $j < $this->n; ++$j) {
721
                    $validValues = true;
722
                    $value = $M->get($i, $j);
723
                    if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
724
                        $this->A[$i][$j] = trim($this->A[$i][$j], '"');
725
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]);
726
                    }
727
                    if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
728
                        $value = trim($value, '"');
729
                        $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value);
730
                    }
731
                    if ($validValues) {
732
                        $this->A[$i][$j] *= $value;
733
                    } else {
734
                        $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN();
735
                    }
736
                }
737
            }
738
739
            return $this;
740
        }
741
        throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
742
    }
743
744
    /**
745
     * arrayRightDivide.