Skip to content

Commit 078b1a6

Browse files
chore: use treat phpdoc type as certain (#7250)
1 parent 7367347 commit 078b1a6

File tree

17 files changed

+18
-31
lines changed

17 files changed

+18
-31
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
- tests
66
- tests/Fixtures/app/console
77
inferPrivatePropertyTypeFromConstructor: true
8+
treatPhpDocTypesAsCertain: false
89
symfony:
910
containerXmlPath: tests/Fixtures/app/var/cache/test/AppKernelTestDebugContainer.xml
1011
constantHassers: false
@@ -107,11 +108,7 @@ parameters:
107108
identifier: property.unusedType
108109
-
109110
identifier: varTag.nativeType
110-
-
111-
identifier: isset.offset
112111
-
113112
identifier: trait.unused
114-
-
115-
identifier: instanceof.alwaysTrue
116113
-
117114
identifier: catch.neverThrown

src/Doctrine/Odm/State/LinksHandlerTrait.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ApiPlatform\State\Util\StateOptionsTrait;
2121
use Doctrine\ODM\MongoDB\Aggregation\Builder;
2222
use Doctrine\ODM\MongoDB\DocumentManager;
23-
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
2423
use Doctrine\Persistence\ManagerRegistry;
2524

2625
/**
@@ -94,10 +93,6 @@ private function buildAggregation(string $toClass, array $links, array $identifi
9493

9594
$classMetadata = $manager->getClassMetadata($aggregationClass);
9695

97-
if (!$classMetadata instanceof ClassMetadata) {
98-
throw new RuntimeException(\sprintf('The class metadata for "%s" must be an instance of "%s".', $aggregationClass, ClassMetadata::class));
99-
}
100-
10196
$aggregation = $previousAggregationBuilder;
10297
if ($aggregationClass !== $previousAggregationClass) {
10398
$aggregation = $manager->createAggregationBuilder($aggregationClass);

src/Doctrine/Orm/Metadata/Property/DoctrineOrmPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function create(string $resourceClass, string $property, array $options =
7070

7171
if ($doctrineClassMetadata instanceof ClassMetadata && \in_array($property, $doctrineClassMetadata->getFieldNames(), true)) {
7272
$fieldMapping = $doctrineClassMetadata->getFieldMapping($property);
73-
if (class_exists(FieldMapping::class) && $fieldMapping instanceof FieldMapping) {
73+
if (class_exists(FieldMapping::class)) {
7474
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping->default ?? $propertyMetadata->getDefault());
7575
} else {
7676
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping['options']['default'] ?? $propertyMetadata->getDefault());

src/Doctrine/Orm/State/CollectionProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5656
$manager = $this->managerRegistry->getManagerForClass($entityClass);
5757

5858
$repository = $manager->getRepository($entityClass);
59-
if (!method_exists($repository, 'createQueryBuilder')) { // @phpstan-ignore-line function.alreadyNarrowedType
59+
if (!method_exists($repository, 'createQueryBuilder')) {
6060
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
6161
}
6262

src/Doctrine/Orm/State/ItemProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6565
}
6666

6767
$repository = $manager->getRepository($entityClass);
68-
if (!method_exists($repository, 'createQueryBuilder')) { // @phpstan-ignore-line function.alreadyNarrowedType
68+
if (!method_exists($repository, 'createQueryBuilder')) {
6969
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
7070
}
7171

src/Elasticsearch/State/ItemProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Elasticsearch\State;
1515

1616
use ApiPlatform\Elasticsearch\Serializer\DocumentNormalizer;
17-
use ApiPlatform\Metadata\Exception\RuntimeException;
1817
use ApiPlatform\Metadata\InflectorInterface;
1918
use ApiPlatform\Metadata\Operation;
2019
use ApiPlatform\Metadata\Util\Inflector;
@@ -49,9 +48,9 @@ public function __construct(
4948
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
5049
{
5150
$resourceClass = $operation->getClass();
52-
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation));
51+
$options = $operation->getStateOptions();
5352
if (!$options instanceof Options) {
54-
throw new RuntimeException(\sprintf('The "%s" provider was called without "%s".', self::class, Options::class));
53+
$options = new Options(index: $this->getIndex($operation));
5554
}
5655

5756
$params = [

src/Metadata/ApiResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ class: $class,
10261026
}
10271027

10281028
/**
1029-
* @return Operations<HttpOperation>
1029+
* @return Operations<HttpOperation>|null
10301030
*/
10311031
public function getOperations(): ?Operations
10321032
{

src/Metadata/Tests/Resource/OperationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testWithResourceTrait(): void
3636

3737
$this->assertSame($operation->getShortName(), 'test');
3838
$this->assertSame($operation->canRead(), false);
39-
$this->assertSame($operation instanceof CollectionOperationInterface, true);
39+
$this->assertInstanceOf(CollectionOperationInterface::class, $operation);
4040
}
4141

4242
#[\PHPUnit\Framework\Attributes\DataProvider('operationProvider')]

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
186186
$openapiAttribute = $operation->getOpenapi();
187187

188188
// Operation ignored from OpenApi
189-
if ($operation instanceof HttpOperation && false === $openapiAttribute) {
189+
if (false === $openapiAttribute) {
190190
continue;
191191
}
192192

@@ -386,7 +386,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
386386
$existingResponses = $openapiOperation->getResponses() ?: [];
387387
$overrideResponses = $operation->getExtraProperties()[self::OVERRIDE_OPENAPI_RESPONSES] ?? $this->openApiOptions->getOverrideResponses();
388388
$errors = null;
389-
if ($operation instanceof HttpOperation && null !== ($errors = $operation->getErrors())) {
389+
if (null !== ($errors = $operation->getErrors())) {
390390
/** @var array<class-string|string, Error> */
391391
$errorOperations = [];
392392
foreach ($errors as $error) {
@@ -629,7 +629,7 @@ private function getLinks(ResourceMetadataCollection $resourceMetadataCollection
629629
}
630630

631631
// Operation ignored from OpenApi
632-
if ($operation instanceof HttpOperation && (false === $operation->getOpenapi() || $operation->getOpenapi() instanceof Webhook)) {
632+
if (false === $operation->getOpenapi() || $operation->getOpenapi() instanceof Webhook) {
633633
continue;
634634
}
635635

src/Serializer/AbstractItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
909909

910910
$data = $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext);
911911
$context['data'] = $data;
912-
$context['type'] = ($nullable && $type instanceof Type) ? Type::nullable($type) : $type;
912+
$context['type'] = $nullable ? Type::nullable($type) : $type;
913913

914914
if ($this->tagCollector) {
915915
$this->tagCollector->collect($context);

0 commit comments

Comments
 (0)