Skip to content

Commit 5874060

Browse files
committed
Added reflection for @source tag.
1 parent aed654a commit 5874060

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* phpDocumentor
4+
*
5+
* PHP Version 5.3
6+
*
7+
* @author Vasil Rangelov <[email protected]>
8+
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock\Tag;
14+
15+
use phpDocumentor\Reflection\DocBlock\Tag;
16+
17+
/**
18+
* Reflection class for a @source tag in a Docblock.
19+
*
20+
* @author Vasil Rangelov <[email protected]>
21+
* @license http://www.opensource.org/licenses/mit-license.php MIT
22+
* @link http://phpdoc.org
23+
*/
24+
class SourceTag extends Tag
25+
{
26+
/**
27+
* @var int The starting line, relative to the structural element's
28+
* location.
29+
*/
30+
protected $startingLine = 1;
31+
32+
/**
33+
* @var int|null The number of lines, relative to the starting line. NULL
34+
* means "to the end".
35+
*/
36+
protected $lineCount = null;
37+
38+
/**
39+
* Parses a tag and populates the member variables.
40+
*
41+
* @param string $type Tag identifier for this tag (should be 'source').
42+
* @param string $content Contents for this tag.
43+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
44+
*/
45+
public function __construct($type, $content, DocBlock $docblock = null)
46+
{
47+
parent::__construct($type, $content, $docblock);
48+
$content = preg_split('/[\ \t]+/u', $this->description, 2);
49+
if (preg_match(
50+
'/^([1-9]\d*)\s*(?:([1-9]\d*)\s+)?(.*)$/su',
51+
$this->description,
52+
$matches
53+
)) {
54+
$this->startingLine = (int)$matches[1];
55+
if (isset($matches[2]) && '' !== $matches[2]) {
56+
$this->lineCount = (int)$matches[2];
57+
}
58+
$this->description = $matches[3];
59+
}
60+
}
61+
62+
/**
63+
* Returns the starting line.
64+
*
65+
* @return int The starting line, relative to the structural element's
66+
* location.
67+
*/
68+
public function getStartingLine()
69+
{
70+
return $this->startingLine;
71+
}
72+
73+
/**
74+
* Returns the number of lines.
75+
*
76+
* @return int|null The number of lines, relative to the starting line. NULL
77+
* means "to the end".
78+
*/
79+
public function getLineCount()
80+
{
81+
return $this->lineCount;
82+
}
83+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* phpDocumentor Source Tag Test
4+
*
5+
* PHP version 5.3
6+
*
7+
* @author Vasil Rangelov <[email protected]>
8+
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock\Tag;
14+
15+
/**
16+
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
17+
*
18+
* @author Vasil Rangelov <[email protected]>
19+
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
20+
* @license http://www.opensource.org/licenses/mit-license.php MIT
21+
* @link http://phpdoc.org
22+
*/
23+
class SourceTagTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\SourceTag can
27+
* understand the @source DocBlock.
28+
*
29+
* @param string $type
30+
* @param string $content
31+
* @param string $exContent
32+
* @param string $exStartingLine
33+
* @param string $exLineCount
34+
*
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::__construct
36+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::getStartingLine
37+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::getLineCount
38+
* @dataProvider provideDataForConstuctor
39+
*
40+
* @return void
41+
*/
42+
public function testConstructorParesInputsIntoCorrectFields(
43+
$type,
44+
$content,
45+
$exContent,
46+
$exDescription,
47+
$exStartingLine,
48+
$exLineCount
49+
) {
50+
$tag = new SourceTag($type, $content);
51+
52+
$this->assertEquals($type, $tag->getName());
53+
$this->assertEquals($exContent, $tag->getContent());
54+
$this->assertEquals($exDescription, $tag->getDescription());
55+
$this->assertEquals($exStartingLine, $tag->getStartingLine());
56+
$this->assertEquals($exLineCount, $tag->getLineCount());
57+
}
58+
59+
/**
60+
* Data provider for testConstructorParesInputsIntoCorrectFields
61+
*
62+
* @return array
63+
*/
64+
public function provideDataForConstuctor()
65+
{
66+
// $type, $content, $exContent, $exDescription, $exStartingLine, $exLineCount
67+
return array(
68+
array(
69+
'source',
70+
'2',
71+
'2',
72+
'',
73+
2,
74+
null
75+
),
76+
array(
77+
'source',
78+
'Testing',
79+
'Testing',
80+
'Testing',
81+
1,
82+
null
83+
),
84+
array(
85+
'source',
86+
'2 Testing',
87+
'2 Testing',
88+
'Testing',
89+
2,
90+
null
91+
),
92+
array(
93+
'source',
94+
'2 3 Testing comments',
95+
'2 3 Testing comments',
96+
'Testing comments',
97+
2,
98+
3
99+
),
100+
array(
101+
'source',
102+
'2 -1 Testing comments',
103+
'2 -1 Testing comments',
104+
'-1 Testing comments',
105+
2,
106+
null
107+
),
108+
array(
109+
'source',
110+
'-1 1 Testing comments',
111+
'-1 1 Testing comments',
112+
'-1 1 Testing comments',
113+
1,
114+
null
115+
),
116+
);
117+
}
118+
}

0 commit comments

Comments
 (0)