13
13
*
14
14
* PHP version 7.2 or greater
15
15
*
16
- * @package jblond\Diff\Renderer\Text
17
- * @author Ferry Cools <[email protected] >
16
+ * @package jblond\Diff\Renderer\Text
17
+ * @author Ferry Cools <[email protected] >
18
18
* @copyright (c) 2020 Ferry Cools
19
- * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
20
- * @version 2.2.1
21
- * @link https://github.com/JBlond/php-diff
19
+ * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
20
+ * @version 2.2.1
21
+ * @link https://github.com/JBlond/php-diff
22
22
*/
23
23
class InlineCli extends MainRenderer implements SubRendererInterface
24
24
{
@@ -31,7 +31,7 @@ class InlineCli extends MainRenderer implements SubRendererInterface
31
31
/**
32
32
* InlineCli constructor.
33
33
*
34
- * @param array $options Custom defined options for the inline diff renderer.
34
+ * @param array $options Custom defined options for the inline diff renderer.
35
35
*
36
36
* @see Inline::$subOptions
37
37
*/
@@ -67,7 +67,7 @@ public function generateDiffHeader(): string
67
67
/**
68
68
* Generate a string representation of the start of a block.
69
69
*
70
- * @param array $changes Contains the op-codes about the changes between two blocks of lines.
70
+ * @param array $changes Contains the op-codes about the changes between two blocks of lines.
71
71
*
72
72
* @return string Start of the diff view.
73
73
*/
@@ -89,14 +89,17 @@ public function generateSkippedLines(): string
89
89
/**
90
90
* Generate a string representation lines without differences between the two versions.
91
91
*
92
- * @param array $changes Contains the op-codes about the changes between two blocks of lines.
92
+ * @param array $changes Contains the op-codes about the changes between two blocks of lines.
93
93
*
94
94
* @return string Text with no difference.
95
95
*/
96
96
public function generateLinesEqual (array $ changes ): string
97
97
{
98
98
$ returnValue = '' ;
99
- $ padding = str_repeat (' ' , $ this ->maxLineMarkerWidth - strlen ($ this ->options ['equalityMarkers ' ][0 ]));
99
+ $ padding = str_repeat (
100
+ ' ' ,
101
+ max ($ this ->maxLineMarkerWidth - strlen ($ this ->options ['equalityMarkers ' ][0 ]), 0 )
102
+ );
100
103
101
104
foreach ($ changes ['base ' ]['lines ' ] as $ line ) {
102
105
$ returnValue .= $ this ->options ['equalityMarkers ' ][0 ] . $ padding . '| ' . $ line . "\n" ;
@@ -108,15 +111,18 @@ public function generateLinesEqual(array $changes): string
108
111
/**
109
112
* Generate a string representation of lines that are added to the 2nd version.
110
113
*
111
- * @param array $changes Contains the op-codes about the changes between two blocks of text.
114
+ * @param array $changes Contains the op-codes about the changes between two blocks of text.
112
115
*
113
116
* @return string Added text.
114
117
*/
115
118
public function generateLinesInsert (array $ changes ): string
116
119
{
117
120
$ colorize = new CliColors ();
118
121
$ returnValue = '' ;
119
- $ padding = str_repeat (' ' , $ this ->maxLineMarkerWidth - strlen ($ this ->options ['insertMarkers ' ][0 ]));
122
+ $ padding = str_repeat (
123
+ ' ' ,
124
+ max ($ this ->maxLineMarkerWidth - strlen ($ this ->options ['insertMarkers ' ][0 ]), 0 )
125
+ );
120
126
121
127
foreach ($ changes ['changed ' ]['lines ' ] as $ line ) {
122
128
if ($ this ->options ['cliColor ' ]) {
@@ -132,15 +138,18 @@ public function generateLinesInsert(array $changes): string
132
138
/**
133
139
* Generate a string representation of lines that are removed from the 2nd version.
134
140
*
135
- * @param array $changes Contains the op-codes about the changes between two blocks of text.
141
+ * @param array $changes Contains the op-codes about the changes between two blocks of text.
136
142
*
137
143
* @return string Removed text.
138
144
*/
139
145
public function generateLinesDelete (array $ changes ): string
140
146
{
141
147
$ colorize = new CliColors ();
142
148
$ returnValue = '' ;
143
- $ padding = str_repeat (' ' , $ this ->maxLineMarkerWidth - strlen ($ this ->options ['deleteMarkers ' ][0 ]));
149
+ $ padding = str_repeat (
150
+ ' ' ,
151
+ max ($ this ->maxLineMarkerWidth - strlen ($ this ->options ['deleteMarkers ' ][0 ]), 0 )
152
+ );
144
153
145
154
foreach ($ changes ['base ' ]['lines ' ] as $ line ) {
146
155
if ($ this ->options ['cliColor ' ]) {
@@ -156,7 +165,7 @@ public function generateLinesDelete(array $changes): string
156
165
/**
157
166
* Generate a string representation of lines that are partially modified.
158
167
*
159
- * @param array $changes Contains the op-codes about the changes between two blocks of text.
168
+ * @param array $changes Contains the op-codes about the changes between two blocks of text.
160
169
*
161
170
* @return string Modified text.
162
171
*/
@@ -179,10 +188,10 @@ public function generateLinesReplace(array $changes): string
179
188
/**
180
189
* Merge the changes between two lines together and mark these changes.
181
190
*
182
- * @param array $baseLines Lines of version 1.
183
- * @param array $changedLines Lines of version 2.
184
- * @param array|null[] $deleteColors Fore- and background colors of part that is removed from the 2nd version.
185
- * @param array|null[] $insertColors Fore- and background colors of part that is added to the 2nd version.
191
+ * @param array $baseLines Lines of version 1.
192
+ * @param array $changedLines Lines of version 2.
193
+ * @param array|null[] $deleteColors Fore- and background colors of part that is removed from the 2nd version.
194
+ * @param array|null[] $insertColors Fore- and background colors of part that is added to the 2nd version.
186
195
*
187
196
* Option $deleteColors and $insertColors only have affect when this class's cliColors option is set to true.
188
197
*
@@ -194,7 +203,11 @@ private function mergeChanges(
194
203
array $ deleteColors = [null , null ],
195
204
array $ insertColors = [null , null ]
196
205
): array {
197
- $ padding = str_repeat (' ' , $ this ->maxLineMarkerWidth - strlen ($ this ->options ['equalityMarkers ' ][1 ]));
206
+ $ padding = str_repeat (
207
+ ' ' ,
208
+ max ($ this ->maxLineMarkerWidth - strlen ($ this ->options ['equalityMarkers ' ][1 ]), 0 )
209
+ );
210
+
198
211
if ($ this ->options ['cliColor ' ]) {
199
212
$ colorize = new CliColors ();
200
213
}
@@ -233,7 +246,7 @@ private function mergeChanges(
233
246
/**
234
247
* Generate a string representation of the end of a block.
235
248
*
236
- * @param array $changes Contains the op-codes about the changes between two blocks of text.
249
+ * @param array $changes Contains the op-codes about the changes between two blocks of text.
237
250
*
238
251
* @return string End of the block
239
252
*/
0 commit comments