Code Duplication    Length = 34-35 lines in 2 locations

src/PhpSpreadsheet/Reader/SYLK.php 1 location

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

src/PhpSpreadsheet/Reader/Excel2003XML.php 1 location

@@ 652-685 (lines=34) @@
649
                                    //    Convert R1C1 style references to A1 style references (but only when not quoted)
650
                                    $temp = explode('"', $cellDataFormula);
651
                                    $key = false;
652
                                    foreach ($temp as &$value) {
653
                                        //    Only replace in alternate array entries (i.e. non-quoted blocks)
654
                                        if ($key = !$key) {
655
                                            preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE);
656
                                            //    Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
657
                                            //        through the formula from left to right. Reversing means that we work right to left.through
658
                                            //        the formula
659
                                            $cellReferences = array_reverse($cellReferences);
660
                                            //    Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
661
                                            //        then modify the formula to use that new reference
662
                                            foreach ($cellReferences as $cellReference) {
663
                                                $rowReference = $cellReference[2][0];
664
                                                //    Empty R reference is the current row
665
                                                if ($rowReference == '') {
666
                                                    $rowReference = $rowID;
667
                                                }
668
                                                //    Bracketed R references are relative to the current row
669
                                                if ($rowReference{0} == '[') {
670
                                                    $rowReference = $rowID + trim($rowReference, '[]');
671
                                                }
672
                                                $columnReference = $cellReference[4][0];
673
                                                //    Empty C reference is the current column
674
                                                if ($columnReference == '') {
675
                                                    $columnReference = $columnNumber;
676
                                                }
677
                                                //    Bracketed C references are relative to the current column
678
                                                if ($columnReference{0} == '[') {
679
                                                    $columnReference = $columnNumber + trim($columnReference, '[]');
680
                                                }
681
                                                $A1CellReference = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference - 1) . $rowReference;
682
                                                $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
683
                                            }
684
                                        }
685
                                    }
686
                                }
687
                                unset($value);
688
                                //    Then rebuild the formula string