Skip to content

Commit 2d0a19d

Browse files
author
Alexander Obuhovich
committed
Merge pull request php-annotations#93 from php-annotations/92-built-in-annotations-should-validate-their-value
Don't trigger notices during malformed `@param` annotation parsing
2 parents 37d6df2 + fde061e commit 2d0a19d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/annotations/standard/ParamAnnotation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public static function parseAnnotation($value)
5353
{
5454
$parts = explode(' ', trim($value), 3);
5555

56+
if (count($parts) < 2) {
57+
// Malformed value, let "initAnnotation" report about it.
58+
return array();
59+
}
60+
5661
return array('type' => $parts[0], 'name' => substr($parts[1], 1));
5762
}
5863

test/suite/Annotations.case.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class SingleNonUsageAnnotation extends Annotation
104104

105105
}
106106

107-
class WrongInterfaceAnnotation {
107+
class WrongInterfaceAnnotation
108+
{
108109

109110
}
110111

@@ -252,6 +253,19 @@ class TestClassFileAwareAnnotation
252253

253254
}
254255

255-
interface TestInterface {
256+
interface TestInterface
257+
{
258+
259+
}
260+
261+
class BrokenParamAnnotationClass
262+
{
256263

264+
/**
265+
* @param $paramName
266+
*/
267+
protected function brokenParamAnnotation($paramName)
268+
{
269+
270+
}
257271
}

test/suite/Annotations.test.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function run(xTestRunner $testRunner)
4646

4747
// disable some annotations not used during testing:
4848
Annotations::getManager()->registry['var'] = false;
49-
Annotations::getManager()->registry['param'] = false;
5049
Annotations::getManager()->registry['undefined'] = 'UndefinedAnnotation';
5150
$testRunner->stopCoverageCollector();
5251

@@ -750,6 +749,17 @@ protected function testFilterUnresolvedAnnotationClass()
750749

751750
$this->check($annotations === array(), 'empty annotation list when filtering failed');
752751
}
752+
753+
public function testMalformedParamAnnotationThrowsException()
754+
{
755+
$this->setExpectedException(
756+
self::ANNOTATION_EXCEPTION,
757+
'ParamAnnotation requires a type property'
758+
);
759+
760+
Annotations::ofMethod('BrokenParamAnnotationClass', 'brokenParamAnnotation');
761+
}
762+
753763
}
754764

755765
return new AnnotationsTest;

0 commit comments

Comments
 (0)