Code cleanup

This commit is contained in:
Björn Fromme
2019-10-01 20:54:35 +02:00
parent f193fa9419
commit 5c5b722972
3 changed files with 60 additions and 39 deletions
@@ -1,10 +1,32 @@
<?php
namespace EP\EpTheme\Form;
/***************************************************************
*
* Copyright notice
*
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use EP\EpTheme\Service\BookingApiService;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
class BpnApiFinisher extends AbstractFinisher
@@ -22,32 +44,9 @@ class BpnApiFinisher extends AbstractFinisher
$this->bookingApiService = $bookingApiService;
}
/**
* @return string|null
*/
protected function executeInternal()
{
$formValues = $this->finisherContext->getFormValues();
$optionsResolver = new OptionsResolver();
$optionsResolver->setRequired(['lastName', 'firstName', 'gender', 'email']);
$optionsResolver->setDefined([
'lastName', 'firstName', 'gender', 'email', 'street', 'zipCode', 'city', 'phone'
]);
$addressData = [
'lastName' => $formValues['name'],
'firstName' => $formValues['firstName'],
'gender' => $formValues['gender'],
'email' => $formValues['email'],
'street' => $formValues['street'],
'zipCode' => $formValues['zipCode'],
'city' => $formValues['city'],
'phone' => $formValues['phone'],
];
try {
$sanitizedFormData = $optionsResolver->resolve($addressData);
$this->bookingApiService->registerAddress($sanitizedFormData);
}
catch (MissingOptionsException $e) {
}
$this->bookingApiService->registerAddress($formValues);
}
}
@@ -1,7 +1,31 @@
<?php
namespace EP\EpTheme\Service;
/***************************************************************
*
* Copyright notice
*
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\HttpClient\HttpClient;
@@ -45,7 +69,6 @@ class BookingApiService implements SingletonInterface, LoggerAwareInterface
/**
* @param array $addressData
* @throws TransportExceptionInterface
*/
public function registerAddress(array $addressData)
{
@@ -61,8 +84,7 @@ class BookingApiService implements SingletonInterface, LoggerAwareInterface
'body' => json_encode($addressData),
]);
}
catch (\Exception $e)
{
catch (TransportExceptionInterface $e) {
$this->logger->error($e->getMessage());
}
}