Skip to content

Remove line breaks from docblocks #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ function export_docblock( $element ) {
}

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

foreach ( $docblock->getTags() as $tag ) {
$t = array(
'name' => $tag->getName(),
'content' => $tag->getDescription(),
'content' => preg_replace( '/[\n\r]+/', ' ', $tag->getDescription() ),
);
if ( method_exists( $tag, 'getTypes' ) ) {
$t['types'] = $tag->getTypes();
Expand Down
64 changes: 64 additions & 0 deletions tests/phpunit/tests/export/docblocks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* This is the file-level docblock summary.
*
* This is the file-level docblock description, which may span multiple lines. In
* fact, this one does. It spans more than two full lines, continuing on to the
* third line.
*
* @since 1.5.0
*/

/**
* This is a function docblock.
*
* This function is just a test, but we've added this description anyway.
*
* @since 2.6.0
*
* @param string $var A string value.
* @param int $num A number.
*
* @return bool Whether the function was called correctly.
*/
function test_func( $var, $num ) {

// In real life, there *might* be more stuff in here.
return true;
}

/**
* This is a class docblock.
*
* This is the more wordy description: This is a comment with two *'s at the start,
* which means that it is a doc comment. Docblock comments are comment blocks used
* to document code. This one documents the Test_Class class.
*
* @since 3.5.2
*/
class Test_Class {

/**
* This is a docblock for a class property.
*
* @since 3.0.0
*
* @var string
*/
public $a_string;

/**
* This is a method docblock.
*
* @since 4.5.0
*
* @param mixed $var A parameter.
* @param array $arr Another parameter.
*
* @return mixed The first param.
*/
public function test_method( $var, $arr ) {
return $var;
}
}
24 changes: 24 additions & 0 deletions tests/phpunit/tests/export/docblocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* A test case for exporting docblocks.
*/

namespace WP_Parser\Tests;
include( '/Users/johngrimes/plugins/jds-dev-tools.php' );// TODO
/**
* Test that docblocks are exported correctly.
*/
class Export_Docblocks extends Export_UnitTestCase {

/**
* Test that line breaks are removed when the description is exported.
*/
public function test_linebreaks_removed() {

$this->assertStringMatchesFormat(
'%s'
, $this->export_data['classes'][0]['doc']['long_description']
);
}
}