Skip to content

Commit

Permalink
Replace AbstractFlashMessage const with enums of ContextualFeedbackSe…
Browse files Browse the repository at this point in the history
…verity
  • Loading branch information
sfroemkenjw committed Oct 27, 2023
1 parent db0e4de commit ca9d187
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 51 deletions.
7 changes: 4 additions & 3 deletions Classes/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use JWeiland\Maps2\Helper\MessageHelper;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;

/**
* Abstract client to send Requests to Map Providers
Expand All @@ -37,21 +38,21 @@ public function processRequest(RequestInterface $request): array
$this->messageHelper->addFlashMessage(
'URI is empty or contains invalid chars. URI: ' . $request->getUri(),
'Invalid request URI',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
return [];
}

$processedResponse = [];
$response = $this->requestFactory->request($request->getUri());
if ($response->getStatusCode() === 200) {
$processedResponse = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$processedResponse = \json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$this->checkResponseForErrors($processedResponse);
} else {
$this->messageHelper->addFlashMessage(
'MapProvider returns a response with a status code different than 200',
'Client Error',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
}

Expand Down
8 changes: 4 additions & 4 deletions Classes/Client/GoogleMapsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace JWeiland\Maps2\Client;

use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
Expand All @@ -27,7 +27,7 @@ protected function checkResponseForErrors(?array $processedResponse): void
$this->messageHelper->addFlashMessage(
'The response of Google Maps was not a valid JSON response.',
'Invalid JSON response',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
} elseif ($processedResponse['status'] !== 'OK') {
if ($processedResponse['status'] === 'ZERO_RESULTS') {
Expand All @@ -43,13 +43,13 @@ protected function checkResponseForErrors(?array $processedResponse): void
'error.noPositionsFound.title',
'maps2'
),
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
} else {
$this->messageHelper->addFlashMessage(
$processedResponse['error_message'],
'Error',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/Client/OpenStreetMapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace JWeiland\Maps2\Client;

use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
Expand All @@ -27,7 +27,7 @@ protected function checkResponseForErrors(?array $processedResponse): void
$this->messageHelper->addFlashMessage(
'The response of Open Street Map was not a valid JSON response.',
'Invalid JSON response',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
} elseif ($processedResponse === []) {
$this->messageHelper->addFlashMessage(
Expand All @@ -42,7 +42,7 @@ protected function checkResponseForErrors(?array $processedResponse): void
'error.noPositionsFound.title',
'maps2'
),
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/CityMapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use JWeiland\Maps2\Domain\Model\Position;
use JWeiland\Maps2\Service\GeoCodeService;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function getPreparedSettings(): array
FlashMessage::class,
'You have forgotten to add maps2 static template for either Google Maps or OpenStreetMap',
'Missing static template',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
));
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/PoiCollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use JWeiland\Maps2\Event\PostProcessFluidVariablesEvent;
use JWeiland\Maps2\Service\GeoCodeService;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function getPreparedSettings(): array
FlashMessage::class,
'You have forgotten to add maps2 static template for either Google Maps or OpenStreetMap',
'Missing static template',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
));
}

Expand Down
12 changes: 6 additions & 6 deletions Classes/Helper/AddressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Doctrine\DBAL\Driver\Exception as DBALException;
use JWeiland\Maps2\Configuration\ExtConf;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -116,7 +116,7 @@ protected function getFallbackCountryName(array $options): string
$this->messageHelper->addFlashMessage(
'We can not find any country information within your extension. Either in Maps2 Registry nor in this record. Please check your configuration or update your extension.',
'No country information found',
AbstractMessage::WARNING
ContextualFeedbackSeverity::WARNING
);

$defaultCountry = $this->extConf->getDefaultCountry();
Expand All @@ -127,7 +127,7 @@ protected function getFallbackCountryName(array $options): string
$this->messageHelper->addFlashMessage(
'Default country in maps2 of extension manager configuration is empty. Request to Google Maps GeoCode will start without any country information, which may lead to curious results.',
'Default country of maps2 is not configured',
AbstractMessage::WARNING
ContextualFeedbackSeverity::WARNING
);

return '';
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function getCountryNameFromStaticCountries(int $uid): string
$this->messageHelper->addFlashMessage(
'Country with UID "' . $uid . '" could not be found in static_countries table. Please check your record for correct country field.',
'Country not found in DB',
AbstractMessage::WARNING
ContextualFeedbackSeverity::WARNING
);

return '';
Expand Down Expand Up @@ -218,7 +218,7 @@ protected function isValidOptionConfiguration(array $options): bool
$this->messageHelper->addFlashMessage(
'Array key "addressColumns" does not exist in your maps2 registration. This field must be filled to prevent creating empty GeoCode requests to google.',
'Key addressColumns is missing',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
return false;
}
Expand All @@ -227,7 +227,7 @@ protected function isValidOptionConfiguration(array $options): bool
$this->messageHelper->addFlashMessage(
'Array key "addressColumns" is a required field in maps2 registraton. Please fill it with column names of your table.',
'Key addressColumns is empty',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);
return false;
}
Expand Down
31 changes: 16 additions & 15 deletions Classes/Helper/MessageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -30,7 +31,7 @@ public function __construct(FlashMessageService $flashMessageService)
$this->flashMessageService = $flashMessageService;
}

public function addFlashMessage(string $message, string $title = '', int $severity = AbstractMessage::OK): void
public function addFlashMessage(string $message, string $title = '', ContextualFeedbackSeverity $severity = ContextualFeedbackSeverity::OK): void
{
// We activate storeInSession, so that messages can be displayed when click on Save&Close button.
$flashMessage = GeneralUtility::makeInstance(
Expand Down Expand Up @@ -62,19 +63,19 @@ public function hasMessages(): bool
}

/**
* @param int $severity Must be one of the constants in AbstractMessage class
* @param ContextualFeedbackSeverity $severity Must be one of the enum values in ContextualFeedbackSeverity class
* @return FlashMessage[]
*/
protected function getFlashMessagesBySeverity(int $severity): array
protected function getFlashMessagesBySeverity(ContextualFeedbackSeverity $severity): array
{
return $this->getFlashMessageQueue()->getAllMessages($severity);
}

