Skip to content

Commit 63e0ca6

Browse files
committed
Open 0.10-dev
1 parent de33963 commit 63e0ca6

11 files changed

+63
-77
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: php
22
php:
3-
- 7.0
43
- 7.1
54
- 7.2
65
before_script:

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"prefer-stable": true,
77
"extra": {
88
"branch-alias": {
9-
"dev-master": "0.9-dev"
9+
"dev-master": "0.10-dev"
1010
}
1111
},
1212
"require": {
13-
"php": "~7.0",
14-
"phpstan/phpstan": "^0.9",
13+
"php": "~7.1",
14+
"phpstan/phpstan": "^0.10",
1515
"nette/component-model": "^2.3.0 || ^3.0.0",
1616
"nette/di": "^2.3.0 || ^3.0.0",
1717
"nette/forms": "^2.3.0 || ^3.0.0",
@@ -21,10 +21,10 @@
2121
"consistence/coding-standard": "~0.13.0",
2222
"jakub-onderka/php-parallel-lint": "^0.9.2",
2323
"phing/phing": "^2.13.0",
24-
"phpstan/phpstan-php-parser": "^0.9",
25-
"phpstan/phpstan-phpunit": "^0.9",
26-
"phpstan/phpstan-strict-rules": "^0.9",
27-
"phpunit/phpunit": "^6.2",
24+
"phpstan/phpstan-php-parser": "^0.10",
25+
"phpstan/phpstan-phpunit": "^0.10",
26+
"phpstan/phpstan-strict-rules": "^0.10",
27+
"phpunit/phpunit": "^7.0",
2828
"satooshi/php-coveralls": "^1.0",
2929
"slevomat/coding-standard": "^2.0"
3030
},

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ includes:
22
- vendor/phpstan/phpstan-php-parser/extension.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
- vendor/phpstan/phpstan-phpunit/rules.neon
5+
- vendor/phpstan/phpstan-phpunit/strictRules.neon
56
- vendor/phpstan/phpstan-strict-rules/rules.neon
67

78
parameters:

rules.neon

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
services:
2-
-
3-
class: PHPStan\Rule\Nette\DoNotExtendNetteObjectRule
4-
tags:
5-
- phpstan.rules.rule
1+
rules:
2+
- PHPStan\Rule\Nette\DoNotExtendNetteObjectRule

src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Constant\ConstantStringType;
89
use PHPStan\Type\DynamicMethodReturnTypeExtension;
910
use PHPStan\Type\MixedType;
1011
use PHPStan\Type\Type;
@@ -37,12 +38,12 @@ public function getTypeFromMethodCall(
3738
return $mixedType;
3839
}
3940

