Skip to content

Commit 9090765

Browse files
committed
Deprecated getPropertyType in favor of getPropertyClass, and getParameterType in favor of getParameterClass
1 parent 12e9ec0 commit 9090765

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

src/PhpDocReader/PhpDocReader.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,29 @@ public function __construct()
3838
}
3939

4040
/**
41-
* Parse the docblock of the property to get the var annotation.
41+
* Parse the docblock of the property to get the class of the var annotation.
4242
*
4343
* @param ReflectionProperty $property
4444
*
4545
* @throws AnnotationException
4646
* @return string|null Type of the property (content of var annotation)
47-
* @todo Rename to getPropertyClass
47+
*
48+
* @deprecated Use getPropertyClass instead.
4849
*/
4950
public function getPropertyType(ReflectionProperty $property)
51+
{
52+
return $this->getPropertyClass($property);
53+
}
54+
55+
/**
56+
* Parse the docblock of the property to get the class of the var annotation.
57+
*
58+
* @param ReflectionProperty $property
59+
*
60+
* @throws AnnotationException
61+
* @return string|null Type of the property (content of var annotation)
62+
*/
63+
public function getPropertyClass(ReflectionProperty $property)
5064
{
5165
// Get the content of the @var annotation
5266
if (preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
@@ -119,15 +133,27 @@ public function getPropertyType(ReflectionProperty $property)
119133
}
120134

121135
/**
122-
* Parse the docblock of the property to get the param annotation.
136+
* Parse the docblock of the property to get the class of the param annotation.
123137
*
124138
* @param ReflectionParameter $parameter
125139
*
126140
* @throws AnnotationException
127141
* @return string|null Type of the property (content of var annotation)
128-
* @todo Rename to getParameterClass
129142
*/
130143
public function getParameterType(ReflectionParameter $parameter)
144+
{
145+
return $this->getParameterClass($parameter);
146+
}
147+
148+
/**
149+
* Parse the docblock of the property to get the class of the param annotation.
150+
*
151+
* @param ReflectionParameter $parameter
152+
*
153+
* @throws AnnotationException
154+
* @return string|null Type of the property (content of var annotation)
155+
*/
156+
public function getParameterClass(ReflectionParameter $parameter)
131157
{
132158
// Use reflection
133159
$parameterClass = $parameter->getClass();

tests/UnitTest/PhpDocReader/FunctionalTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public function testReadPropertyType()
1717

1818
$className = 'UnitTest\PhpDocReader\Fixtures\Class1';
1919

20-
$type = $parser->getPropertyType(new ReflectionProperty($className, 'propNone'));
20+
$type = $parser->getPropertyClass(new ReflectionProperty($className, 'propNone'));
2121
$this->assertNull($type);
2222

23-
$type = $parser->getPropertyType(new ReflectionProperty($className, 'propFQN'));
23+
$type = $parser->getPropertyClass(new ReflectionProperty($className, 'propFQN'));
2424
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class2', $type);
2525

26-
$type = $parser->getPropertyType(new ReflectionProperty($className, 'propLocalName'));
26+
$type = $parser->getPropertyClass(new ReflectionProperty($className, 'propLocalName'));
2727
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class2', $type);
2828

29-
$type = $parser->getPropertyType(new ReflectionProperty($className, 'propAlias'));
29+
$type = $parser->getPropertyClass(new ReflectionProperty($className, 'propAlias'));
3030
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class3', $type);
3131
}
3232

@@ -36,19 +36,19 @@ public function testReadParamType()
3636

3737
$method = array('UnitTest\PhpDocReader\Fixtures\Class1', 'foo');
3838

39-
$type = $parser->getParameterType(new ReflectionParameter($method, 'paramNone'));
39+
$type = $parser->getParameterClass(new ReflectionParameter($method, 'paramNone'));
4040
$this->assertNull($type);
4141

42-
$type = $parser->getParameterType(new ReflectionParameter($method, 'paramTypeHint'));
42+
$type = $parser->getParameterClass(new ReflectionParameter($method, 'paramTypeHint'));
4343
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class2', $type);
4444

45-
$type = $parser->getParameterType(new ReflectionParameter($method, 'paramFQN'));
45+
$type = $parser->getParameterClass(new ReflectionParameter($method, 'paramFQN'));
4646
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class2', $type);
4747

48-
$type = $parser->getParameterType(new ReflectionParameter($method, 'paramLocalName'));
48+
$type = $parser->getParameterClass(new ReflectionParameter($method, 'paramLocalName'));
4949
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class2', $type);
5050

51-
$type = $parser->getParameterType(new ReflectionParameter($method, 'paramAlias'));
51+
$type = $parser->getParameterClass(new ReflectionParameter($method, 'paramAlias'));
5252
$this->assertEquals('UnitTest\PhpDocReader\Fixtures\Class3', $type);
5353
}
5454
}

tests/UnitTest/PhpDocReader/Issue1Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testProperties($type)
1717
$parser = new PhpDocReader();
1818
$class = new \ReflectionClass('UnitTest\PhpDocReader\FixturesIssue1\Class1');
1919

20-
$this->assertNull($parser->getPropertyType($class->getProperty($type)));
20+
$this->assertNull($parser->getPropertyClass($class->getProperty($type)));
2121
}
2222

