Skip to content

Commit

Permalink
PR feedback changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jul 30, 2024
1 parent 0613dbb commit b62295a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/GraphQL/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function addViolation($message, array $properties = []): void {
/**
* {@inheritdoc}
*/
public function addViolations($messages, array $properties = []): void {
public function addViolations(array $messages, array $properties = []): void {
foreach ($messages as $message) {
$this->addViolation($message, $properties);
}
Expand Down
8 changes: 3 additions & 5 deletions src/GraphQL/Response/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Drupal\graphql\GraphQL\Response;

use Symfony\Component\Validator\ConstraintViolationListInterface;

/**
* Response interface used for GraphQL responses.
*/
Expand All @@ -14,7 +12,7 @@ interface ResponseInterface {
/**
* Adds the violation.
*
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup|\Symfony\Component\Validator\ConstraintViolationListInterface $message
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $message
* Violation message.
* @param array $properties
* Other properties related to the violation.
Expand All @@ -24,12 +22,12 @@ public function addViolation($message, array $properties = []): void;
/**
* Adds multiple violations.
*
* @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[]|\Symfony\Component\Validator\ConstraintViolationListInterface $messages
* @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] $messages
* Violation messages.
* @param array $properties
* Other properties related to the violation.
*/
public function addViolations(array|ConstraintViolationListInterface $messages, array $properties = []): void;
public function addViolations(array $messages, array $properties = []): void;

/**
* Gets the violations.
Expand Down
19 changes: 12 additions & 7 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
$file->setSize(@filesize($temp_file_path));

// Validate against fileValidator first with the temporary path.
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */
$errors = $this->fileValidator->validate($file, $validators);
if (count($errors) > 0) {
$response->addViolations($errors);
return $response;
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $file_validate_errors */
$file_validate_errors = $this->fileValidator->validate($file, $validators);
$errors = [];
if (count($file_validate_errors) > 0) {
foreach ($file_validate_errors as $violation) {
$errors[] = $violation->getMessage();
}
}

// Validate Image resolution.
Expand All @@ -294,11 +296,14 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
if (!empty($maxResolution) || !empty($minResolution)) {
$image_resolution_errors = $this->validateFileImageResolution($file, $maxResolution, $minResolution);
if (!empty($image_resolution_errors)) {
$response->addViolations($image_resolution_errors);
return $response;
$errors = array_merge($errors, $image_resolution_errors);
}
}

if (!empty($errors)) {
$response->addViolations($errors);
return $response;
}
$file->setFileUri($file_uri);
// Move the file to the correct location after validation. Use
// FileSystemInterface::EXISTS_ERROR as the file location has already been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
// @phpstan-ignore-next-line
$height = $entity->height;

if (!isset($width) || !isset($height)) {
if ($width == NULL || $height == NULL) {
/** @var \Drupal\Core\Image\ImageInterface $image */
$image = \Drupal::service('image.factory')->get($entity->getFileUri());
if ($image->isValid()) {
Expand Down

0 comments on commit b62295a

Please sign in to comment.