@@ -30,16 +30,19 @@ class Text extends Generator
30
30
*/
31
31
public function processSniff (DOMNode $ doc )
32
32
{
33
- $ this ->printTitle ($ doc );
34
-
33
+ $ content = '' ;
35
34
foreach ($ doc ->childNodes as $ node ) {
36
35
if ($ node ->nodeName === 'standard ' ) {
37
- $ this ->printTextBlock ($ node );
36
+ $ content .= $ this ->getFormattedTextBlock ($ node );
38
37
} else if ($ node ->nodeName === 'code_comparison ' ) {
39
- $ this ->printCodeComparisonBlock ($ node );
38
+ $ content .= $ this ->getFormattedCodeComparisonBlock ($ node );
40
39
}
41
40
}
42
41
42
+ if (trim ($ content ) !== '' ) {
43
+ echo $ this ->getFormattedTitle ($ doc ), $ content ;
44
+ }
45
+
43
46
}//end processSniff()
44
47
45
48
@@ -50,32 +53,76 @@ public function processSniff(DOMNode $doc)
50
53
* It represents the "documentation" tag in the XML
51
54
* standard file.
52
55
*
56
+ * @deprecated 3.12.0 Use Text::getFormattedTitle() instead.
57
+ *
58
+ * @codeCoverageIgnore
59
+ *
53
60
* @return void
54
61
*/
55
62
protected function printTitle (DOMNode $ doc )
63
+ {
64
+ echo $ this ->getFormattedTitle ($ doc );
65
+
66
+ }//end printTitle()
67
+
68
+
69
+ /**
70
+ * Format the title area for a single sniff.
71
+ *
72
+ * @param \DOMNode $doc The DOMNode object for the sniff.
73
+ * It represents the "documentation" tag in the XML
74
+ * standard file.
75
+ *
76
+ * @since 3.12.0 Replaces the deprecated Text::printTitle() method.
77
+ *
78
+ * @return string
79
+ */
80
+ protected function getFormattedTitle (DOMNode $ doc )
56
81
{
57
82
$ title = $ this ->getTitle ($ doc );
58
83
$ standard = $ this ->ruleset ->name ;
59
84
$ displayTitle = "$ standard CODING STANDARD: $ title " ;
60
85
$ titleLength = strlen ($ displayTitle );
61
86
62
- echo PHP_EOL ;
63
- echo str_repeat ('- ' , ($ titleLength + 4 ));
64
- echo strtoupper (PHP_EOL ."| $ displayTitle | " .PHP_EOL );
65
- echo str_repeat ('- ' , ($ titleLength + 4 ));
66
- echo PHP_EOL .PHP_EOL ;
87
+ $ output = PHP_EOL ;
88
+ $ output .= str_repeat ('- ' , ($ titleLength + 4 ));
89
+ $ output .= strtoupper (PHP_EOL ."| $ displayTitle | " .PHP_EOL );
90
+ $ output .= str_repeat ('- ' , ($ titleLength + 4 ));
91
+ $ output .= PHP_EOL .PHP_EOL ;
67
92
68
- }//end printTitle()
93
+ return $ output ;
94
+
95
+ }//end getFormattedTitle()
69
96
70
97
71
98
/**
72
99
* Print a text block found in a standard.
73
100
*
74
101
* @param \DOMNode $node The DOMNode object for the text block.
75
102
*
103
+ * @deprecated 3.12.0 Use Text::getFormattedTextBlock() instead.
104
+ *
105
+ * @codeCoverageIgnore
106
+ *
76
107
* @return void
77
108
*/
78
109
protected function printTextBlock (DOMNode $ node )
110
+ {
111
+ echo $ this ->getFormattedTextBlock ($ node );
112
+
113
+ }//end printTextBlock()
114
+
115
+
116
+ /**
117
+ * Format a text block found in a standard.
118
+ *
119
+ * @param \DOMNode $node The DOMNode object for the text block.
120
+ *
121
+ * @since 3.12.0 Replaces the deprecated Text::printTextBlock() method.
122
+ *
123
+ * @return string
124
+ */
125
+ protected function getFormattedTextBlock (DOMNode $ node )
79
126
{
80
127
$ text = trim ($ node ->nodeValue );
81
128
$ text = str_replace ('<em> ' , '* ' , $ text );
@@ -117,19 +164,39 @@ protected function printTextBlock(DOMNode $node)
117
164
}
118
165
}//end foreach
119
166
120
- echo implode (PHP_EOL , $ lines ).PHP_EOL .PHP_EOL ;
167
+ return implode (PHP_EOL , $ lines ).PHP_EOL .PHP_EOL ;
121
168
122
- }//end printTextBlock ()
169
+ }//end getFormattedTextBlock ()
123
170
124
171
125
172
/**
126
173
* Print a code comparison block found in a standard.
127
174
*
128
175
* @param \DOMNode $node The DOMNode object for the code comparison block.
129
176
*
177
+ * @deprecated 3.12.0 Use Text::getFormattedCodeComparisonBlock() instead.
178
+ *
179
+ * @codeCoverageIgnore
180
+ *
130
181
* @return void
131
182
*/
132
183
protected function printCodeComparisonBlock (DOMNode $ node )
184
+ {
185
+ echo $ this ->getFormattedCodeComparisonBlock ($ node );
186
+
187
+ }//end printCodeComparisonBlock()
188
+
189
+
190
+ /**
191
+ * Format a code comparison block found in a standard.
192
+ *
193
+ * @param \DOMNode $node The DOMNode object for the code comparison block.
194
+ *
195
+ * @since 3.12.0 Replaces the deprecated Text::printCodeComparisonBlock() method.
196
+ *
197
+ * @return string
198
+ */
199
+ protected function getFormattedCodeComparisonBlock (DOMNode $ node )
133
200
{
134
201
$ codeBlocks = $ node ->getElementsByTagName ('code ' );
135
202
$ first = trim ($ codeBlocks ->item (0 )->nodeValue );
@@ -205,9 +272,9 @@ protected function printCodeComparisonBlock(DOMNode $node)
205
272
$ maxCodeLines = max (count ($ firstLines ), count ($ secondLines ));
206
273
$ maxTitleLines = max (count ($ firstTitleLines ), count ($ secondTitleLines ));
207
274
208
- echo str_repeat ('- ' , 41 );
209
- echo ' CODE COMPARISON ' ;
210
- echo str_repeat ('- ' , 42 ).PHP_EOL ;
275
+ $ output = str_repeat ('- ' , 41 );
276
+ $ output .= ' CODE COMPARISON ' ;
277
+ $ output .= str_repeat ('- ' , 42 ).PHP_EOL ;
211
278
212
279
for ($ i = 0 ; $ i < $ maxTitleLines ; $ i ++) {
213
280
if (isset ($ firstTitleLines [$ i ]) === true ) {
@@ -222,14 +289,14 @@ protected function printCodeComparisonBlock(DOMNode $node)
222
289
$ secondLineText = '' ;
223
290
}
224
291
225
- echo '| ' ;
226
- echo $ firstLineText .str_repeat (' ' , (46 - strlen ($ firstLineText )));
227
- echo ' | ' ;
228
- echo $ secondLineText .str_repeat (' ' , (47 - strlen ($ secondLineText )));
229
- echo ' | ' .PHP_EOL ;
292
+ $ output .= '| ' ;
293
+ $ output .= $ firstLineText .str_repeat (' ' , (46 - strlen ($ firstLineText )));
294
+ $ output .= ' | ' ;
295
+ $ output .= $ secondLineText .str_repeat (' ' , (47 - strlen ($ secondLineText )));
296
+ $ output .= ' | ' .PHP_EOL ;
230
297
}//end for
231
298
232
- echo str_repeat ('- ' , 100 ).PHP_EOL ;
299
+ $ output .= str_repeat ('- ' , 100 ).PHP_EOL ;
233
300
234
301
for ($ i = 0 ; $ i < $ maxCodeLines ; $ i ++) {
235
302
if (isset ($ firstLines [$ i ]) === true ) {
@@ -244,16 +311,18 @@ protected function printCodeComparisonBlock(DOMNode $node)
244
311
$ secondLineText = '' ;
245
312
}
246
313
247
- echo '| ' ;
248
- echo $ firstLineText .str_repeat (' ' , max (0 , (47 - strlen ($ firstLineText ))));
249
- echo '| ' ;
250
- echo $ secondLineText .str_repeat (' ' , max (0 , (48 - strlen ($ secondLineText ))));
251
- echo '| ' .PHP_EOL ;
314
+ $ output .= '| ' ;
315
+ $ output .= $ firstLineText .str_repeat (' ' , max (0 , (47 - strlen ($ firstLineText ))));
316
+ $ output .= '| ' ;
317
+ $ output .= $ secondLineText .str_repeat (' ' , max (0 , (48 - strlen ($ secondLineText ))));
318
+ $ output .= '| ' .PHP_EOL ;
252
319
}//end for
253
320
254
- echo str_repeat ('- ' , 100 ).PHP_EOL .PHP_EOL ;
321
+ $ output .= str_repeat ('- ' , 100 ).PHP_EOL .PHP_EOL ;
255
322
256
- }//end printCodeComparisonBlock()
323
+ return $ output ;
324
+
325
+ }//end getFormattedCodeComparisonBlock()
257
326
258
327
259
328
}//end class
0 commit comments