Code Duplication    Length = 34-35 lines in 2 locations

src/PhpSpreadsheet/Reader/Slk.php 1 location

@@ 315-349 (lines=35) @@
312
                            //    Convert R1C1 style references to A1 style references (but only when not quoted)
313
                            $temp = explode('"', $cellDataFormula);
314
                            $key = false;
315
                            foreach ($temp as &$value) {
316
                                //    Only count/replace in alternate array entries
317
                                if ($key = !$key) {
318
                                    preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE);
319
                                    //    Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
320
                                    //        through the formula from left to right. Reversing means that we work right to left.through
321
                                    //        the formula
322
                                    $cellReferences = array_reverse($cellReferences);
323
                                    //    Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
324
                                    //        then modify the formula to use that new reference
325
                                    foreach ($cellReferences as $cellReference) {
326
                                        $rowReference = $cellReference[2][0];
327
                                        //    Empty R reference is the current row
328
                                        if ($rowReference == '') {
329
                                            $rowReference = $row;
330
                                        }
331
                                        //    Bracketed R references are relative to the current row
332
                                        if ($rowReference[0] == '[') {
333
                                            $rowReference = $row + trim($rowReference, '[]');
334
                                        }
335
                                        $columnReference = $cellReference[4][0];
336
                                        //    Empty C reference is the current column
337
                                        if ($columnReference == '') {
338
                                            $columnReference = $column;
339
                                        }
340
                                        //    Bracketed C references are relative to the current column
341
                                        if ($columnReference[0] == '[') {
342
                                            $columnReference = $column + trim($columnReference, '[]');
343
                                        }
344
                                        $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference;
345
346
                                        $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
347
                                    }
348
                                }
349
                            }
350
                            unset($value);
351
                            //    Then rebuild the formula string
352
                            $cellDataFormula = implode('"', $temp);

src/PhpSpreadsheet/Reader/Xml.php 1 location

@@ 720-753 (lines=34) @@
717
                                    //    Convert R1C1 style references to A1 style references (but only when not quoted)
718
                                    $temp = explode('"', $cellDataFormula);
719
                                    $key = false;
720
                                    foreach ($temp as &$value) {
721
                                        //    Only replace in alternate array entries (i.e. non-quoted blocks)
722
                                        if ($key = !$key) {
723
                                            preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE);
724
                                            //    Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
725
                                            //        through the formula from left to right. Reversing means that we work right to left.through
726
                                            //        the formula
727
                                            $cellReferences = array_reverse($cellReferences);
728
                                            //    Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
729
                                            //        then modify the formula to use that new reference
730
                                            foreach ($cellReferences as $cellReference) {
731
                                                $rowReference = $cellReference[2][0];
732
                                                //    Empty R reference is the current row
733
                                                if ($rowReference == '') {
734
                                                    $rowReference = $rowID;
735
                                                }
736
                                                //    Bracketed R references are relative to the current row
737
                                                if ($rowReference[0] == '[') {
738
                                                    $rowReference = $rowID + trim($rowReference, '[]');
739
                                                }
740
                                                $columnReference = $cellReference[4][0];
741
                                                //    Empty C reference is the current column
742
                                                if ($columnReference == '') {
743
                                                    $columnReference = $columnNumber;
744
                                                }
745
                                                //    Bracketed C references are relative to the current column
746
                                                if ($columnReference[0] == '[') {
747
                                                    $columnReference = $columnNumber + trim($columnReference, '[]');
748
                                                }
749
                                                $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference;
750
                                                $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
751
                                            }
752
                                        }
753
                                    }
754
                                }
755
                                unset($value);
756
                                //    Then rebuild the formula string