Code Duplication    Length = 34-35 lines in 2 locations

src/PhpSpreadsheet/Reader/SYLK.php 1 location

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

src/PhpSpreadsheet/Reader/Excel2003XML.php 1 location

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