Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fix reflection for one line docblocks #7299

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion library/Zend/Code/Reflection/DocBlockReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected function reflect()
return;
}

$docComment = $this->docComment; // localize variable
$docComment = preg_replace('#[ ]{0,1}\*/$#', '', $this->docComment);

// create a clean docComment
$this->cleanDocComment = preg_replace("#[ \t]*(?:/\*\*|\*/|\*)[ ]{0,1}(.*)?#", '$1', $docComment);
Expand Down
16 changes: 14 additions & 2 deletions tests/ZendTest/Code/Reflection/DocBlockReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public function testDocBlockTags()
$this->assertEquals('mixed', $returnTag->getType());
}

public function testShortDocBlocks()
{
$classReflection = new ClassReflection('ZendTest\Code\Reflection\TestAsset\TestSampleClass13');
$this->assertEquals(0, count($classReflection->getDocBlock()->getTags()));

$this->assertSame('Short Method Description', $classReflection->getMethod('doSomething')->getDocBlock()->getShortDescription());
$this->assertSame('Short Class Description', $classReflection->getDocBlock()->getShortDescription());

$returnTag = $classReflection->getMethod('returnSomething')->getDocBlock()->getTag('return');
$this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\TagInterface', $returnTag);
$this->assertEquals('Something', $returnTag->getType());
$this->assertEquals('This describes something', $returnTag->getDescription());
}

public function testTabbedDocBlockTags()
{
$classReflection = new ClassReflection('ZendTest\Code\Reflection\TestAsset\TestSampleClass10');
Expand All @@ -85,8 +99,6 @@ public function testTabbedDocBlockTags()

public function testDocBlockLines()
{
//$this->markTestIncomplete('Line numbers incomplete');

$classReflection = new ClassReflection('ZendTest\Code\Reflection\TestAsset\TestSampleClass5');

$classDocBlock = $classReflection->getDocBlock();
Expand Down
15 changes: 15 additions & 0 deletions tests/ZendTest/Code/Reflection/TestAsset/TestSampleClass13.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ZendTest\Code\Reflection\TestAsset;

/** Short Class Description */
class TestSampleClass13
{
/** Short Method Description */
public function doSomething()
{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put each curly braces on one line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it makes more sense to omit this class from our php_cs rules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that path is already excluded from our php-cs-fixer ruleset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This asset is actually supposed to have this particular structure to trigger a failure


/** @return Something This describes something */
public function returnSomething()
{}
}