40-
$arg = $args[0]->value;
41-
if (!$arg instanceof \PhpParser\Node\Scalar\String_) {
41+
$argType = $scope->getType($args[0]->value);
42+
if (!$argType instanceof ConstantStringType) {
4243
return $mixedType;
4344
}
4445

45-
$componentName = $arg->value;
46+
$componentName = $argType->getValue();
4647

4748
$methodName = sprintf('createComponent%s', ucfirst($componentName));
4849
if (!$calledOnType->hasMethod($methodName)) {

src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Type\ArrayType;
9+
use PHPStan\Type\Constant\ConstantBooleanType;
910
use PHPStan\Type\DynamicMethodReturnTypeExtension;
10-
use PHPStan\Type\FalseBooleanType;
1111
use PHPStan\Type\MixedType;
1212
use PHPStan\Type\ObjectType;
1313
use PHPStan\Type\StringType;
14-
use PHPStan\Type\TrueBooleanType;
1514
use PHPStan\Type\Type;
1615

1716
final class FormContainerValuesDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -35,16 +34,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3534

3635
$arg = $methodCall->args[0]->value;
3736
$scopedType = $scope->getType($arg);
38-
39-
if ($scopedType instanceof FalseBooleanType) {
40-
return new ObjectType(\Nette\Utils\ArrayHash::class);
37+
if (!$scopedType instanceof ConstantBooleanType) {
38+
return $methodReflection->getReturnType();
4139
}
4240

43-
if ($scopedType instanceof TrueBooleanType) {
44-
return new ArrayType(new StringType(), new MixedType());
41+
if (!$scopedType->getValue()) {
42+
return new ObjectType(\Nette\Utils\ArrayHash::class);
4543
}
4644

47-
return $methodReflection->getReturnType();
45+
return new ArrayType(new StringType(), new MixedType());
4846
}
4947

5048
}

src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Constant\ConstantBooleanType;
9+
use PHPStan\Type\Constant\ConstantStringType;
810
use PHPStan\Type\MixedType;
911
use PHPStan\Type\ObjectType;
10-
use PHPStan\Type\TrueBooleanType;
1112
use PHPStan\Type\Type;
1213
use PHPStan\Type\TypeCombinator;
1314

@@ -41,33 +42,23 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
4142
if (count($methodCall->args) === 0) {
4243
return $mixedType;
4344
}
44-
$arg = $methodCall->args[0]->value;
45-
if (!($arg instanceof \PhpParser\Node\Expr\ClassConstFetch)) {
45+
$argType = $scope->getType($methodCall->args[0]->value);
46+
if (!$argType instanceof ConstantStringType) {
4647
return $mixedType;
4748
}
4849

49-
$class = $arg->class;
50-
if (!($class instanceof \PhpParser\Node\Name)) {
51-
return $mixedType;
52-
}
53-
54-
$class = (string) $class;
55-
56-
if ($class === 'static') {
57-
return $mixedType;
58-
}
59-
60-
if ($class === 'self') {
61-
$class = $scope->getClassReflection()->getName();
62-
}
63-
64-
$type = new ObjectType($class);
50+
$type = new ObjectType($argType->getValue());
6551
if (
6652
$methodReflection->getName() === 'getByType'
6753
&& count($methodCall->args) >= 2
68-
&& $scope->getType($methodCall->args[1]->value) instanceof TrueBooleanType
6954
) {
70-
$type = TypeCombinator::addNull($type);
55+
$throwType = $scope->getType($methodCall->args[1]->value);
56+
if (
57+
!$throwType instanceof ConstantBooleanType
58+
|| !$throwType->getValue()
59+
) {
60+
$type = TypeCombinator::addNull($type);
61+
}
7162
}
7263

7364
return $type;

tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ public function dataHasMethod(): array
4242
public function testHasMethod(string $className, bool $result)
4343
{
4444
$classReflection = $this->broker->getClass($className);
45-
$this->assertSame($result, $this->extension->hasMethod($classReflection, 'href'));
45+
self::assertSame($result, $this->extension->hasMethod($classReflection, 'href'));
4646
}
4747

4848
public function testGetMethod()
4949
{
5050
$classReflection = $this->broker->getClass(\Nette\Utils\Html::class);
5151
$methodReflection = $this->extension->getMethod($classReflection, 'href');
52-
$this->assertSame('href', $methodReflection->getName());
53-
$this->assertSame($classReflection, $methodReflection->getDeclaringClass());
54-
$this->assertFalse($methodReflection->isStatic());
55-
$this->assertEmpty($methodReflection->getParameters());
56-
$this->assertTrue($methodReflection->isVariadic());
57-
$this->assertFalse($methodReflection->isPrivate());
58-
$this->assertTrue($methodReflection->isPublic());
59-
$this->assertSame(\Nette\Utils\Html::class, $methodReflection->getReturnType()->describe());
52+
self::assertSame('href', $methodReflection->getName());
53+
self::assertSame($classReflection, $methodReflection->getDeclaringClass());
54+
self::assertFalse($methodReflection->isStatic());
55+
self::assertEmpty($methodReflection->getParameters());
56+
self::assertTrue($methodReflection->isVariadic());
57+
self::assertFalse($methodReflection->isPrivate());
58+
self::assertTrue($methodReflection->isPublic());
59+
self::assertSame(\Nette\Utils\Html::class, $methodReflection->getReturnType()->describe());
6060
}
6161

6262
/**
@@ -84,18 +84,18 @@ public function dataHasProperty(): array
8484
public function testHasProperty(string $className, bool $result)
8585
{
8686
$classReflection = $this->broker->getClass($className);
87-
$this->assertSame($result, $this->extension->hasProperty($classReflection, 'href'));
87+
self::assertSame($result, $this->extension->hasProperty($classReflection, 'href'));
8888
}
8989

9090
public function testGetProperty()
9191
{
9292
$classReflection = $this->broker->getClass(\Nette\Utils\Html::class);
9393
$propertyReflection = $this->extension->getProperty($classReflection, 'href');
94-
$this->assertSame($classReflection, $propertyReflection->getDeclaringClass());
95-
$this->assertFalse($propertyReflection->isStatic());
96-
$this->assertFalse($propertyReflection->isPrivate());
97-
$this->assertTrue($propertyReflection->isPublic());
98-
$this->assertSame('mixed', $propertyReflection->getType()->describe());
94+
self::assertSame($classReflection, $propertyReflection->getDeclaringClass());
95+
self::assertFalse($propertyReflection->isStatic());
96+
self::assertFalse($propertyReflection->isPrivate());
97+
self::assertTrue($propertyReflection->isPublic());
98+
self::assertSame('mixed', $propertyReflection->getType()->describe());
9999
}
100100

101101
}

tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function dataHasMethod(): array
5757
public function testHasMethod(string $className, string $method, bool $result)
5858
{
5959
$classReflection = $this->broker->getClass($className);
60-
$this->assertSame($result, $this->extension->hasMethod($classReflection, $method));
60+
self::assertSame($result, $this->extension->hasMethod($classReflection, $method));
6161
}
6262

6363
/**
@@ -100,7 +100,7 @@ public function dataHasProperty(): array
100100
public function testHasProperty(string $className, string $property, bool $result)
101101
{
102102
$classReflection = $this->broker->getClass($className);
103-
$this->assertSame($result, $this->extension->hasProperty($classReflection, $property));
103+
self::assertSame($result, $this->extension->hasProperty($classReflection, $property));
104104
}
105105

106106
}

tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testSmartObjectChild()
2020
public function testNetteObjectChild()
2121
{
2222
if (PHP_VERSION_ID >= 70200) {
23-
$this->markTestSkipped('PHP 7.2 is incompatible with Nette\Object.');
23+
self::markTestSkipped('PHP 7.2 is incompatible with Nette\Object.');
2424
}
2525

2626
$this->analyse([__DIR__ . '/../../data/NetteObjectChild.php'], [

0 commit comments

Comments
 (0)