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

Updated PHPUnit and PHPStan dependencies #400

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
php: 7.1
env: DEPENDENCIES=""
before_script:
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8.3
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.9.2
script: vendor/bin/phpstan analyse -l 5 -c phpstan.neon src

- stage: Run benchmarks
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

],
"require-dev": {
"phpunit/phpunit": "^6.3.0"
"phpunit/phpunit": "^7.0.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 5 additions & 5 deletions src/NodeCompiler/CompileNodeToValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,27 @@ private function compileConstFetch(Node\Expr\ConstFetch $constNode)
*/
private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, CompilerContext $context)
{
/** @var Node\Name $node->class */
/** @var string $nodeName */
$nodeName = $node->name;
$className = $node->class->toString();

if ($node->name === 'class') {
if ($nodeName === 'class') {
return $className;
}

/** @var ReflectionClass|null $classInfo */
$classInfo = null;

if ($className === 'self' || $className === 'static') {
$classInfo = $this->getConstantDeclaringClass($node->name, $context->getSelf());
$classInfo = $this->getConstantDeclaringClass($nodeName, $context->getSelf());
}

if ($classInfo === null) {
/** @var ReflectionClass $classInfo */
$classInfo = $context->getReflector()->reflect($className);
}

/** @var string $node->name */
$reflectionConstant = $classInfo->getReflectionConstant($node->name);
$reflectionConstant = $classInfo->getReflectionConstant($nodeName);

return $this->__invoke(
$reflectionConstant->getAst()->consts[$reflectionConstant->getPositionInAst()]->value,
Expand Down
6 changes: 5 additions & 1 deletion src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,12 @@ function (ClassMethod $methodNode) : ReflectionMethod {
...array_map(
function (ReflectionClass $trait) : array {
return array_map(function (ReflectionMethod $method) use ($trait) : ReflectionMethod {
/** @var ClassMethod $methodAst */
$methodAst = $method->getAst();

return ReflectionMethod::createFromNode(
$this->reflector,
$method->getAst(),
$methodAst,
$this->declaringNamespace,
$trait,
$this
Expand Down Expand Up @@ -958,6 +961,7 @@ public function getTraitAliases() : array
$adaptations = $traitUsage->adaptations;

foreach ($adaptations as $adaptation) {
/** @var Node\Name|null $usedTrait */
$usedTrait = $adaptation->trait;
if ($usedTrait === null) {
$usedTrait = $traitNames[0];
Expand Down
11 changes: 8 additions & 3 deletions src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ private function nodeIsOrContainsYield(Node $node) : bool
return true;
}

foreach ($node as $nodeProperty) {
foreach ($node->getSubNodeNames() as $nodeName) {
$nodeProperty = $node->$nodeName;

if ($nodeProperty instanceof Node && $this->nodeIsOrContainsYield($nodeProperty)) {
return true;
}
Expand Down Expand Up @@ -379,7 +381,7 @@ public function getEndColumn() : int
*/
public function returnsReference() : bool
{
return (bool) $this->node->byRef;
return $this->node->byRef;
}

/**
Expand Down Expand Up @@ -503,7 +505,10 @@ public function setBodyFromClosure(Closure $newBody) : void
new Identifier(self::CLOSURE_NAME, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION))
);

$this->node->stmts = $closureReflection->getNode()->stmts;
/** @var Node\Stmt\Function_ $functionNode */
$functionNode = $closureReflection->getNode();

$this->node->stmts = $functionNode->stmts;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Reflection/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function createFromClosure(Closure $closure, string $parameterName
* - ['foo']
* - [function () {}]
*
* @param string[]|string|\Closure $spec
* @param object[]|string[]|string|\Closure $spec
* @throws \Exception
* @throws \InvalidArgumentException
*/
Expand Down Expand Up @@ -196,8 +196,9 @@ private function parseDefaultValueNode() : void
$className = $defaultValueNode->class->toString();

if ($className === 'self' || $className === 'static') {
/** @var string $defaultValueNode->name */
$className = $this->findParentClassDeclaringConstant($defaultValueNode->name);
/** @var string $constantName */
$constantName = $defaultValueNode->name;
$className = $this->findParentClassDeclaringConstant($constantName);
}

$this->isDefaultValueConstant = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Reflector/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function __construct(SourceLocator $sourceLocator)
/**
* Create a ReflectionClass for the specified $className.
*
* @return \Roave\BetterReflection\Reflection\ReflectionClass|Reflection
* @return \Roave\BetterReflection\Reflection\ReflectionClass
* @throws \Roave\BetterReflection\Reflector\Exception\IdentifierNotFound
*/
public function reflect(string $className) : Reflection
{
$identifier = new Identifier($className, new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

/** @var \Roave\BetterReflection\Reflection\ReflectionClass|null $classInfo */
$classInfo = $this->sourceLocator->locateIdentifier($this, $identifier);

if ($classInfo === null) {
Expand Down
3 changes: 2 additions & 1 deletion src/Reflector/FunctionReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public function __construct(SourceLocator $sourceLocator, ClassReflector $classR
/**
* Create a ReflectionFunction for the specified $functionName.
*
* @return \Roave\BetterReflection\Reflection\Reflection|\Roave\BetterReflection\Reflection\ReflectionFunction
* @return \Roave\BetterReflection\Reflection\ReflectionFunction
* @throws \Roave\BetterReflection\Reflector\Exception\IdentifierNotFound
*/
public function reflect(string $functionName) : Reflection
{
$identifier = new Identifier($functionName, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION));

/** @var \Roave\BetterReflection\Reflection\ReflectionFunction|null $functionInfo */
$functionInfo = $this->sourceLocator->locateIdentifier($this->classReflector, $identifier);

if ($functionInfo === null) {
Expand Down
10 changes: 6 additions & 4 deletions test/unit/TestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

use ClassWithExplicitGlobalNamespace;
use ClassWithNoNamespace;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestListener as BaseTestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use Roave\BetterReflectionTest\Fixture\ExampleClass;
use Roave\BetterReflectionTest\Fixture\Methods;
use Roave\BetterReflectionTest\FixtureOther\AnotherClass;
use function class_exists;

class TestListener extends BaseTestListener
class TestListener implements BaseTestListener
{
use TestListenerDefaultImplementation;

/**
* @var \PHPUnit\Framework\TestSuite|null
*/
Expand Down Expand Up @@ -50,11 +53,10 @@ class_exists($className, false),
/**
* Ensure the fixture classes have not actually been loaded (where applicable)
*
* @param float $time
* @throws \PHPUnit\Framework\AssertionFailedError
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function endTest(Test $test, $time) : void
public function endTest(Test $test, float $time) : void
{
// Only test PHPUnit tests (i.e. no .phpt tests or anything else unexpected)
if (! ($test instanceof TestCase)) {
Expand Down