-
Notifications
You must be signed in to change notification settings - Fork 132
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
[WIP] Variable collector #224
Changes from 2 commits
d9ff53e
448b9ba
8c599d8
3a73b19
21a81c3
3ba940b
eeffd3b
ddd165c
bf38f08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
# - 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace BetterReflection\Reflection; | ||
|
||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\Types; | ||
|
||
class ReflectionVariable | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $declaredAt; | ||
|
||
/** | ||
* @var $type | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @param string $name | ||
* @param int $declaredAt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure about just having the line number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, ideally there would be the range of (characters?) that the variable is available for, but the PHP parser just gives us line numbers .. |
||
* @param string $type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't say much - need some sort of more restrictive hint here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its actually a |
||
* @return ReflectionType | ||
*/ | ||
public static function createFromName($name, ReflectionType $type = null, $declaredAt) | ||
{ | ||
$reflectionType = new self(); | ||
$reflectionType->name = $name; | ||
$reflectionType->declaredAt = $declaredAt; | ||
$reflectionType->type = $type; | ||
return $reflectionType; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getDeclaredAt() | ||
{ | ||
return $this->declaredAt; | ||
} | ||
|
||
/** | ||
* Get a PhpDocumentor type object for this type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the type mutated during execution? Two variables with same name, but different type and declaration line, then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We return all declarations, so you could get two with the same name, but covering different parts of the code. |
||
* | ||
* @return Type | ||
*/ | ||
public function getTypeObject() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* Checks if it is a built-in type (i.e., it's not an object...) | ||
* | ||
* @see http://php.net/manual/en/reflectiontype.isbuiltin.php | ||
* @return bool | ||
*/ | ||
public function isBuiltin() | ||
{ | ||
return (!$this->type instanceof Types\Object_); | ||
} | ||
|
||
/** | ||
* Convert this string type to a string | ||
* | ||
* @see https://github.com/php/php-src/blob/master/ext/reflection/php_reflection.c#L2993 | ||
* @return string | ||
*/ | ||
public function __toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't add this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found it useful for testing, but mainly I added it to be consistent with the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless it actually is required API, I wouldn't add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, will remove it. I can only guess that the |
||
{ | ||
return sprintf('@var $%s (%s): %s', $this->name, $this->type, $this->declaredAt); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have switched to using PHP7 at least for development - guessing that you are going to switch to PHP7 in the near-future anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - that's the plan :) #221