From 1b194f8d7b6ee4412f2119861befe4160bee5abe Mon Sep 17 00:00:00 2001 From: berliner Date: Thu, 26 Oct 2023 13:25:14 +0200 Subject: [PATCH] HPC-9255: Fix usage of Exception class that is only available using dev composer packages --- .../ApiObjects/Attachments/DataAttachment.php | 18 +++++++++--------- .../InvalidAttachmentTypeException.php | 9 +++++++++ .../ghi_plans/src/Helpers/AttachmentHelper.php | 8 ++++---- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 html/modules/custom/ghi_plans/src/Exceptions/InvalidAttachmentTypeException.php diff --git a/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php b/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php index d21e36b29..123207e36 100644 --- a/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php +++ b/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php @@ -7,13 +7,13 @@ use Drupal\ghi_plans\ApiObjects\AttachmentPrototype\AttachmentPrototype; use Drupal\ghi_plans\ApiObjects\Measurements\Measurement; use Drupal\ghi_plans\Entity\Plan; +use Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException; use Drupal\ghi_plans\Helpers\PlanEntityHelper; use Drupal\ghi_plans\Traits\PlanReportingPeriodTrait; use Drupal\hpc_api\Query\EndpointQuery; use Drupal\hpc_api\Traits\SimpleCacheTrait; use Drupal\hpc_common\Helpers\ArrayHelper; use Drupal\hpc_common\Helpers\ThemeHelper; -use Symfony\Component\Config\Definition\Exception\InvalidTypeException; /** * Abstraction for API data attachment objects. @@ -888,7 +888,7 @@ private static function getEndpointQueryManager() { * The data point value, extracted from the attachment according to the * given configuration. * - * @throws \Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @throws \Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException */ public function getValue(array $conf) { switch ($conf['processing']) { @@ -899,7 +899,7 @@ public function getValue(array $conf) { return $this->getCalculatedValue($conf); default: - throw new InvalidTypeException(sprintf('Unknown processing type: %s', $conf['processing'])); + throw new InvalidAttachmentTypeException(sprintf('Unknown processing type: %s', $conf['processing'])); } } @@ -958,7 +958,7 @@ private function getCalculatedValue(array $conf, array $reporting_periods = NULL break; default: - throw new InvalidTypeException(sprintf('Unknown calculation type: %s', $conf['calculation'])); + throw new InvalidAttachmentTypeException(sprintf('Unknown calculation type: %s', $conf['calculation'])); } return $final_value; @@ -1056,7 +1056,7 @@ public function getLastNonEmptyReportingPeriod($index, $reporting_periods = NULL * The data point value, extracted and formatted from the attachment * according to the given configuration. * - * @throws \Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @throws \Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException */ public function formatValue(array $conf) { // Prepare the build. @@ -1134,7 +1134,7 @@ protected function isMeasurement(array $conf) { * The data point value, extracted and formatted from the attachment * according to the given configuration. * - * @throws \Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @throws \Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException */ private function formatAsText(array $conf) { $value = $this->getValue($conf); @@ -1215,7 +1215,7 @@ private function formatAsText(array $conf) { break; default: - throw new InvalidTypeException(sprintf('Unknown formatting type: %s', $conf['formatting'])); + throw new InvalidAttachmentTypeException(sprintf('Unknown formatting type: %s', $conf['formatting'])); } return $rendered_value; @@ -1231,7 +1231,7 @@ private function formatAsText(array $conf) { * The data point value, extracted and formatted from the attachment * according to the given configuration. * - * @throws \Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @throws \Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException */ private function formatAsWidget(array $conf) { switch ($conf['widget']) { @@ -1252,7 +1252,7 @@ private function formatAsWidget(array $conf) { break; default: - throw new InvalidTypeException(sprintf('Unknown widget type: %s', $conf['widget'])); + throw new InvalidAttachmentTypeException(sprintf('Unknown widget type: %s', $conf['widget'])); } return $widget; diff --git a/html/modules/custom/ghi_plans/src/Exceptions/InvalidAttachmentTypeException.php b/html/modules/custom/ghi_plans/src/Exceptions/InvalidAttachmentTypeException.php new file mode 100644 index 000000000..b02659184 --- /dev/null +++ b/html/modules/custom/ghi_plans/src/Exceptions/InvalidAttachmentTypeException.php @@ -0,0 +1,9 @@ +id] = self::processAttachment($attachment); } - catch (InvalidTypeException $e) { + catch (InvalidAttachmentTypeException $e) { // Ignore this for the moment. } } @@ -46,7 +46,7 @@ public static function processAttachments(array $attachments) { * @return \Drupal\ghi_plans\ApiObjects\Attachments\AttachmentInterface * A single attachment object. * - * @throws \Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @throws \Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException * For unsupported attachment types, an Exception is thrown. */ public static function processAttachment(object $attachment) { @@ -67,7 +67,7 @@ public static function processAttachment(object $attachment) { return new ContactAttachment($attachment); default: - throw new InvalidTypeException(sprintf('Unknown attachment type: %s', $attachment->type)); + throw new InvalidAttachmentTypeException(sprintf('Unknown attachment type: %s', $attachment->type)); } }