diff --git a/docs/compatibility.md b/docs/compatibility.md index 27b2e76ad..1fc624959 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -12,7 +12,7 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | getDefaultProperties | todo | | getDocComment | todo | | getEndLine | todo | -| getExtension | :x: No - extensions are not supported (#15) | +| getExtension | :x: No - extensions are not supported ([#15](https://github.com/Roave/BetterReflection/issues/15)) | | getFileName | :heavy_check_mark: Yes | | getInterfaceNames | todo | | getInterfaces | todo | @@ -26,8 +26,8 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | getProperty | :heavy_check_mark: Yes | | getShortName | :heavy_check_mark: Yes | | getStartLine | todo | -| getStaticProperties | :x: No - would require loading (#14) | -| getStaticPropertyValue | :x: No - would require loading (#14) | +| getStaticProperties | :x: No - would require loading ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| getStaticPropertyValue | :x: No - would require loading ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | getTraitAliases | todo | | getTraitNames | todo | | getTraits | todo | @@ -50,18 +50,18 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | newInstance | todo | | newInstanceArgs | todo | | newInstanceWithoutConstructor | todo | -| setStaticPropertyValue | :x: No - would require loading (#14) | +| setStaticPropertyValue | :x: No - would require loading ([#14](https://github.com/Roave/BetterReflection/issues/14)) | ## ReflectionFunctionAbstract | Method | Supported | |--------|-----------| -| getClosureScopeClass | :x: No - would require loading of the method itself (#14) | -| getClosureThis | :x: No - would require loading of the method itself (#14) | +| getClosureScopeClass | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| getClosureThis | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | getDocComment | :heavy_check_mark: Yes | | getEndLine | :heavy_check_mark: Yes | -| getExtension | :x: No - extensions are not supported (#15) | -| getExtensionName | :x: No - extensions are not supported (#15) | +| getExtension | :x: No - extensions are not supported ([#15](https://github.com/Roave/BetterReflection/issues/15)) | +| getExtensionName | :x: No - extensions are not supported ([#15](https://github.com/Roave/BetterReflection/issues/15)) | | getFileName | :heavy_check_mark: Yes | | getName | :heavy_check_mark: Yes | | getNamespaceName | :heavy_check_mark: Yes | @@ -70,26 +70,26 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | getParameters | :heavy_check_mark: Yes | | getShortName | :heavy_check_mark: Yes | | getStartLine | :heavy_check_mark: Yes | -| getStaticVariables | :x: No - would require loading (#14) | +| getStaticVariables | :x: No - would require loading ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | inNamespace | :heavy_check_mark: Yes | -| isClosure | :heavy_check_mark: Yes - but see issue (#37) | -| isDeprecated | :heavy_check_mark: Yes - but see issue (#38) | +| isClosure | :heavy_check_mark: Yes - but see issue ([#37](https://github.com/Roave/BetterReflection/issues/37)) | +| isDeprecated | :heavy_check_mark: Yes - but see issue ([#38](https://github.com/Roave/BetterReflection/issues/38)) | | isGenerator | :heavy_check_mark: Yes | -| isInternal | :heavy_check_mark: Yes - but see issue (#38) | +| isInternal | :heavy_check_mark: Yes - but see issue ([#38](https://github.com/Roave/BetterReflection/issues/38)) | | isUserDefined | :heavy_check_mark: Yes | | isVariadic | :heavy_check_mark: Yes | -| returnsReference | :heavy_check_mark: Ye | +| returnsReference | :heavy_check_mark: Yes | ## ReflectionMethod | Method | Supported | |--------|-----------| -| getClosure | :x: No - would require loading of the method itself (#14) | +| getClosure | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | getDeclaringClass | :heavy_check_mark: Yes | -| getModifiers | todo | -| getPrototype | todo | -| invoke | :x: No - would require loading of the method itself (#14) | -| invokeArgs | :x: No - would require loading of the method itself (#14) | +| getModifiers | :heavy_check_mark: Yes | +| getPrototype | todo - [#57](https://github.com/Roave/BetterReflection/issues/57) | +| invoke | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| invokeArgs | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | isAbstract | :heavy_check_mark: Yes | | isConstructor | :heavy_check_mark: Yes | | isDestructor | :heavy_check_mark: Yes | @@ -98,7 +98,7 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | isProtected | :heavy_check_mark: Yes | | isPublic | :heavy_check_mark: Yes | | isStatic | :heavy_check_mark: Yes | -| setAccessible | :x: No - would require loading of the method itself (#14) | +| setAccessible | :x: No - would require loading of the method itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | _inherited methods_ | see `ReflectionFunctionAbstract` | ## ReflectionParameter @@ -126,10 +126,10 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | Method | Supported | |--------|-----------| -| getClosure | :x: No - would require actual compilation of the AST (#14) | -| invoke | :x: No - would require loading of the function itself (#14) | -| invokeArgs | :x: No - would require loading of the function itself (#14) | -| isDisabled | :heavy_check_mark: Yes - but see issue (#38) | +| getClosure | :x: No - would require actual compilation of the AST ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| invoke | :x: No - would require loading of the function itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| invokeArgs | :x: No - would require loading of the function itself ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| isDisabled | :heavy_check_mark: Yes - but see issue ([#38](https://github.com/Roave/BetterReflection/issues/38)) | | _inherited methods_ | see `ReflectionFunctionAbstract` | ## ReflectionProperty @@ -140,14 +140,14 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c | getDocComment | :heavy_check_mark: Yes | | getModifiers | :heavy_check_mark: Yes | | getName | :heavy_check_mark: Yes | -| getValue | :x: No - would require an instance of an object (#14) | +| getValue | :x: No - would require an instance of an object ([#14](https://github.com/Roave/BetterReflection/issues/14)) | | isDefault | :heavy_check_mark: Yes | | isPrivate | :heavy_check_mark: Yes | | isProtected | :heavy_check_mark: Yes | | isPublic | :heavy_check_mark: Yes | | isStatic | :heavy_check_mark: Yes | -| setAccessible | :x: No - would require an instance of an object (#14) | -| setValue | :x: No - would require an instance of an object (#14) | +| setAccessible | :x: No - would require an instance of an object ([#14](https://github.com/Roave/BetterReflection/issues/14)) | +| setValue | :x: No - would require an instance of an object ([#14](https://github.com/Roave/BetterReflection/issues/14)) | ## ReflectionExtension diff --git a/src/Reflection/Exception/MethodPrototypeNotFound.php b/src/Reflection/Exception/MethodPrototypeNotFound.php new file mode 100644 index 000000000..cfa005833 --- /dev/null +++ b/src/Reflection/Exception/MethodPrototypeNotFound.php @@ -0,0 +1,7 @@ +getDeclaringClass()->getName(), + $this->getName() + )); + } + + /** + * Get the core-reflection-compatible modifier values + * + * @return int + */ + public function getModifiers() + { + $val = 0; + $val += $this->isStatic() ? \ReflectionMethod::IS_STATIC : 0; + $val += $this->isPublic() ? \ReflectionMethod::IS_PUBLIC : 0; + $val += $this->isProtected() ? \ReflectionMethod::IS_PROTECTED : 0; + $val += $this->isPrivate() ? \ReflectionMethod::IS_PRIVATE : 0; + $val += $this->isAbstract() ? \ReflectionMethod::IS_ABSTRACT : 0; + $val += $this->isFinal() ? \ReflectionMethod::IS_FINAL : 0; + return $val; + } + /** * Check to see if a flag is set on this method * diff --git a/test/unit/Fixture/PrototypeTree.php b/test/unit/Fixture/PrototypeTree.php new file mode 100644 index 000000000..66dd507c1 --- /dev/null +++ b/test/unit/Fixture/PrototypeTree.php @@ -0,0 +1,31 @@ +assertSame('', $methodInfo->getNamespaceName()); $this->assertSame('someMethod', $methodInfo->getShortName()); } + + public function modifierProvider() + { + return [ + ['publicMethod', \ReflectionMethod::IS_PUBLIC, ['public']], + ['privateMethod', \ReflectionMethod::IS_PRIVATE, ['private']], + ['protectedMethod', \ReflectionMethod::IS_PROTECTED, ['protected']], + ['finalPublicMethod', \ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC, ['final', 'public']], + ['abstractPublicMethod', \ReflectionMethod::IS_ABSTRACT | \ReflectionMethod::IS_PUBLIC, ['abstract', 'public']], + ['staticPublicMethod', \ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC, ['public', 'static']], + ['noVisibility', \ReflectionMethod::IS_PUBLIC, ['public']], + ]; + } + + /** + * @param string $methodName + * @param int $expectedModifier + * @param string[] $expectedModifierNames + * @dataProvider modifierProvider + */ + public function testGetModifiers($methodName, $expectedModifier, array $expectedModifierNames) + { + $classInfo = $this->reflector->reflect('\BetterReflectionTest\Fixture\Methods'); + $method = $classInfo->getMethod($methodName); + + $this->assertSame($expectedModifier, $method->getModifiers()); + $this->assertSame( + $expectedModifierNames, + \Reflection::getModifierNames($method->getModifiers()) + ); + } + + public function testGetPrototype() + { + $fixture = __DIR__ . '/../Fixture/PrototypeTree.php'; + $reflector = new ClassReflector(new SingleFileSourceLocator($fixture)); + + $this->setExpectedException(MethodPrototypeNotFound::class); + $reflector->reflect('ClassB')->getMethod('foo')->getPrototype(); + } } diff --git a/test/unit/Reflection/ReflectionPropertyTest.php b/test/unit/Reflection/ReflectionPropertyTest.php index 1d5b5831a..7582aed1e 100644 --- a/test/unit/Reflection/ReflectionPropertyTest.php +++ b/test/unit/Reflection/ReflectionPropertyTest.php @@ -123,10 +123,10 @@ public function testExportThrowsException() public function modifierProvider() { return [ - ['publicProperty', 256, ['public']], - ['protectedProperty', 512, ['protected']], - ['privateProperty', 1024, ['private']], - ['publicStaticProperty', 257, ['public', 'static']], + ['publicProperty', \ReflectionProperty::IS_PUBLIC, ['public']], + ['protectedProperty', \ReflectionProperty::IS_PROTECTED, ['protected']], + ['privateProperty', \ReflectionProperty::IS_PRIVATE, ['private']], + ['publicStaticProperty', \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_STATIC, ['public', 'static']], ]; }