Skip to content

Commit 3912e20

Browse files
authored
Merge branch 'master' into generic-query
2 parents 2abd21c + 9f40e7f commit 3912e20

27 files changed

+634
-72
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ jobs:
1414
runs-on: "ubuntu-latest"
1515

1616
strategy:
17+
fail-fast: false
1718
matrix:
1819
php-version:
1920
- "7.1"
2021
- "7.2"
2122
- "7.3"
2223
- "7.4"
2324
- "8.0"
25+
- "8.1"
2426

2527
steps:
2628
- name: "Checkout"
@@ -35,12 +37,16 @@ jobs:
3537
- name: "Validate Composer"
3638
run: "composer validate"
3739

38-
- name: "Install dependencies"
39-
run: "composer install --no-interaction --no-progress --no-suggest"
40-
4140
- name: "Downgrade PHPUnit"
4241
if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3'
43-
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"
42+
run: "composer require --dev phpunit/phpunit:^7.5.20 --no-update --update-with-dependencies"
43+
44+
- name: "Downgrade Doctrine ORM"
45+
if: matrix.php-version == '7.1'
46+
run: "composer require --dev doctrine/orm:^2.7.5 doctrine/lexer:^1.0 --no-update --update-with-dependencies"
47+
48+
- name: "Install dependencies"
49+
run: "composer install --no-interaction --no-progress"
4450

4551
- name: "Lint"
4652
run: "make lint"
@@ -64,7 +70,7 @@ jobs:
6470
run: "composer validate"
6571

6672
- name: "Install dependencies"
67-
run: "composer install --no-interaction --no-progress --no-suggest"
73+
run: "composer install --no-interaction --no-progress"
6874

6975
- name: "Lint"
7076
run: "make lint"
@@ -85,6 +91,7 @@ jobs:
8591
- "7.3"
8692
- "7.4"
8793
- "8.0"
94+
- "8.1"
8895
dependencies:
8996
- "lowest"
9097
- "highest"
@@ -99,17 +106,21 @@ jobs:
99106
coverage: "none"
100107
php-version: "${{ matrix.php-version }}"
101108

109+
- name: "Downgrade PHPUnit"
110+
if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3'
111+
run: "composer require --dev phpunit/phpunit:^7.5.20 --no-update --update-with-dependencies"
112+
113+
- name: "Downgrade Doctrine ORM"
114+
if: matrix.php-version == '7.1'
115+
run: "composer require --dev doctrine/orm:^2.7.5 doctrine/lexer:^1.0 --no-update --update-with-dependencies"
116+
102117
- name: "Install lowest dependencies"
103118
if: ${{ matrix.dependencies == 'lowest' }}
104-
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
119+
run: "composer update --prefer-lowest --no-interaction --no-progress"
105120

106121
- name: "Install highest dependencies"
107122
if: ${{ matrix.dependencies == 'highest' }}
108-
run: "composer update --no-interaction --no-progress --no-suggest"
109-
110-
- name: "Downgrade PHPUnit"
111-
if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3'
112-
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"
123+
run: "composer update --no-interaction --no-progress"
113124

114125
- name: "Tests"
115126
run: "make tests"
@@ -127,6 +138,7 @@ jobs:
127138
- "7.3"
128139
- "7.4"
129140
- "8.0"
141+
- "8.1"
130142
dependencies:
131143
- "lowest"
132144
- "highest"
@@ -143,17 +155,21 @@ jobs:
143155
extensions: mbstring
144156
tools: composer:v2
145157

158+
- name: "Downgrade PHPUnit"
159+
if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3'
160+
run: "composer require --dev phpunit/phpunit:^7.5.20 --no-update --update-with-dependencies"
161+
162+
- name: "Downgrade Doctrine ORM"
163+
if: matrix.php-version == '7.1'
164+
run: "composer require --dev doctrine/orm:^2.7.5 doctrine/lexer:^1.0 --no-update --update-with-dependencies"
165+
146166
- name: "Install lowest dependencies"
147167
if: ${{ matrix.dependencies == 'lowest' }}
148-
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
168+
run: "composer update --prefer-lowest --no-interaction --no-progress"
149169

150170
- name: "Install highest dependencies"
151171
if: ${{ matrix.dependencies == 'highest' }}
152-
run: "composer update --no-interaction --no-progress --no-suggest"
153-
154-
- name: "Downgrade PHPUnit"
155-
if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3'
156-
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"
172+
run: "composer update --no-interaction --no-progress"
157173

158174
- name: "PHPStan"
159175
run: "make phpstan"

