Skip to content

Commit

Permalink
Merge pull request #770 from UN-OCHA/berliner/HPC-9255
Browse files Browse the repository at this point in the history
HPC-9255: Fix usage of Exception class that is only available using dev composer packages
  • Loading branch information
berliner authored Oct 26, 2023
2 parents eda5c09 + 1b194f8 commit 46e54e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']) {
Expand All @@ -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']));
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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']) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Drupal\ghi_plans\Exceptions;

/**
* Represents an exception for an invalid attachment type.
*/
class InvalidAttachmentTypeException extends \Exception {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Drupal\ghi_plans\ApiObjects\Attachments\FileAttachment;
use Drupal\ghi_plans\ApiObjects\Attachments\IndicatorAttachment;
use Drupal\ghi_plans\ApiObjects\Attachments\TextAttachment;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
use Drupal\ghi_plans\Exceptions\InvalidAttachmentTypeException;

/**
* Helper class for mapping attachment objects.
Expand All @@ -30,7 +30,7 @@ public static function processAttachments(array $attachments) {
try {
$processed[$attachment->id] = self::processAttachment($attachment);
}
catch (InvalidTypeException $e) {
catch (InvalidAttachmentTypeException $e) {
// Ignore this for the moment.
}
}
Expand All @@ -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) {
Expand All @@ -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));
}
}

Expand Down

0 comments on commit 46e54e9

Please sign in to comment.