/**
* @param int $severity Must be one of the constants in AbstractMessage class
* @param ContextualFeedbackSeverity $severity Must be one of the enum values in ContextualFeedbackSeverity class
* @return FlashMessage[]
*/
public function getFlashMessagesBySeverityAndFlush(int $severity): array
public function getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity $severity): array
{
return $this->getFlashMessageQueue()->getAllMessagesAndFlush($severity);
}
Expand All @@ -90,10 +91,10 @@ public function hasErrorMessages(): bool
public function getErrorMessages(bool $flush = true): array
{
if ($flush) {
return $this->getFlashMessagesBySeverityAndFlush(AbstractMessage::ERROR);
return $this->getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity::ERROR);
}

return $this->getFlashMessagesBySeverity(AbstractMessage::ERROR);
return $this->getFlashMessagesBySeverity(ContextualFeedbackSeverity::ERROR);
}

public function hasWarningMessages(): bool
Expand All @@ -107,10 +108,10 @@ public function hasWarningMessages(): bool
public function getWarningMessages(bool $flush = true): array
{
if ($flush) {
return $this->getFlashMessagesBySeverityAndFlush(AbstractMessage::WARNING);
return $this->getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity::WARNING);
}

return $this->getFlashMessagesBySeverity(AbstractMessage::WARNING);
return $this->getFlashMessagesBySeverity(ContextualFeedbackSeverity::WARNING);
}

public function hasOkMessages(): bool
Expand All @@ -124,10 +125,10 @@ public function hasOkMessages(): bool
public function getOkMessages(bool $flush = true): array
{
if ($flush) {
return $this->getFlashMessagesBySeverityAndFlush(AbstractMessage::OK);
return $this->getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity::OK);
}

return $this->getFlashMessagesBySeverity(AbstractMessage::OK);
return $this->getFlashMessagesBySeverity(ContextualFeedbackSeverity::OK);
}

public function hasInfoMessages(): bool
Expand All @@ -141,10 +142,10 @@ public function hasInfoMessages(): bool
public function getInfoMessages(bool $flush = true): array
{
if ($flush) {
return $this->getFlashMessagesBySeverityAndFlush(AbstractMessage::INFO);
return $this->getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity::INFO);
}

return $this->getFlashMessagesBySeverity(AbstractMessage::INFO);
return $this->getFlashMessagesBySeverity(ContextualFeedbackSeverity::INFO);
}

public function hasNoticeMessages(): bool
Expand All @@ -158,10 +159,10 @@ public function hasNoticeMessages(): bool
public function getNoticeMessages(bool $flush = true): array
{
if ($flush) {
return $this->getFlashMessagesBySeverityAndFlush(AbstractMessage::NOTICE);
return $this->getFlashMessagesBySeverityAndFlush(ContextualFeedbackSeverity::NOTICE);
}

return $this->getFlashMessagesBySeverity(AbstractMessage::NOTICE);
return $this->getFlashMessagesBySeverity(ContextualFeedbackSeverity::NOTICE);
}

protected function getFlashMessageQueue(): FlashMessageQueue
Expand Down
4 changes: 2 additions & 2 deletions Classes/Helper/StoragePidHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -84,7 +84,7 @@ protected function updateStoragePidFromMaps2Registry(
$this->messageHelper->addFlashMessage(
'You have configured a defaultStoragePid in maps2 registration, but returned value is still 0. Please check Maps2 Registry',
'Invalid defaultStoragePid configuration found',
AbstractMessage::WARNING
ContextualFeedbackSeverity::WARNING
);
} else {
$defaultStoragePid = $storagePid;
Expand Down
10 changes: 5 additions & 5 deletions Classes/Hook/CreateMaps2RecordHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

Expand Down Expand Up @@ -412,7 +412,7 @@ protected function createNewMapsRecord(
$this->messageHelper->addFlashMessage(
'While saving this record, we tried to automatically create a new maps2 record, but Map Providers GeoCode API can not find your address: ' . $address,
'Map Provider has not found your address',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);

return false;
Expand Down Expand Up @@ -485,7 +485,7 @@ public function synchronizeColumnsFromForeignRecordWithPoiCollection(
$this->messageHelper->addFlashMessage(
'There are no synchronizationColumns configured in your maps2 registration, so we are using the address as maps2 title',
'Using address as record title',
AbstractMessage::INFO
ContextualFeedbackSeverity::INFO
);

return false;
Expand Down Expand Up @@ -541,7 +541,7 @@ protected function isValidSynchronizeConfiguration(array $synchronizeColumns, st
$this->messageHelper->addFlashMessage(
'Please check your Maps registration. The keys foreignColumnName and poiCollectionColumnName have to be set.',
'Missing registration keys',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);

return false;
Expand All @@ -557,7 +557,7 @@ protected function isValidSynchronizeConfiguration(array $synchronizeColumns, st
$this->messageHelper->addFlashMessage(
'Error while trying to synchronize columns of your record with maps2 record. It seems that "' . $foreignTableName . '" is not registered as table or "' . $foreignColumnName . '" is not a valid column in ' . $foreignTableName,
'Missing table/column in TCA',
AbstractMessage::ERROR
ContextualFeedbackSeverity::ERROR
);

return false;
Expand Down
Loading

0 comments on commit ca9d187

Please sign in to comment.