Skip to content

Commit aed654a

Browse files
committed
Merge pull request #11 from boenrobot/version-and-derivatives
Reflections for @Version, @SInCE and @deprecated
2 parents 2812eac + 8eb596c commit aed654a

File tree

7 files changed

+481
-1
lines changed

7 files changed

+481
-1
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Tag implements \Reflector
5151
=> '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
5252
'covers'
5353
=> '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
54+
'deprecated'
55+
=> '\phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag',
5456
'link'
5557
=> '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
5658
'method'
@@ -67,14 +69,18 @@ class Tag implements \Reflector
6769
=> '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
6870
'see'
6971
=> '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
72+
'since'
73+
=> '\phpDocumentor\Reflection\DocBlock\Tag\SinceTag',
7074
'throw'
7175
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
7276
'throws'
7377
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
7478
'uses'
7579
=> '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
7680
'var'
77-
=> '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
81+
=> '\phpDocumentor\Reflection\DocBlock\Tag\VarTag',
82+
'version'
83+
=> '\phpDocumentor\Reflection\DocBlock\Tag\VersionTag'
7884
);
7985

8086
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\VersionTag;
16+
17+
/**
18+
* Reflection class for a @deprecated 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 DeprecatedTag extends VersionTag
25+
{
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\VersionTag;
16+
17+
/**
18+
* Reflection class for a @since 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 SinceTag extends VersionTag
25+
{
26+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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;
16+
use phpDocumentor\Reflection\DocBlock\Tag;
17+
18+
/**
19+
* Reflection class for a @version tag in a Docblock.
20+
*
21+
* @author Vasil Rangelov <[email protected]>
22+
* @license http://www.opensource.org/licenses/mit-license.php MIT
23+
* @link http://phpdoc.org
24+
*/
25+
class VersionTag extends Tag
26+
{
27+
/** @var string The version vector. */
28+
protected $version = '';
29+
30+
/**
31+
* Parses a tag and populates the member variables.
32+
*
33+
* @param string $type Tag identifier for this tag (should be 'version').
34+
* @param string $content Contents for this tag.
35+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
36+
*/
37+
public function __construct($type, $content, DocBlock $docblock = null)
38+
{
39+
parent::__construct($type, $content, $docblock);
40+
41+
if (preg_match(
42+
'/^
43+
# The version vector
44+
((?:
45+
# Normal release vectors.
46+
\d\S*
47+
|
48+
# VCS version vectors. Per PHPCS, they are expected to
49+
# follow the form of the VCS name, followed by ":", followed
50+
# by the version vector itself.
51+
# By convention, popular VCSes like CVS, SVN and GIT use "$"
52+
# around the actual version vector.
53+
[^\s\:]+\:\s*\$[^\$]+\$
54+
))
55+
\s*
56+
# The description
57+
(.+)?
58+
$/sux',
59+
$this->description,
60+
$matches
61+
)) {
62+
$this->version = $matches[1];
63+
$this->description = isset($matches[2]) ? $matches[2] : '';
64+
}
65+
}
66+
67+
/**
68+
* Returns the version section of the tag.
69+
*
70+
* @return string The version section of the tag.
71+
*/
72+
public function getVersion()
73+
{
74+
return $this->version;
75+
}
76+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* phpDocumentor Deprecated 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\DeprecatedTag
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 DeprecatedTagTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
27+
* a link for the @deprecated doc block.
28+
*
29+
* @param string $type
30+
* @param string $content
31+
* @param string $exContent
32+
* @param string $exDescription
33+
* @param string $exVersion
34+
*
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag
36+
* @dataProvider provideDataForConstuctor
37+
*
38+
* @return void
39+
*/
40+
public function testConstructorParesInputsIntoCorrectFields(
41+
$type,
42+
$content,
43+
$exContent,
44+
$exDescription,
45+
$exVersion
46+
) {
47+
$tag = new DeprecatedTag($type, $content);
48+
49+
$this->assertEquals($type, $tag->getName());
50+
$this->assertEquals($exContent, $tag->getContent());
51+
$this->assertEquals($exDescription, $tag->getDescription());
52+
$this->assertEquals($exVersion, $tag->getVersion());
53+
}
54+
55+
/**
56+
* Data provider for testConstructorParesInputsIntoCorrectFields
57+
*
58+
* @return array
59+
*/
60+
public function provideDataForConstuctor()
61+
{
62+
// $type, $content, $exContent, $exDescription, $exVersion
63+
return array(
64+
array(
65+
'deprecated',
66+
'1.0 First release.',
67+
'1.0 First release.',
68+
'First release.',
69+
'1.0'
70+
),
71+
array(
72+
'deprecated',
73+
"1.0\nFirst release.",
74+
"1.0\nFirst release.",
75+
'First release.',
76+
'1.0'
77+
),
78+
array(
79+
'deprecated',
80+
"1.0\nFirst\nrelease.",
81+
"1.0\nFirst\nrelease.",
82+
"First\nrelease.",
83+
'1.0'
84+
),
85+
array(
86+
'deprecated',
87+
'Unfinished release',
88+
'Unfinished release',
89+
'Unfinished release',
90+
''
91+
),
92+
array(
93+
'deprecated',
94+
'1.0',
95+
'1.0',
96+
'',
97+
'1.0'
98+
),
99+
array(
100+
'deprecated',
101+
'GIT: $Id$',
102+
'GIT: $Id$',
103+
'',
104+
'GIT: $Id$'
105+
),
106+
array(
107+
'deprecated',
108+
'GIT: $Id$ Dev build',
109+
'GIT: $Id$ Dev build',
110+
'Dev build',
111+
'GIT: $Id$'
112+
)
113+
);
114+
}
115+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* phpDocumentor Since 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\SinceTag
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 SinceTagTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
27+
* a link for the @since doc block.
28+
*
29+
* @param string $type
30+
* @param string $content
31+
* @param string $exContent
32+
* @param string $exDescription
33+
* @param string $exVersion
34+
*
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SinceTag
36+
* @dataProvider provideDataForConstuctor
37+
*
38+
* @return void
39+
*/
40+
public function testConstructorParesInputsIntoCorrectFields(
41+
$type,
42+
$content,
43+
$exContent,
44+
$exDescription,
45+
$exVersion
46+
) {
47+
$tag = new SinceTag($type, $content);
48+
49+
$this->assertEquals($type, $tag->getName());
50+
$this->assertEquals($exContent, $tag->getContent());
51+
$this->assertEquals($exDescription, $tag->getDescription());
52+
$this->assertEquals($exVersion, $tag->getVersion());
53+
}
54+
55+
/**
56+
* Data provider for testConstructorParesInputsIntoCorrectFields
57+
*
58+
* @return array
59+
*/
60+
public function provideDataForConstuctor()
61+
{
62+
// $type, $content, $exContent, $exDescription, $exVersion
63+
return array(
64+
array(
65+
'since',
66+
'1.0 First release.',
67+
'1.0 First release.',
68+
'First release.',
69+
'1.0'
70+
),
71+
array(
72+
'since',
73+
"1.0\nFirst release.",
74+
"1.0\nFirst release.",
75+
'First release.',
76+
'1.0'
77+
),
78+
array(
79+
'since',
80+
"1.0\nFirst\nrelease.",
81+
"1.0\nFirst\nrelease.",
82+
"First\nrelease.",
83+
'1.0'
84+
),
85+
array(
86+
'since',
87+
'Unfinished release',
88+
'Unfinished release',
89+
'Unfinished release',
90+
''
91+
),
92+
array(
93+
'since',
94+
'1.0',
95+
'1.0',
96+
'',
97+
'1.0'
98+
),
99+
array(
100+
'since',
101+
'GIT: $Id$',
102+
'GIT: $Id$',
103+
'',
104+
'GIT: $Id$'
105+
),
106+
array(
107+
'since',
108+
'GIT: $Id$ Dev build',
109+
'GIT: $Id$ Dev build',
110+
'Dev build',
111+
'GIT: $Id$'
112+
)
113+
);
114+
}
115+
}

0 commit comments

Comments
 (0)