2323
/**
@@ -34,7 +34,7 @@ public function testMethodParameters($type)
3434
}, $params);
3535
$params = array_combine($keys, $params);
3636

37-
$this->assertNull($parser->getParameterType($params[$type]));
37+
$this->assertNull($parser->getParameterClass($params[$type]));
3838
}
3939

4040
public function typeProvider()

tests/UnitTest/PhpDocReader/Issue87Test.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function testGetParameterTypeUseStatementBeforeLocalNamespace()
2323
$target1ReflectionMethod = $target1ReflectionClass->getMethod("SomeMethod");
2424
$target1ReflectionParams = $target1ReflectionMethod->getParameters();
2525

26-
$result = $parser->getParameterType($target1ReflectionParams[0]);
26+
$result = $parser->getParameterClass($target1ReflectionParams[0]);
2727

2828
//Since TargetFixture1 file has a use statement to the Subspace namespace, that's the one that should be returned
2929
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture', $result);
3030

3131

32-
$result = $parser->getParameterType($target1ReflectionParams[1]);
32+
$result = $parser->getParameterClass($target1ReflectionParams[1]);
3333

3434
//this parameter should be unaffected by use namespace since it has a relative type path
3535
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
@@ -42,13 +42,13 @@ public function testGetParameterTypeUseStatementBeforeLocalNamespace()
4242
$target2ReflectionMethod = $target2ReflectionClass->getMethod("SomeMethod");
4343
$target2ReflectionParams = $target2ReflectionMethod->getParameters();
4444

45-
$result = $parser->getParameterType($target2ReflectionParams[0]);
45+
$result = $parser->getParameterClass($target2ReflectionParams[0]);
4646

4747
//Since TargetFixture2 file has a use statement with an alias to the Subspace namespace, that's the one that should be returned
4848
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
4949

5050

51-
$result = $parser->getParameterType($target2ReflectionParams[1]);
51+
$result = $parser->getParameterClass($target2ReflectionParams[1]);
5252

5353
//this parameter should be unaffected by use namespace since it has a relative type path
5454
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
@@ -61,13 +61,13 @@ public function testGetParameterTypeUseStatementBeforeLocalNamespace()
6161
$target3ReflectionMethod = $target3ReflectionClass->getMethod("SomeMethod");
6262
$target3ReflectionParams = $target3ReflectionMethod->getParameters();
6363

64-
$result = $parser->getParameterType($target3ReflectionParams[0]);
64+
$result = $parser->getParameterClass($target3ReflectionParams[0]);
6565

6666
//Since TargetFixture3 file has NO use statement, the one local to the target's namespace should be used
6767
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\SomeDependencyFixture', $result);
6868

6969

70-
$result = $parser->getParameterType($target3ReflectionParams[1]);
70+
$result = $parser->getParameterClass($target3ReflectionParams[1]);
7171

7272
//this parameter should be unaffected by use namespace since it has a relative type path
7373
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
@@ -87,15 +87,15 @@ public function testGetPropertyTypeUseStatementBeforeLocalNamespace()
8787
$target1ReflectionClass = new \ReflectionClass($target1);
8888
$target1ReflectionProperty1 = $target1ReflectionClass->getProperty("dependency1");
8989

90-
$result = $parser->getPropertyType($target1ReflectionProperty1);
90+
$result = $parser->getPropertyClass($target1ReflectionProperty1);
9191

9292
//Since TargetFixture1 file has a use statement to the Subspace namespace, that's the one that should be returned
9393
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture', $result);
9494

9595

9696
$target1ReflectionProperty2 = $target1ReflectionClass->getProperty("dependency2");
9797

98-
$result = $parser->getPropertyType($target1ReflectionProperty2);
98+
$result = $parser->getPropertyClass($target1ReflectionProperty2);
9999

100100
//this property should be unaffected by use namespace since it has a relative type path
101101
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
@@ -107,15 +107,15 @@ public function testGetPropertyTypeUseStatementBeforeLocalNamespace()
107107
$target2ReflectionClass = new \ReflectionClass($target2);
108108
$target2ReflectionProperty1 = $target2ReflectionClass->getProperty("dependency1");
109109

110-
$result = $parser->getPropertyType($target2ReflectionProperty1);
110+
$result = $parser->getPropertyClass($target2ReflectionProperty1);
111111

112112
//Since TargetFixture2 file has a use statement with an alias to the Subspace namespace, that's the one that should be returned
113113
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
114114

115115

116116
$target2ReflectionProperty2 = $target2ReflectionClass->getProperty("dependency2");
117117

118-
$result = $parser->getPropertyType($target2ReflectionProperty2);
118+
$result = $parser->getPropertyClass($target2ReflectionProperty2);
119119

120120
//this property should be unaffected by use namespace since it has a relative type path
121121
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);
@@ -127,15 +127,15 @@ public function testGetPropertyTypeUseStatementBeforeLocalNamespace()
127127
$target3ReflectionClass = new \ReflectionClass($target3);
128128
$target3ReflectionProperty1 = $target3ReflectionClass->getProperty("dependency1");
129129

130-
$result = $parser->getPropertyType($target3ReflectionProperty1);
130+
$result = $parser->getPropertyClass($target3ReflectionProperty1);
131131

132132
//Since TargetFixture3 file has NO use statement, the one local to the target's namespace should be used
133133
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\SomeDependencyFixture', $result);
134134

135135

136136
$target3ReflectionProperty2 = $target3ReflectionClass->getProperty("dependency2");
137137

138-
$result = $parser->getPropertyType($target3ReflectionProperty2);
138+
$result = $parser->getPropertyClass($target3ReflectionProperty2);
139139

140140
//this property should be unaffected by use namespace since it has a relative type path
141141
$this->assertEquals('UnitTest\PhpDocReader\FixturesIssue87\Subspace\SomeDependencyFixture2', $result);

0 commit comments

Comments
 (0)