Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility for ReflectionFunctionAbstract and ReflectionFunction #40

Merged
merged 14 commits into from
Jul 8, 2015
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | todo |
| getStaticPropertyValue | :x: No - would require an instance (#14) |
| getStaticProperties | :x: No - would require loading (#14) |
| getStaticPropertyValue | :x: No - would require loading (#14) |
| getTraitAliases | todo |
| getTraitNames | todo |
| getTraits | todo |
Expand All @@ -50,35 +50,35 @@ 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 an instance (#14) |
| setStaticPropertyValue | :x: No - would require loading (#14) |

## ReflectionFunctionAbstract

| Method | Supported |
|--------|-----------|
| getClosureScopeClass | todo |
| getClosureThis | todo |
| getClosureScopeClass | :x: No - would require loading of the method itself (#14) |
| getClosureThis | :x: No - would require loading of the method itself (#14) |
| getDocComment | :heavy_check_mark: Yes |
| getEndLine | todo |
| getExtension | todo |
| getExtensionName | todo |
| getEndLine | :heavy_check_mark: Yes |
| getExtension | :x: No - extensions are not supported (#15) |
| getExtensionName | :x: No - extensions are not supported (#15) |
| getFileName | :heavy_check_mark: Yes |
| getName | :heavy_check_mark: Yes |
| getNamespaceName | todo |
| getNamespaceName | :heavy_check_mark: Yes |
| getNumberOfParameters | :heavy_check_mark: Yes |
| getNumberOfRequiredParameters | :heavy_check_mark: Yes |
| getParameters | :heavy_check_mark: Yes |
| getShortName | todo |
| getStartLine | todo |
| getStaticVariables | todo |
| inNamespace | todo |
| isClosure | todo |
| isDeprecated | todo |
| isGenerator | todo |
| isInternal | todo |
| isUserDefined | todo |
| isVariadic | todo |
| returnsReference | todo |
| getShortName | :heavy_check_mark: Yes |
| getStartLine | :heavy_check_mark: Yes |
| getStaticVariables | :x: No - would require loading (#14) |
| inNamespace | :heavy_check_mark: Yes |
| isClosure | :heavy_check_mark: Yes - but see issue (#37) |
| isDeprecated | :heavy_check_mark: Yes - but see issue (#38) |
| isGenerator | :heavy_check_mark: Yes |
| isInternal | :heavy_check_mark: Yes - but see issue (#38) |
| isUserDefined | :heavy_check_mark: Yes |
| isVariadic | :heavy_check_mark: Yes |
| returnsReference | :heavy_check_mark: Ye |

## ReflectionMethod

Expand Down Expand Up @@ -129,7 +129,7 @@ The progress of compatibility can also be tracked in issue [#7](https://github.c
| 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 | todo |
| isDisabled | :heavy_check_mark: Yes - but see issue (#38) |
| _inherited methods_ | see `ReflectionFunctionAbstract` |

## ReflectionProperty
Expand Down
9 changes: 7 additions & 2 deletions src/Identifier/IdentifierType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use PhpParser\Node;
use BetterReflection\Reflection\ReflectionClass;
use BetterReflection\Reflection\ReflectionFunction;
use BetterReflection\Reflection\Reflection;

class IdentifierType
{
const IDENTIFIER_CLASS = ReflectionClass::class;
const IDENTIFIER_FUNCTION = ReflectionFunction::class;

/**
* @var string[]
*/
private $validTypes = [
self::IDENTIFIER_CLASS,
self::IDENTIFIER_FUNCTION,
];

/**
Expand Down Expand Up @@ -50,10 +53,12 @@ public function getName()
public function isMatchingReflector(Reflection $reflector)
{
if ($this->name == self::IDENTIFIER_CLASS) {
return $reflector instanceof ReflectionClass;
return ($reflector instanceof ReflectionClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parenthesis not needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one day

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#48

}

// @todo add more type checks
if ($this->name == self::IDENTIFIER_FUNCTION) {
return ($reflector instanceof ReflectionFunction);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parenthesis not needed

}

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ private function __construct()
* Create from a Class Node
*
* @param ClassNode $node
* @param NamespaceNode $namespace optional - if omitted, we assume it is global namespaced class
* @param string $filename If set, this is the filename the class was declared in
* @param NamespaceNode|null $namespace optional - if omitted, we assume it is global namespaced class
* @param string|null $filename If set, this is the filename the class was declared in
* @return ReflectionClass
*/
public static function createFromNode(
Expand Down
43 changes: 43 additions & 0 deletions src/Reflection/ReflectionFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace BetterReflection\Reflection;

use PhpParser\Node\Stmt\Function_ as FunctionNode;
use PhpParser\Node\Stmt\Namespace_ as NamespaceNode;

class ReflectionFunction extends ReflectionFunctionAbstract implements Reflection
{
/**
* @param FunctionNode $node
* @param NamespaceNode|null $namespaceNode
* @param string|null $filename
* @return ReflectionMethod
*/
public static function createFromNode(
FunctionNode $node,
NamespaceNode $namespaceNode = null,
$filename = null
) {
$method = new self($node);

$method->populateFunctionAbstract($node, $namespaceNode, $filename);

return $method;
}

/**
* Check to see if this function has been disabled (by the PHP INI file
* directive `disable_functions`)
*
* Note - we cannot reflect on internal functions (as there is no PHP source
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link #14 here

* code we can access. This means, at present, we can only EVER return false
* from this function, because you cannot disable user-defined functions.
*
* @see http://php.net/manual/en/ini.core.php#ini.disable-functions
* @return bool
*/
public function isDisabled()
{
return false;
}
}
Loading