@@ -22,16 +22,6 @@ final class Context extends AbstractText
2222 'type ' => 'Text ' ,
2323 ];
2424
25- /**
26- * @var string[] array of the different opcodes and their context diff equivalents
27- */
28- const TAG_MAP = [
29- SequenceMatcher::OP_DEL => '- ' ,
30- SequenceMatcher::OP_EQ => ' ' ,
31- SequenceMatcher::OP_INS => '+ ' ,
32- SequenceMatcher::OP_REP => '! ' ,
33- ];
34-
3525 /**
3626 * {@inheritdoc}
3727 */
@@ -94,7 +84,7 @@ protected function renderHunkOld(Differ $differ, array $hunk): string
9484 $ hasChangeInHunk = true ;
9585 }
9686
97- $ ret .= $ this ->renderContext (self :: TAG_MAP [ $ op] , $ differ , self ::OLD_AS_SOURCE , $ i1 , $ i2 );
87+ $ ret .= $ this ->renderContext ($ op , $ differ , self ::OLD_AS_SOURCE , $ i1 , $ i2 );
9888 }
9989
10090 return $ hasChangeInHunk ? $ ret : '' ;
@@ -120,7 +110,7 @@ protected function renderHunkNew(Differ $differ, array $hunk): string
120110 $ hasChangeInHunk = true ;
121111 }
122112
123- $ ret .= $ this ->renderContext (self :: TAG_MAP [ $ op] , $ differ , self ::NEW_AS_SOURCE , $ j1 , $ j2 );
113+ $ ret .= $ this ->renderContext ($ op , $ differ , self ::NEW_AS_SOURCE , $ j1 , $ j2 );
124114 }
125115
126116 return $ hasChangeInHunk ? $ ret : '' ;
@@ -129,14 +119,21 @@ protected function renderHunkNew(Differ $differ, array $hunk): string
129119 /**
130120 * Render the context array with the symbol.
131121 *
132- * @param string $symbol the symbol
122+ * @param int $op the operation
133123 * @param Differ $differ the differ
134124 * @param int $source the source type
135125 * @param int $a1 the begin index
136126 * @param int $a2 the end index
137127 */
138- protected function renderContext (string $ symbol , Differ $ differ , int $ source , int $ a1 , int $ a2 ): string
128+ protected function renderContext (int $ op , Differ $ differ , int $ source , int $ a1 , int $ a2 ): string
139129 {
130+ static $ opToSymbol = [
131+ SequenceMatcher::OP_DEL => '- ' ,
132+ SequenceMatcher::OP_EQ => ' ' ,
133+ SequenceMatcher::OP_INS => '+ ' ,
134+ SequenceMatcher::OP_REP => '! ' ,
135+ ];
136+
140137 $ context = $ source === self ::OLD_AS_SOURCE
141138 ? $ differ ->getOld ($ a1 , $ a2 )
142139 : $ differ ->getNew ($ a1 , $ a2 );
@@ -145,7 +142,7 @@ protected function renderContext(string $symbol, Differ $differ, int $source, in
145142 return '' ;
146143 }
147144
148- $ ret = "{$ symbol } " . \implode ("\n{$ symbol } " , $ context ) . "\n" ;
145+ $ ret = "{$ opToSymbol [ $ op ] } " . \implode ("\n{$ opToSymbol [ $ op ] } " , $ context ) . "\n" ;
149146
150147 if (
151148 ($ source === self ::OLD_AS_SOURCE && $ a2 === $ differ ->getOldNoEolAtEofIdx ()) ||
0 commit comments