-
-
Notifications
You must be signed in to change notification settings - Fork 926
chore: disable treat phpdoc type as certain for phpstan #7250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ public function create(string $resourceClass, string $property, array $options = | |
|
||
if ($doctrineClassMetadata instanceof ClassMetadata && \in_array($property, $doctrineClassMetadata->getFieldNames(), true)) { | ||
$fieldMapping = $doctrineClassMetadata->getFieldMapping($property); | ||
if (class_exists(FieldMapping::class) && $fieldMapping instanceof FieldMapping) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As soon as |
||
if (class_exists(FieldMapping::class)) { | ||
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping->default ?? $propertyMetadata->getDefault()); | ||
} else { | ||
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping['options']['default'] ?? $propertyMetadata->getDefault()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c | |
$manager = $this->managerRegistry->getManagerForClass($entityClass); | ||
|
||
$repository = $manager->getRepository($entityClass); | ||
if (!method_exists($repository, 'createQueryBuilder')) { // @phpstan-ignore-line function.alreadyNarrowedType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is now no error with treatPhpdocAsCertain: false |
||
if (!method_exists($repository, 'createQueryBuilder')) { | ||
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.'); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
namespace ApiPlatform\Elasticsearch\State; | ||
|
||
use ApiPlatform\Elasticsearch\Serializer\DocumentNormalizer; | ||
use ApiPlatform\Metadata\Exception\RuntimeException; | ||
use ApiPlatform\Metadata\InflectorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\Util\Inflector; | ||
|
@@ -49,9 +48,9 @@ | |
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object | ||
{ | ||
$resourceClass = $operation->getClass(); | ||
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here options was always an Options.
So I rewrite the code to help phpstorm understand it and avoid the false positive for phpstan |
||
$options = $operation->getStateOptions(); | ||
if (!$options instanceof Options) { | ||
throw new RuntimeException(\sprintf('The "%s" provider was called without "%s".', self::class, Options::class)); | ||
$options = new Options(index: $this->getIndex($operation)); | ||
} | ||
|
||
$params = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -909,7 +909,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string | |
|
||
$data = $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext); | ||
$context['data'] = $data; | ||
$context['type'] = ($nullable && $type instanceof Type) ? Type::nullable($type) : $type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already check $type instanceof CollectionType before |
||
$context['type'] = $nullable ? Type::nullable($type) : $type; | ||
|
||
if ($this->tagCollector) { | ||
$this->tagCollector->collect($context); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c | |
throw new UnsupportedMediaTypeHttpException('Format not supported.'); | ||
} | ||
|
||
if ($operation instanceof HttpOperation && null === ($serializerContext[SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE] ?? null)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is
before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've also improved HttpOperation detection recently with 4dc91a0 don't hesitate if you find things that needs type definition improvement (we can always track them in a separated issue) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is another PHPStan failure to fix since the recent symfony release |
||
if (null === ($serializerContext[SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE] ?? null)) { | ||
$method = $operation->getMethod(); | ||
$assignObjectToPopulate = 'POST' === $method | ||
|| 'PATCH' === $method | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
|
||
namespace ApiPlatform\Symfony\EventListener; | ||
|
||
use ApiPlatform\Metadata\HttpOperation; | ||
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; | ||
use ApiPlatform\State\ProviderInterface; | ||
use ApiPlatform\State\SerializerContextBuilderInterface; | ||
|
@@ -62,7 +61,7 @@ public function onKernelRequest(RequestEvent $event): void | |
return; | ||
} | ||
|
||
if (null === $operation->canDeserialize() && $operation instanceof HttpOperation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $this->initializeOperation always returns a HttpOperation and it use native return type. Same idea for all the following |
||
if (null === $operation->canDeserialize()) { | ||
$operation = $operation->withDeserialize(\in_array($method, ['POST', 'PUT', 'PATCH'], true)); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getClassMetadata returns always a ClassMetadata according to the native return type.
Yes, objectManager only has phpdoc for doctrine/persistence < 4, but here we always has a documentManager and this one use native type since 2.0
https://github.com/doctrine/mongodb-odm/blob/cdae04333cc592e3c0d388aa6745d1d486aed6e3/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L282