5 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* A doc generator that outputs text-based documentation.
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PHP_CodeSniffer
|
|
|
9 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
10 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
11 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
12 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
34 |
aurelien |
13 |
* @version CVS: $Id: Text.php 34 2009-04-09 07:34:39Z aurelien $
|
5 |
aurelien |
14 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
require_once 'PHP/CodeSniffer/DocGenerators/Generator.php';
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* A doc generator that outputs text-based documentation.
|
|
|
21 |
*
|
|
|
22 |
* Output is designed to be displayed in a terminal and is wrapped to 100 characters.
|
|
|
23 |
*
|
|
|
24 |
* @category PHP
|
|
|
25 |
* @package PHP_CodeSniffer
|
|
|
26 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
27 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
28 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
29 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
30 |
* @version Release: 1.2.0RC1
|
|
|
31 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
32 |
*/
|
|
|
33 |
class PHP_CodeSniffer_DocGenerators_Text extends PHP_CodeSniffer_DocGenerators_Generator
|
|
|
34 |
{
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Process the documentation for a single sniff.
|
|
|
39 |
*
|
|
|
40 |
* @param DOMNode $doc The DOMNode object for the sniff.
|
|
|
41 |
* It represents the "documentation" tag in the XML
|
|
|
42 |
* standard file.
|
|
|
43 |
*
|
|
|
44 |
* @return void
|
|
|
45 |
*/
|
|
|
46 |
public function processSniff(DOMNode $doc)
|
|
|
47 |
{
|
|
|
48 |
$this->printTitle($doc);
|
|
|
49 |
|
|
|
50 |
foreach ($doc->childNodes as $node) {
|
|
|
51 |
if ($node->nodeName === 'standard') {
|
|
|
52 |
$this->printTextBlock($node);
|
|
|
53 |
} else if ($node->nodeName === 'code_comparison') {
|
|
|
54 |
$this->printCodeComparisonBlock($node);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
}//end processSniff()
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Prints the title area for a single sniff.
|
|
|
63 |
*
|
|
|
64 |
* @param DOMNode $doc The DOMNode object for the sniff.
|
|
|
65 |
* It represents the "documentation" tag in the XML
|
|
|
66 |
* standard file.
|
|
|
67 |
*
|
|
|
68 |
* @return void
|
|
|
69 |
*/
|
|
|
70 |
protected function printTitle(DOMNode $doc)
|
|
|
71 |
{
|
|
|
72 |
$title = $this->getTitle($doc);
|
|
|
73 |
$standard = $this->getStandard();
|
|
|
74 |
|
|
|
75 |
echo PHP_EOL;
|
|
|
76 |
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
|
|
77 |
echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL);
|
|
|
78 |
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
|
|
79 |
echo PHP_EOL.PHP_EOL;
|
|
|
80 |
|
|
|
81 |
}//end printTitle()
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Print a text block found in a standard.
|
|
|
86 |
*
|
|
|
87 |
* @param DOMNode $node The DOMNode object for the text block.
|
|
|
88 |
*
|
|
|
89 |
* @return void
|
|
|
90 |
*/
|
|
|
91 |
protected function printTextBlock($node)
|
|
|
92 |
{
|
|
|
93 |
$text = trim($node->nodeValue);
|
|
|
94 |
$text = str_replace('<em>', '*', $text);
|
|
|
95 |
$text = str_replace('</em>', '*', $text);
|
|
|
96 |
|
|
|
97 |
$lines = array();
|
|
|
98 |
$tempLine = '';
|
|
|
99 |
$words = explode(' ', $text);
|
|
|
100 |
|
|
|
101 |
foreach ($words as $word) {
|
|
|
102 |
if (strlen($tempLine.$word) >= 99) {
|
|
|
103 |
if (strlen($tempLine.$word) === 99) {
|
|
|
104 |
// Adding the extra space will push us to the edge
|
|
|
105 |
// so we are done.
|
|
|
106 |
$lines[] = $tempLine.$word;
|
|
|
107 |
$tempLine = '';
|
|
|
108 |
} else if (strlen($tempLine.$word) === 100) {
|
|
|
109 |
// We are already at the edge, so we are done.
|
|
|
110 |
$lines[] = $tempLine.$word;
|
|
|
111 |
$tempLine = '';
|
|
|
112 |
} else {
|
|
|
113 |
$lines[] = rtrim($tempLine);
|
|
|
114 |
$tempLine = $word.' ';
|
|
|
115 |
}
|
|
|
116 |
} else {
|
|
|
117 |
$tempLine .= $word.' ';
|
|
|
118 |
}
|
|
|
119 |
}//end foreach
|
|
|
120 |
|
|
|
121 |
if ($tempLine !== '') {
|
|
|
122 |
$lines[] = rtrim($tempLine);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;
|
|
|
126 |
|
|
|
127 |
}//end printTextBlock()
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* Print a code comparison block found in a standard.
|
|
|
132 |
*
|
|
|
133 |
* @param DOMNode $node The DOMNode object for the code comparison block.
|
|
|
134 |
*
|
|
|
135 |
* @return void
|
|
|
136 |
*/
|
|
|
137 |
protected function printCodeComparisonBlock($node)
|
|
|
138 |
{
|
|
|
139 |
$codeBlocks = $node->getElementsByTagName('code');
|
|
|
140 |
$first = trim($codeBlocks->item(0)->nodeValue);
|
|
|
141 |
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
|
|
142 |
|
|
|
143 |
$firstTitleLines = array();
|
|
|
144 |
$tempTitle = '';
|
|
|
145 |
$words = explode(' ', $firstTitle);
|
|
|
146 |
|
|
|
147 |
foreach ($words as $word) {
|
|
|
148 |
if (strlen($tempTitle.$word) >= 45) {
|
|
|
149 |
if (strlen($tempTitle.$word) === 45) {
|
|
|
150 |
// Adding the extra space will push us to the edge
|
|
|
151 |
// so we are done.
|
|
|
152 |
$firstTitleLines[] = $tempTitle.$word;
|
|
|
153 |
$tempTitle = '';
|
|
|
154 |
} else if (strlen($tempTitle.$word) === 46) {
|
|
|
155 |
// We are already at the edge, so we are done.
|
|
|
156 |
$firstTitleLines[] = $tempTitle.$word;
|
|
|
157 |
$tempTitle = '';
|
|
|
158 |
} else {
|
|
|
159 |
$firstTitleLines[] = $tempTitle;
|
|
|
160 |
$tempTitle = $word;
|
|
|
161 |
}
|
|
|
162 |
} else {
|
|
|
163 |
$tempTitle .= $word.' ';
|
|
|
164 |
}
|
|
|
165 |
}//end foreach
|
|
|
166 |
|
|
|
167 |
if ($tempTitle !== '') {
|
|
|
168 |
$firstTitleLines[] = $tempTitle;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
$first = str_replace('<em>', '', $first);
|
|
|
172 |
$first = str_replace('</em>', '', $first);
|
|
|
173 |
$firstLines = explode("\n", $first);
|
|
|
174 |
|
|
|
175 |
$second = trim($codeBlocks->item(1)->nodeValue);
|
|
|
176 |
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
|
|
177 |
|
|
|
178 |
$secondTitleLines = array();
|
|
|
179 |
$tempTitle = '';
|
|
|
180 |
$words = explode(' ', $secondTitle);
|
|
|
181 |
|
|
|
182 |
foreach ($words as $word) {
|
|
|
183 |
if (strlen($tempTitle.$word) >= 45) {
|
|
|
184 |
if (strlen($tempTitle.$word) === 45) {
|
|
|
185 |
// Adding the extra space will push us to the edge
|
|
|
186 |
// so we are done.
|
|
|
187 |
$secondTitleLines[] = $tempTitle.$word;
|
|
|
188 |
$tempTitle = '';
|
|
|
189 |
} else if (strlen($tempTitle.$word) === 46) {
|
|
|
190 |
// We are already at the edge, so we are done.
|
|
|
191 |
$secondTitleLines[] = $tempTitle.$word;
|
|
|
192 |
$tempTitle = '';
|
|
|
193 |
} else {
|
|
|
194 |
$secondTitleLines[] = $tempTitle;
|
|
|
195 |
$tempTitle = $word;
|
|
|
196 |
}
|
|
|
197 |
} else {
|
|
|
198 |
$tempTitle .= $word.' ';
|
|
|
199 |
}
|
|
|
200 |
}//end foreach
|
|
|
201 |
|
|
|
202 |
if ($tempTitle !== '') {
|
|
|
203 |
$secondTitleLines[] = $tempTitle;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
$second = str_replace('<em>', '', $second);
|
|
|
207 |
$second = str_replace('</em>', '', $second);
|
|
|
208 |
$secondLines = explode("\n", $second);
|
|
|
209 |
|
|
|
210 |
$maxCodeLines = max(count($firstLines), count($secondLines));
|
|
|
211 |
$maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
|
|
|
212 |
|
|
|
213 |
echo str_repeat('-', 41);
|
|
|
214 |
echo ' CODE COMPARISON ';
|
|
|
215 |
echo str_repeat('-', 42).PHP_EOL;
|
|
|
216 |
|
|
|
217 |
for ($i = 0; $i < $maxTitleLines; $i++) {
|
|
|
218 |
if (isset($firstTitleLines[$i]) === true) {
|
|
|
219 |
$firstLineText = $firstTitleLines[$i];
|
|
|
220 |
} else {
|
|
|
221 |
$firstLineText = '';
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
if (isset($secondTitleLines[$i]) === true) {
|
|
|
225 |
$secondLineText = $secondTitleLines[$i];
|
|
|
226 |
} else {
|
|
|
227 |
$secondLineText = '';
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
echo '| ';
|
|
|
231 |
echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
|
|
|
232 |
echo ' | ';
|
|
|
233 |
echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
|
|
|
234 |
echo ' |'.PHP_EOL;
|
|
|
235 |
}//end for
|
|
|
236 |
|
|
|
237 |
echo str_repeat('-', 100).PHP_EOL;
|
|
|
238 |
|
|
|
239 |
for ($i = 0; $i < $maxCodeLines; $i++) {
|
|
|
240 |
if (isset($firstLines[$i]) === true) {
|
|
|
241 |
$firstLineText = $firstLines[$i];
|
|
|
242 |
} else {
|
|
|
243 |
$firstLineText = '';
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
if (isset($secondLines[$i]) === true) {
|
|
|
247 |
$secondLineText = $secondLines[$i];
|
|
|
248 |
} else {
|
|
|
249 |
$secondLineText = '';
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
echo '| ';
|
|
|
253 |
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
|
|
|
254 |
echo '| ';
|
|
|
255 |
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
|
|
|
256 |
echo '|'.PHP_EOL;
|
|
|
257 |
}//end for
|
|
|
258 |
|
|
|
259 |
echo str_repeat('-', 100).PHP_EOL.PHP_EOL;
|
|
|
260 |
|
|
|
261 |
}//end printCodeComparisonBlock()
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
}//end class
|
|
|
265 |
|
|
|
266 |
?>
|