From bf6444f4a65236027c956541f105812c9d1ff3a3 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Thu, 25 Jul 2024 23:18:43 +0530 Subject: [PATCH] Fixing phpstan issues. --- src/EventSubscriber/ApqSubscriber.php | 2 +- src/EventSubscriber/OperationSubscriber.php | 2 +- src/GraphQL/Response/ResponseInterface.php | 2 ++ src/GraphQL/Utility/FileUpload.php | 4 ++-- .../DataProducer/Entity/Fields/Image/ImageDerivative.php | 5 +---- tests/src/Kernel/Framework/UploadFileServiceTest.php | 7 ------- 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/EventSubscriber/ApqSubscriber.php b/src/EventSubscriber/ApqSubscriber.php index ada2b53dd..0dcd364e5 100644 --- a/src/EventSubscriber/ApqSubscriber.php +++ b/src/EventSubscriber/ApqSubscriber.php @@ -65,7 +65,7 @@ public function onBeforeOperation(OperationEvent $event): void { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ OperationEvent::GRAPHQL_OPERATION_BEFORE => 'onBeforeOperation', ]; diff --git a/src/EventSubscriber/OperationSubscriber.php b/src/EventSubscriber/OperationSubscriber.php index a79cd94ba..989f07e85 100644 --- a/src/EventSubscriber/OperationSubscriber.php +++ b/src/EventSubscriber/OperationSubscriber.php @@ -73,7 +73,7 @@ public function onAfterOperation(OperationEvent $event): void { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ OperationEvent::GRAPHQL_OPERATION_BEFORE => 'onBeforeOperation', OperationEvent::GRAPHQL_OPERATION_AFTER => 'onAfterOperation', diff --git a/src/GraphQL/Response/ResponseInterface.php b/src/GraphQL/Response/ResponseInterface.php index f83eda7c7..eba425edf 100644 --- a/src/GraphQL/Response/ResponseInterface.php +++ b/src/GraphQL/Response/ResponseInterface.php @@ -4,6 +4,8 @@ namespace Drupal\graphql\GraphQL\Response; +use Symfony\Component\Validator\ConstraintViolationListInterface; + /** * Response interface used for GraphQL responses. */ diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index d2d38f4ca..7d1aff08c 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -520,9 +520,9 @@ protected function prepareFilename(string $filename, array &$validators): string /** @var \Drupal\file\FileInterface $file */ $file = $this->fileStorage->create([]); $file->setFilename($filename); - $passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); + $passes_validation = count($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); } - if (empty($validators['FileExtension']['extensions']) || $passes_validation) { + if (empty($validators['FileExtension']['extensions']) || ($passes_validation > 0)) { if ((substr($filename, -4) != '.txt')) { // The destination filename will also later be used to create the // URI. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php index 277756d48..43ae72580 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php @@ -98,12 +98,9 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable $metadata->addCacheableDependency($access); if ($access->isAllowed() && $image_style = ImageStyle::load($style)) { - // @phpstan-ignore-next-line $width = $entity->width; - // @phpstan-ignore-next-line $height = $entity->height; - - if (empty($width) || empty($height)) { + if (!isset($width) || !isset($height)) { /** @var \Drupal\Core\Image\ImageInterface $image */ $image = \Drupal::service('image.factory')->get($entity->getFileUri()); if ($image->isValid()) { diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index ae2b864ed..dffb9c3a2 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -22,13 +22,6 @@ class UploadFileServiceTest extends GraphQLTestBase { */ protected $uploadService; - /** - * Modules to enable. - * - * @var array - */ - protected static $modules = ['file']; - /** * Gets the file path of the source file. *