File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ $rendererOptions = [
92
92
// internally, ops (tags) are all int type but this is not good for human reading.
93
93
// set this to "true" to convert them into string form before outputting.
94
94
'outputTagAsString' => true,
95
- // change this value to a non-null one as the the returned diff
95
+ // change this value to a string as the the returned diff
96
96
// if the two input strings are identical
97
97
'resultForIdenticals' => null,
98
98
// extra HTML classes added to the DOM of the diff container
Original file line number Diff line number Diff line change 48
48
// internally, ops (tags) are all int type but this is not good for human reading.
49
49
// set this to "true" to convert them into string form before outputting.
50
50
'outputTagAsString ' => false ,
51
- // change this value to a non-null one as the the returned diff
51
+ // change this value to a string as the the returned diff
52
52
// if the two input strings are identical
53
53
'resultForIdenticals ' => null ,
54
54
// extra HTML classes added to the DOM of the diff container
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ abstract class AbstractRenderer implements RendererInterface
49
49
// internally, ops (tags) are all int type but this is not good for human reading.
50
50
// set this to "true" to convert them into string form before outputting.
51
51
'outputTagAsString ' => false ,
52
- // change this value to a non-null one as the the returned diff
52
+ // change this value to a string as the the returned diff
53
53
// if the two input strings are identical
54
54
'resultForIdenticals ' => null ,
55
55
// extra HTML classes added to the DOM of the diff container
@@ -111,10 +111,20 @@ public function getOptions(): array
111
111
* @final
112
112
*
113
113
* @todo mark this method with "final" in the next major release
114
+ *
115
+ * @throws \InvalidArgumentException
114
116
*/
115
117
public function getResultForIdenticals (): string
116
118
{
117
- return $ this ->options ['resultForIdenticals ' ] ?? $ this ->getResultForIdenticalsDefault ();
119
+ $ custom = $ this ->options ['resultForIdenticals ' ];
120
+
121
+ if (isset ($ custom ) && !\is_string ($ custom )) {
122
+ throw new \InvalidArgumentException (
123
+ 'renderer option `resultForIdenticals` must be null or string. '
124
+ );
125
+ }
126
+
127
+ return $ custom ?? $ this ->getResultForIdenticalsDefault ();
118
128
}
119
129
120
130
/**
Original file line number Diff line number Diff line change @@ -68,4 +68,22 @@ public function testSetOptionsWithResultForIdenticals(): void
68
68
'Rederer options: result for identicals should work. '
69
69
);
70
70
}
71
+
72
+ /**
73
+ * Test the AbstractRenderer::setOptions with an invalid result for identicals.
74
+ *
75
+ * @covers \Jfcherng\Diff\Renderer\AbstractRenderer::setOptions
76
+ */
77
+ public function testSetOptionsWithInvalidResultForIdenticals (): void
78
+ {
79
+ static ::expectException (\InvalidArgumentException::class);
80
+
81
+ $ diffResult = DiffHelper::calculate (
82
+ 'we are the same ' ,
83
+ 'we are the same ' ,
84
+ 'Inline ' ,
85
+ [],
86
+ ['resultForIdenticals ' => 50 ]
87
+ );
88
+ }
71
89
}
You can’t perform that action at this time.
0 commit comments