@@ -196,16 +196,11 @@ private function getDiffBufferElement($diff, $i, $newChunk, $buffer)
196196 */
197197 public function diffToArray ($ from , $ to , LongestCommonSubsequence $ lcs = null )
198198 {
199- preg_match_all ( ' (\r\n|\r|\n) ' , $ from , $ fromMatches );
200- preg_match_all ( ' (\r\n|\r|\n) ' , $ to , $ toMatches );
199+ $ fromMatches = $ this -> getNewLineMatches ( $ from );
200+ $ toMatches = $ this -> getNewLineMatches ( $ to );
201201
202- if (is_string ($ from )) {
203- $ from = preg_split ('(\r\n|\r|\n) ' , $ from );
204- }
205-
206- if (is_string ($ to )) {
207- $ to = preg_split ('(\r\n|\r|\n) ' , $ to );
208- }
202+ $ from = $ this ->splitStringByLines ($ from );
203+ $ to = $ this ->splitStringByLines ($ to );
209204
210205 $ start = array ();
211206 $ end = array ();
@@ -287,6 +282,31 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
287282 return $ diff ;
288283 }
289284
285+ /**
286+ * @param $string
287+ *
288+ * @return mixed
289+ */
290+ private function getNewLineMatches ($ string ) {
291+ preg_match_all ('(\r\n|\r|\n) ' , $ string , $ stringMatches );
292+ return $ stringMatches ;
293+
294+ }
295+
296+ /**
297+ * Checks if input is string, if so it will split it line-by-life.
298+ * @param $input
299+ *
300+ * @return array
301+ */
302+ private function splitStringByLines ($ input ) {
303+ if (is_string ($ input )) {
304+ return preg_split ('(\r\n|\r|\n) ' , $ input );
305+ }
306+
307+ return $ input ;
308+ }
309+
290310 /**
291311 * @param array $from
292312 * @param array $to
0 commit comments