build-cs/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"consistence-community/coding-standard": "^3.10",
44
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
55
"slevomat/coding-standard": "^6.4"
6+
},
7+
"config": {
8+
"allow-plugins": {
9+
"dealerdirect/phpcodesniffer-composer-installer": true
10+
}
611
}
712
}

composer.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.1 || ^8.0",
10-
"phpstan/phpstan": "^1.0"
10+
"phpstan/phpstan": "^1.3"
1111
},
1212
"conflict": {
1313
"doctrine/collections": "<1.0",
@@ -21,23 +21,28 @@
2121
"doctrine/collections": "^1.6",
2222
"doctrine/common": "^2.7 || ^3.0",
2323
"doctrine/dbal": "^2.13.1",
24+
"doctrine/lexer": "^1.2.1",
2425
"doctrine/mongodb-odm": "^1.3 || ^2.1",
2526
"doctrine/orm": "^2.9.1",
2627
"doctrine/persistence": "^1.1 || ^2.0",
2728
"nesbot/carbon": "^2.49",
28-
"nikic/php-parser": "^4.13.0",
29+
"nikic/php-parser": "^4.13.2",
2930
"php-parallel-lint/php-parallel-lint": "^1.2",
3031
"phpstan/phpstan-phpunit": "^1.0",
3132
"phpstan/phpstan-strict-rules": "^1.0",
32-
"phpunit/phpunit": "^9.5",
33-
"ramsey/uuid-doctrine": "^1.5.0"
33+
"phpunit/phpunit": "^9.5.10",
34+
"ramsey/uuid-doctrine": "^1.5.0",
35+
"symfony/cache": "^4.4.35"
3436
},
3537
"config": {
3638
"platform": {
37-
"php": "7.3.24",
38-
"ext-mongo": "1.6.16"
39+
"ext-mongo": "1.12",
40+
"ext-mongodb": "1.6.16"
3941
},
40-
"sort-packages": true
42+
"sort-packages": true,
43+
"allow-plugins": {
44+
"composer/package-versions-deprecated": true
45+
}
4146
},
4247
"extra": {
4348
"branch-alias": {

extension.neon

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ parameters:
99
# setting this to false might lead to performance problems
1010
# it changes the braching logic - with false, queryBuilders from all branches are analysed separately
1111
queryBuilderFastAlgorithm: true
12+
featureToggles:
13+
skipCheckGenericClasses:
14+
- Doctrine\ODM\MongoDB\Mapping\ClassMetadata
15+
- Doctrine\ORM\Mapping\ClassMetadata
16+
- Doctrine\ORM\Mapping\ClassMetadataInfo
17+
- Doctrine\Persistence\Mapping\ClassMetadata
1218
stubFiles:
13-
- stubs/ClassMetadataInfo.stub
1419
- stubs/Criteria.stub
1520
- stubs/DocumentManager.stub
1621
- stubs/DocumentRepository.stub
@@ -20,6 +25,7 @@ parameters:
2025
- stubs/EntityRepository.stub
2126
- stubs/ServiceEntityRepository.stub
2227
- stubs/MongoClassMetadataInfo.stub
28+
2329
- stubs/Persistence/ManagerRegistry.stub
2430
- stubs/Persistence/ObjectManager.stub
2531
- stubs/Persistence/ObjectManagerDecorator.stub
@@ -30,7 +36,10 @@ parameters:
3036
- stubs/Collections/Selectable.stub
3137
- stubs/ORM/QueryBuilder.stub
3238
- stubs/ORM/AbstractQuery.stub
33-
- stubs/ORM/Query.stub
39+
- stubs/ORM/Mapping/ClassMetadata.stub
40+
- stubs/ORM/Mapping/ClassMetadataInfo.stub
41+
- stubs/ORM/Query.stub
42+
- stubs/Persistence/Mapping/ClassMetadata.stub
3443
- stubs/ServiceDocumentRepository.stub
3544

3645
parametersSchema:

phpstan-baseline.neon

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

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
includes:
22
- extension.neon
33
- rules.neon
4-
- phpstan-baseline.neon
54
- vendor/phpstan/phpstan-strict-rules/rules.neon
65
- vendor/phpstan/phpstan-phpunit/extension.neon
76
- vendor/phpstan/phpstan-phpunit/rules.neon
@@ -10,6 +9,7 @@ includes:
109
parameters:
1110
excludePaths:
1211
- tests/*/data/*
12+
- tests/*/data-php-*/*
1313

1414
ignoreErrors:
1515
-

src/Rules/Doctrine/ORM/PropertiesExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function isAlwaysRead(PropertyReflection $property, string $propertyName)
3030

3131
/**
3232
* @param class-string $className
33+
* @return \Doctrine\ORM\Mapping\ClassMetadataInfo<object>
3334
*/
3435
private function findMetadata(string $className): ?\Doctrine\ORM\Mapping\ClassMetadataInfo
3536
{

src/Type/Doctrine/ObjectMetadataResolver.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Doctrine\Persistence\ObjectManager;
66
use PHPStan\Reflection\ReflectionProvider;
7-
use function file_exists;
7+
use function is_file;
88
use function is_readable;
99

1010
final class ObjectMetadataResolver
@@ -60,11 +60,18 @@ public function getObjectManager(): ?ObjectManager
6060

6161
private function loadObjectManager(string $objectManagerLoader): ?ObjectManager
6262
{
63-
if (
64-
!file_exists($objectManagerLoader)
65-
|| !is_readable($objectManagerLoader)
66-
) {
67-
throw new \PHPStan\ShouldNotHappenException('Object manager could not be loaded');
63+
if (!is_file($objectManagerLoader)) {
64+
throw new \PHPStan\ShouldNotHappenException(sprintf(
65+
'Object manager could not be loaded: file "%s" does not exist',
66+
$objectManagerLoader
67+
));
68+
}
69+
70+
if (!is_readable($objectManagerLoader)) {
71+
throw new \PHPStan\ShouldNotHappenException(sprintf(
72+
'Object manager could not be loaded: file "%s" is not readable',
73+
$objectManagerLoader
74+
));
6875
}
6976

7077
return require $objectManagerLoader;
@@ -108,14 +115,14 @@ public function getRepositoryClass(string $className): string
108115

109116
$ormMetadataClass = 'Doctrine\ORM\Mapping\ClassMetadata';
110117
if ($metadata instanceof $ormMetadataClass) {
111-
/** @var \Doctrine\ORM\Mapping\ClassMetadata $ormMetadata */
118+
/** @var \Doctrine\ORM\Mapping\ClassMetadata<object> $ormMetadata */
112119
$ormMetadata = $metadata;
113120
return $ormMetadata->customRepositoryClassName ?? $this->getResolvedRepositoryClass();
114121
}
115122

116123
$odmMetadataClass = 'Doctrine\ODM\MongoDB\Mapping\ClassMetadata';
117124
if ($metadata instanceof $odmMetadataClass) {
118-
/** @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $odmMetadata */
125+
/** @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata<object> $odmMetadata */
119126
$odmMetadata = $metadata;
120127
return $odmMetadata->customRepositoryClassName ?? $this->getResolvedRepositoryClass();
121128
}

src/Type/Doctrine/QueryBuilder/QueryBuilderMethodDynamicReturnTypeExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private function findClassNode(string $className, array $nodes): ?Class_
210210
foreach ($nodes as $node) {
211211
if (
212212
$node instanceof Class_
213+
&& $node->namespacedName !== null
213214
&& $node->namespacedName->toString() === $className
214215
) {
215216
return $node;

stubs/ClassMetadataInfo.stub

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

stubs/MongoClassMetadataInfo.stub

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,40 @@
22

33
namespace Doctrine\ODM\MongoDB\Mapping;
44

5-
class ClassMetadata
5+
use Doctrine\Persistence\Mapping\ClassMetadata as BaseClassMetadata;
6+
use ReflectionClass;
7+
8+
/**
9+
* @template-covariant T of object
10+
* @template-implements BaseClassMetadata<T>
11+
*/
12+
class ClassMetadata implements BaseClassMetadata
613
{
714

815
/** @var string|null */
916
public $customRepositoryClassName;
1017

18+
/**
19+
* @var class-string<T>
20+
*/
21+
public $name;
22+
23+
/**
24+
* @param class-string<T> $documentName
25+
*/
26+
public function __construct(string $documentName)
27+
{
28+
29+
}
30+
31+
/**
32+
* @return class-string<T>
33+
*/
34+
public function getName();
35+
36+
/**
37+
* @return ReflectionClass<T>
38+
*/
39+
public function getReflectionClass();
40+
1141
}

stubs/ORM/Mapping/ClassMetadata.stub

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Doctrine\ORM\Mapping;
4+
5+
/**
6+
* @template-covariant T of object
7+
* @extends ClassMetadataInfo<T>
8+
*/
9+
class ClassMetadata extends ClassMetadataInfo
10+
{
11+
/**
12+
* @param class-string<T> $entityName
13+
*/
14+
public function __construct($entityName)
15+
{
16+
17+
}
18+
}

0 commit comments

Comments
 (0)