Skip to content

Commit 6b705bd

Browse files
authored
Merge pull request #29 from jtojnar/ci-fix
Fix CI
2 parents 3d285dd + 3d7fdf1 commit 6b705bd

17 files changed

+80
-583
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: monthly
7+
open-pull-requests-limit: 20

.github/workflows/build.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
php-version: [ '7.1', '7.2', '7.3', '7.4', '8.0' ]
20+
php-version: [ '8.1', '8.2' ]
2121
deps: [ 'lowest', 'newest' ]
2222
exclude:
23-
- php-version: '7.2'
24-
deps: lowest
25-
- php-version: '7.3'
26-
deps: lowest
27-
- php-version: '7.4'
28-
deps: lowest
29-
- php-version: '8.0'
23+
- php-version: '8.1'
3024
deps: lowest
3125

3226
runs-on: ubuntu-latest

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"MIT"
77
],
88
"require": {
9-
"php": "~7.1 || ~8.0",
10-
"phpstan/phpstan": "^1.0"
9+
"php": "~8.1",
10+
"phpstan/phpstan": "^1.10"
1111
},
1212
"require-dev": {
1313
"phpstan/extension-installer": "^1.1",
1414
"phpstan/phpstan-deprecation-rules": "^1.0",
15-
"nextras/orm": "~4.0 || ~5.0@dev",
15+
"nextras/orm": "~5.0@dev",
1616
"nette/tester": "^2.3.1"
1717
},
1818
"autoload": {
@@ -35,6 +35,12 @@
3535
}
3636
},
3737
"scripts": {
38+
"phpstan": "phpstan analyze",
3839
"tests": "tester ./tests/test.php && phpstan analyze"
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"phpstan/extension-installer": true
44+
}
3945
}
4046
}

extension.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
services:
2-
-
3-
class: Nextras\OrmPhpStan\Types\CollectionReturnTypeExtension
4-
tags:
5-
- phpstan.broker.dynamicMethodReturnTypeExtension
6-
-
7-
class: Nextras\OrmPhpStan\Types\MapperMethodReturnTypeExtension
8-
tags:
9-
- phpstan.broker.dynamicMethodReturnTypeExtension
10-
-
11-
class: Nextras\OrmPhpStan\Types\RelationshipReturnTypeExtension
12-
tags:
13-
- phpstan.broker.dynamicMethodReturnTypeExtension
14-
-
15-
class: Nextras\OrmPhpStan\Types\RepositoryReturnTypeExtension
16-
tags:
17-
- phpstan.broker.dynamicMethodReturnTypeExtension
182
-
193
class: Nextras\OrmPhpStan\Reflection\EntityRelationshipPropertyReflectionExtension
204
tags:
@@ -27,5 +11,3 @@ services:
2711
class: Nextras\OrmPhpStan\Rules\SetValueMethodRule
2812
tags:
2913
- phpstan.rules.rule
30-
31-
- Nextras\OrmPhpStan\Types\Helpers\RepositoryEntityTypeHelper(@currentPhpVersionSimpleDirectParser)

src/Rules/SetValueMethodRule.php

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Expr\MethodCall;
88
use PHPStan\Analyser\Scope;
9-
use PHPStan\Broker\Broker;
109
use PHPStan\Reflection\ClassReflection;
1110
use PHPStan\Reflection\ReflectionProvider;
1211
use PHPStan\Rules\Rule;
13-
use PHPStan\Type\TypeWithClassName;
1412
use PHPStan\Type\VerbosityLevel;
1513

14+
1615
/**
1716
* @phpstan-implements Rule<MethodCall>
1817
*/
@@ -60,53 +59,59 @@ public function processNode(Node $node, Scope $scope): array
6059

6160
$valueType = $scope->getType($args[1]->value);
6261
$varType = $scope->getType($node->var);
63-
if (!$varType instanceof TypeWithClassName) {
62+
$classNames = $varType->getObjectClassNames();
63+
if (count($classNames) < 1) {
6464
return [];
6565
}
6666

6767
$firstValue = $args[0]->value;
6868
if (!$firstValue instanceof Node\Scalar\String_) {
6969
return [];
7070
}
71-
7271
$fieldName = $firstValue->value;
73-
$class = $this->reflectionProvider->getClass($varType->getClassName());
74-
$interfaces = array_map(function (ClassReflection $interface) {
75-
return $interface->getName();
76-
}, $class->getInterfaces());
77-
if (!in_array(IEntity::class, $interfaces, true)) {
78-
return [];
79-
}
80-
81-
if (!$class->hasProperty($fieldName)) {
82-
return [sprintf(
83-
'Entity %s has no $%s property.',
84-
$varType->getClassName(),
85-
$fieldName
86-
)];
87-
}
88-
89-
$property = $class->getProperty($fieldName, $scope);
90-
$propertyType = $property->getWritableType();
91-
92-
if (!$propertyType->accepts($valueType, true)->yes()) {
93-
return [sprintf(
94-
'Entity %s: property $%s (%s) does not accept %s.',
95-
$varType->getClassName(),
96-
$fieldName,
97-
$propertyType->describe(VerbosityLevel::typeOnly()),
98-
$valueType->describe(VerbosityLevel::typeOnly())
99-
)];
100-
}
10172

102-
if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') {
103-
return [sprintf(
104-
'Entity %s: property $%s is read-only.',
105-
$varType->getClassName(),
106-
$fieldName
107-
)];
73+
$errors = [];
74+
foreach ($classNames as $className) {
75+
$class = $this->reflectionProvider->getClass($className);
76+
$interfaces = array_map(function (ClassReflection $interface) {
77+
return $interface->getName();
78+
}, $class->getInterfaces());
79+
if (!in_array(IEntity::class, $interfaces, true)) {
80+
continue;
81+
}
82+
83+
if (!$class->hasProperty($fieldName)) {
84+
$errors[] = sprintf(
85+
'Entity %s has no $%s property.',
86+
$className,
87+
$fieldName
88+
);
89+
continue;
90+
}
91+
92+
$property = $class->getProperty($fieldName, $scope);
93+
$propertyType = $property->getWritableType();
94+
95+
if (!$propertyType->accepts($valueType, true)->yes()) {
96+
$errors[] = sprintf(
97+
'Entity %s: property $%s (%s) does not accept %s.',
98+
$className,
99+
$fieldName,
100+
$propertyType->describe(VerbosityLevel::typeOnly()),
101+
$valueType->describe(VerbosityLevel::typeOnly())
102+
);
103+
continue;
104+
}
105+
106+
if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') {
107+
$errors[] = sprintf(
108+
'Entity %s: property $%s is read-only.',
109+
$className,
110+
$fieldName
111+
);
112+
}
108113
}
109114

110-
return [];
115+
return $errors;
111116
}
112117
}

src/Types/CollectionReturnTypeExtension.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/Types/Helpers/RepositoryEntityTypeHelper.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)