Code Duplication    Length = 34-35 lines in 2 locations

src/PhpSpreadsheet/Reader/Xml.php 1 location

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

src/PhpSpreadsheet/Reader/Slk.php 1 location

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