Skip to content

Commit

Permalink
Updated for PHPStan 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 8, 2017
1 parent 1c116ae commit aea27d5
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
>
<arg value="analyse"/>
<arg value="-l"/>
<arg value="4"/>
<arg value="7"/>
<arg value="-c"/>
<arg path="phpstan.neon"/>
<arg path="src"/>
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
"license": ["MIT"],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.7-dev"
}
},
"require": {
"php": "~7.0",
"phpstan/phpstan": "^0.6",
"phpstan/phpstan": "^0.7",
"nette/component-model": "^2.3.0 || ^3.0.0",
"nette/di": "^2.3.0 || ^3.0.0",
"nette/forms": "^2.3.0 || ^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
ignoreErrors:
- '#Call to an undefined method PHPUnit_Framework_MockObject_MockObject::[a-zA-Z0-9_]+\(\)#'
- '#PHPUnit_Framework_MockObject_MockObject given#'
- '#Class Nette\\Utils\\ObjectHelpers not found#'
- '#Call to static method getMagicProperties\(\) on an unknown class Nette\\Utils\\ObjectHelpers#'
2 changes: 1 addition & 1 deletion src/Reflection/Nette/HtmlMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getName(): string

public function getReturnType(): Type
{
return new ObjectType(Html::class, false);
return new ObjectType(Html::class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private function getMethodByProperty(ClassReflection $classReflection, string $p

public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
/** @var \PHPStan\Reflection\MethodReflection $getterMethod */
$getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
return new NetteObjectPropertyReflection($classReflection, $getterMethod->getReturnType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private function getMethodByProperty(ClassReflection $classReflection, string $p

public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
/** @var \PHPStan\Reflection\MethodReflection $getterMethod */
$getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
return new NetteObjectPropertyReflection($classReflection, $getterMethod->getReturnType());
}
Expand Down
9 changes: 5 additions & 4 deletions src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\TrueBooleanType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

class ServiceLocatorDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension
{
Expand Down Expand Up @@ -47,19 +48,19 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}

if ($class === 'self') {
$class = $scope->getClass();
$class = $scope->getClassReflection()->getName();
}

$isNullable = false;
$type = new ObjectType($class);
if (
$methodReflection->getName() === 'getByType'
&& count($methodCall->args) >= 2
&& $scope->getType($methodCall->args[1]->value) instanceof TrueBooleanType
) {
$isNullable = true;
$type = TypeCombinator::addNull($type);
}

return new ObjectType($class, $isNullable);
return $type;
}

}
9 changes: 2 additions & 7 deletions tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace PHPStan\Reflection\Nette;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;

class HtmlClassReflectionExtensionTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -58,9 +56,7 @@ public function testGetMethod()
$this->assertTrue($methodReflection->isVariadic());
$this->assertFalse($methodReflection->isPrivate());
$this->assertTrue($methodReflection->isPublic());
$this->assertInstanceOf(ObjectType::class, $methodReflection->getReturnType());
$this->assertSame(\Nette\Utils\Html::class, $methodReflection->getReturnType()->getClass());
$this->assertFalse($methodReflection->getReturnType()->isNullable());
$this->assertSame(\Nette\Utils\Html::class, $methodReflection->getReturnType()->describe());
}

/**
Expand Down Expand Up @@ -101,8 +97,7 @@ public function testGetProperty()
$this->assertFalse($propertyReflection->isStatic());
$this->assertFalse($propertyReflection->isPrivate());
$this->assertTrue($propertyReflection->isPublic());
$this->assertInstanceOf(MixedType::class, $propertyReflection->getType());
$this->assertTrue($propertyReflection->getType()->isNullable());
$this->assertSame('mixed', $propertyReflection->getType()->describe());
}

}

0 comments on commit aea27d5

Please sign in to comment.