Skip to content

Commit 155df34

Browse files
committed
Merge pull request #123 from JDGrimes/issue-114
Remove line breaks from docblocks
2 parents 15b11f5 + d580584 commit 155df34

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

lib/runner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ function export_docblock( $element ) {
120120
}
121121

122122
$output = array(
123-
'description' => $docblock->getShortDescription(),
124-
'long_description' => $docblock->getLongDescription()->getFormattedContents(),
123+
'description' => preg_replace( '/[\n\r]+/', ' ', $docblock->getShortDescription() ),
124+
'long_description' => preg_replace( '/[\n\r]+/', ' ', $docblock->getLongDescription()->getFormattedContents() ),
125125
'tags' => array(),
126126
);
127127

128128
foreach ( $docblock->getTags() as $tag ) {
129129
$t = array(
130130
'name' => $tag->getName(),
131-
'content' => $tag->getDescription(),
131+
'content' => preg_replace( '/[\n\r]+/', ' ', $tag->getDescription() ),
132132
);
133133
if ( method_exists( $tag, 'getTypes' ) ) {
134134
$t['types'] = $tag->getTypes();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* This is the file-level docblock summary.
5+
*
6+
* This is the file-level docblock description, which may span multiple lines. In
7+
* fact, this one does. It spans more than two full lines, continuing on to the
8+
* third line.
9+
*
10+
* @since 1.5.0
11+
*/
12+
13+
/**
14+
* This is a function docblock.
15+
*
16+
* This function is just a test, but we've added this description anyway.
17+
*
18+
* @since 2.6.0
19+
*
20+
* @param string $var A string value.
21+
* @param int $num A number.
22+
*
23+
* @return bool Whether the function was called correctly.
24+
*/
25+
function test_func( $var, $num ) {
26+
27+
// In real life, there *might* be more stuff in here.
28+
return true;
29+
}
30+
31+
/**
32+
* This is a class docblock.
33+
*
34+
* This is the more wordy description: This is a comment with two *'s at the start,
35+
* which means that it is a doc comment. Docblock comments are comment blocks used
36+
* to document code. This one documents the Test_Class class.
37+
*
38+
* @since 3.5.2
39+
*/
40+
class Test_Class {
41+
42+
/**
43+
* This is a docblock for a class property.
44+
*
45+
* @since 3.0.0
46+
*
47+
* @var string
48+
*/
49+
public $a_string;
50+
51+
/**
52+
* This is a method docblock.
53+
*
54+
* @since 4.5.0
55+
*
56+
* @param mixed $var A parameter.
57+
* @param array $arr Another parameter.
58+
*
59+
* @return mixed The first param.
60+
*/
61+
public function test_method( $var, $arr ) {
62+
return $var;
63+
}
64+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* A test case for exporting docblocks.
5+
*/
6+
7+
namespace WP_Parser\Tests;
8+
include( '/Users/johngrimes/plugins/jds-dev-tools.php' );// TODO
9+
/**
10+
* Test that docblocks are exported correctly.
11+
*/
12+
class Export_Docblocks extends Export_UnitTestCase {
13+
14+
/**
15+
* Test that line breaks are removed when the description is exported.
16+
*/
17+
public function test_linebreaks_removed() {
18+
19+
$this->assertStringMatchesFormat(
20+
'%s'
21+
, $this->export_data['classes'][0]['doc']['long_description']
22+
);
23+
}
24+
}

0 commit comments

Comments
 (0)