From 59272afffdb8f0a942b7a5ca00853a6f515ec410 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 7 Jan 2021 08:50:43 +0100 Subject: [PATCH] Add php code sniffer to follow PSR-12 Also apply ./vendor/bin/phpcbf to auto migrate what is possible. Relates: #8092 --- .../Command/DestinationDataImportCommand.php | 14 +- Classes/Command/RemoveAllCommand.php | 1 + Classes/Command/RemovePastCommand.php | 1 + Classes/Controller/DateController.php | 1 + Classes/Controller/EventController.php | 9 +- Classes/Domain/Model/Date.php | 9 +- Classes/Domain/Model/Dto/DateDemand.php | 3 +- Classes/Domain/Model/Dto/EventDemand.php | 8 +- Classes/Domain/Model/Event.php | 74 ++++---- Classes/Domain/Model/Organizer.php | 58 +++--- Classes/Domain/Model/Region.php | 18 +- Classes/Domain/Repository/DateRepository.php | 4 +- Classes/Domain/Repository/EventRepository.php | 5 +- .../Domain/Repository/OrganizerRepository.php | 4 +- .../Domain/Repository/RegionRepository.php | 4 +- .../Service/DestinationDataImportService.php | 177 ++++++++++-------- Classes/ViewHelpers/FormViewHelper.php | 8 +- Tests/Unit/Controller/DateControllerTest.php | 1 + Tests/Unit/Controller/EventControllerTest.php | 1 + .../Unit/Controller/EventsControllerTest.php | 1 + Tests/Unit/Domain/Model/DateTest.php | 1 + Tests/Unit/Domain/Model/EventTest.php | 1 + Tests/Unit/Domain/Model/EventsTest.php | 1 + Tests/Unit/Domain/Model/OrganizerTest.php | 1 + Tests/Unit/Domain/Model/RegionTest.php | 1 + composer.json | 3 + ext_localconf.php | 4 +- ext_tables.php | 5 +- phpcs.xml.dist | 21 +++ 29 files changed, 255 insertions(+), 184 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/Classes/Command/DestinationDataImportCommand.php b/Classes/Command/DestinationDataImportCommand.php index 79e45b1..a26d84a 100644 --- a/Classes/Command/DestinationDataImportCommand.php +++ b/Classes/Command/DestinationDataImportCommand.php @@ -1,18 +1,18 @@ addArgument('rest-experience', + $this->addArgument( + 'rest-experience', InputArgument::OPTIONAL, 'What is the rest experience?', 'stadtmarketing-erfurt' ); - $this->addArgument('files-folder', + $this->addArgument( + 'files-folder', InputArgument::OPTIONAL, 'Where to save the image files?', 'staedte/erfurt/events/' @@ -56,4 +58,4 @@ class DestinationDataImportCommand extends Command { $input->getArgument('files-folder') ); } -} \ No newline at end of file +} diff --git a/Classes/Command/RemoveAllCommand.php b/Classes/Command/RemoveAllCommand.php index 38306ab..0f87879 100644 --- a/Classes/Command/RemoveAllCommand.php +++ b/Classes/Command/RemoveAllCommand.php @@ -1,4 +1,5 @@ createDemandFromSettings(); $events = $this->eventRepository->findByDemand($demand); $this->view->assign('events', $events); - } /** * Action show - * + * * @param Event $event * @return void */ @@ -75,7 +75,7 @@ class EventController extends ActionController /** * action teaser - * + * * @return void */ public function teaserAction() @@ -96,7 +96,6 @@ class EventController extends ActionController $this->view->assign('search', $search); $this->view->assign('events', $this->eventRepository->findSearchWord($search)); - } /** diff --git a/Classes/Domain/Model/Date.php b/Classes/Domain/Model/Date.php index ff3b508..33b017f 100644 --- a/Classes/Domain/Model/Date.php +++ b/Classes/Domain/Model/Date.php @@ -1,7 +1,9 @@ _languageUid = $languageUid; } /** * @return int */ - public function getLanguageUid() { + public function getLanguageUid() + { return $this->_languageUid; } - } diff --git a/Classes/Domain/Model/Dto/DateDemand.php b/Classes/Domain/Model/Dto/DateDemand.php index fe6d447..319b40c 100644 --- a/Classes/Domain/Model/Dto/DateDemand.php +++ b/Classes/Domain/Model/Dto/DateDemand.php @@ -4,7 +4,8 @@ namespace Wrm\Events\Domain\Model\Dto; use TYPO3\CMS\Core\Utility\GeneralUtility; -class DateDemand { +class DateDemand +{ /** * @var string diff --git a/Classes/Domain/Model/Dto/EventDemand.php b/Classes/Domain/Model/Dto/EventDemand.php index 0367554..eb74e00 100644 --- a/Classes/Domain/Model/Dto/EventDemand.php +++ b/Classes/Domain/Model/Dto/EventDemand.php @@ -2,7 +2,8 @@ namespace Wrm\Events\Domain\Model\Dto; -class EventDemand { +class EventDemand +{ /** * @var string @@ -171,7 +172,4 @@ class EventDemand { { $this->limit = $limit; } - - - -} \ No newline at end of file +} diff --git a/Classes/Domain/Model/Event.php b/Classes/Domain/Model/Event.php index bd0e1a8..ab47e24 100644 --- a/Classes/Domain/Model/Event.php +++ b/Classes/Domain/Model/Event.php @@ -1,14 +1,15 @@ * @cascade remove */ @@ -181,21 +182,21 @@ class Event extends AbstractEntity /** * organizer - * + * * @var \Wrm\Events\Domain\Model\Organizer */ protected $organizer = null; /** * region - * + * * @var \Wrm\Events\Domain\Model\Region */ protected $region = null; /** * categories - * + * * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> */ protected $categories; @@ -225,7 +226,7 @@ class Event extends AbstractEntity /** * Returns the globalId - * + * * @return string $globalId */ public function getGlobalId() @@ -481,7 +482,7 @@ class Event extends AbstractEntity /** * @return string $instagram - */ + */ public function getInstagram() { return $this->instagram; @@ -489,12 +490,12 @@ class Event extends AbstractEntity /** * @param string $instagram - */ + */ public function setInstagram(string $instagram) { $this->instagram = $instagram; } - + /** * @return string $latitude */ @@ -606,7 +607,8 @@ class Event extends AbstractEntity * @param ObjectStorage $dates * @return void */ - public function removeAllDates(ObjectStorage $dates) { + public function removeAllDates(ObjectStorage $dates) + { $this->dates->removeAll($dates); } @@ -714,14 +716,16 @@ class Event extends AbstractEntity * @param int $languageUid * @return void */ - public function setLanguageUid($languageUid) { + public function setLanguageUid($languageUid) + { $this->_languageUid = $languageUid; } /** * @return int */ - public function getLanguageUid() { + public function getLanguageUid() + { return $this->_languageUid; } } diff --git a/Classes/Domain/Model/Organizer.php b/Classes/Domain/Model/Organizer.php index 3e4ce2e..0106ed1 100644 --- a/Classes/Domain/Model/Organizer.php +++ b/Classes/Domain/Model/Organizer.php @@ -1,7 +1,9 @@ _languageUid = $languageUid; } /** * @return int */ - public function getLanguageUid() { + public function getLanguageUid() + { return $this->_languageUid; } } diff --git a/Classes/Domain/Model/Region.php b/Classes/Domain/Model/Region.php index eb252b1..0198035 100644 --- a/Classes/Domain/Model/Region.php +++ b/Classes/Domain/Model/Region.php @@ -1,7 +1,9 @@ _languageUid = $languageUid; } /** * @return int */ - public function getLanguageUid() { + public function getLanguageUid() + { return $this->_languageUid; } } diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index e6eb387..5fb5d5c 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -1,4 +1,5 @@ equals('event.region', $demand->getRegion()); } - if ($demand->getHighlight() !== FALSE) { + if ($demand->getHighlight() !== false) { $constraints['highlight'] = $query->equals('event.highlight', $demand->getHighlight()); } @@ -183,5 +184,4 @@ class DateRepository extends Repository return $statement->execute()->fetchAll(); } - } diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index 90331d4..551e08e 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -1,7 +1,9 @@ setLimit(20); return $query->execute(); } - -} \ No newline at end of file +} diff --git a/Classes/Domain/Repository/OrganizerRepository.php b/Classes/Domain/Repository/OrganizerRepository.php index 67f1849..87d7cc2 100644 --- a/Classes/Domain/Repository/OrganizerRepository.php +++ b/Classes/Domain/Repository/OrganizerRepository.php @@ -1,7 +1,9 @@ restExperience = $restExperience; $this->storagePid = $storagePid; @@ -237,21 +236,21 @@ class DestinationDataImportService { $restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&mode=' . $this->restMode . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate; $this->logger->info('Try to get data from ' . $restUrl); - if ($jsonResponse = json_decode(file_get_contents($restUrl),true)) { + if ($jsonResponse = json_decode(file_get_contents($restUrl), true)) { $this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items'); return $this->processData($jsonResponse); } else { $this->logger->error('Could not receive data.'); return 1; } - } /** * @param $data * @return int */ - public function processData($data) { + public function processData($data) + { $this->logger->info('Processing json ' . count($data['items'])); @@ -259,7 +258,6 @@ class DestinationDataImportService { $selectedRegion = $this->regionRepository->findByUid($this->regionUid); foreach ($data['items'] as $event) { - $this->logger->info('Processing event ' . substr($event['title'], 0, 20)); // Event already exists? If not create one! @@ -275,50 +273,59 @@ class DestinationDataImportService { $this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254)); // Set Highlight (Is only set in rest if true) - if($event['highlight']) + if ($event['highlight']) { $this->tmpCurrentEvent->setHighlight($event['highlight']); + } // Set Texts - if($event['texts']) + if ($event['texts']) { $this->setTexts($event['texts']); + } // Set address and geo data - if($event['name'] || $event['street'] || $event['city'] || $event['zip'] || $event['country'] || $event['web']) + if ($event['name'] || $event['street'] || $event['city'] || $event['zip'] || $event['country'] || $event['web']) { $this->setAddress($event); + } // Set LatLng - if($event['geo']['main']['latitude'] && $event['geo']['main']['longitude']) + if ($event['geo']['main']['latitude'] && $event['geo']['main']['longitude']) { $this->setLatLng($event['geo']['main']['latitude'], $event['geo']['main']['longitude']); + } // Set Categories - if($event['categories']) + if ($event['categories']) { $this->setCategories($event['categories']); + } // Set Organizer - if($event['addresses']) + if ($event['addresses']) { $this->setOrganizer($event['addresses']); + } // Set Social - if($event['media_objects']) + if ($event['media_objects']) { $this->setSocial($event['media_objects']); + } // Set Tickets - if($event['media_objects']) + if ($event['media_objects']) { $this->setTickets($event['media_objects']); + } // Set Dates - if($event['timeIntervals']) + if ($event['timeIntervals']) { $this->setDates($event['timeIntervals']); + } // Set Assets - if($event['media_objects']) + if ($event['media_objects']) { $this->setAssets($event['media_objects']); + } // Update and persist $this->logger->info('Persist database'); $this->eventRepository->update($this->tmpCurrentEvent); $this->persistenceManager->persistAll(); - } $this->doSlugUpdate(); $this->logger->info('Finished import'); @@ -329,7 +336,8 @@ class DestinationDataImportService { * * @param array $categories */ - protected function setCategories(Array $categories) { + protected function setCategories(array $categories) + { $sysParentCategory = $this->sysCategoriesRepository->findByUid($this->categoryParentUid); foreach ($categories as $categoryTitle) { $tmpSysCategory = $this->sysCategoriesRepository->findOneByTitle($categoryTitle); @@ -351,7 +359,8 @@ class DestinationDataImportService { * @param array $timeIntervals * @TODO: split into functions */ - protected function setDates(Array $timeIntervals) { + protected function setDates(array $timeIntervals) + { // @TODO: does not seem to work --> //$currentEventDates = $this->tmpCurrentEvent->getDates(); @@ -370,10 +379,8 @@ class DestinationDataImportService { $today = $today->getTimestamp(); foreach ($timeIntervals as $date) { - // Check if dates are given as interval or not if (empty($date['interval'])) { - if (strtotime($date['start']) > $today) { $this->logger->info('Setup single date'); $dateObj = $this->objectManager->get(Date::class); @@ -387,18 +394,15 @@ class DestinationDataImportService { $dateObj->setEnd($end); $this->tmpCurrentEvent->addDate($dateObj); } - } else { - if ($date['freq'] == 'Daily' && empty($date['weekdays']) && !empty($date['repeatUntil'])) { - $this->logger->info('Setup daily interval dates'); $this->logger->info('Start ' . $date['start']); $this->logger->info('End ' . $date['repeatUntil']); $start = new \DateTime($date['start'], new \DateTimeZone($date['tz'])); $until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz'])); - for($i = strtotime($start->format('l'), $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 day', $i)) { + for ($i = strtotime($start->format('l'), $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 day', $i)) { if ($i >= $today) { $eventStart = new \DateTime(); $eventStart->setTimestamp($i); @@ -413,10 +417,7 @@ class DestinationDataImportService { $this->tmpCurrentEvent->addDate($dateObj); } } - - } - - else if ($date['freq'] == 'Weekly' && !empty($date['weekdays']) && !empty($date['repeatUntil'])) { + } elseif ($date['freq'] == 'Weekly' && !empty($date['weekdays']) && !empty($date['repeatUntil'])) { foreach ($date['weekdays'] as $day) { $this->logger->info('Setup weekly interval dates for ' . $day); $this->logger->info('Start ' . $date['start']); @@ -424,7 +425,7 @@ class DestinationDataImportService { $start = new \DateTime($date['start'], new \DateTimeZone($date['tz'])); $until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz'])); - for($i = strtotime($day, $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 week', $i)) { + for ($i = strtotime($day, $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 week', $i)) { if ($i >= $today) { $eventStart = new \DateTime(); $eventStart->setTimestamp($i); @@ -449,9 +450,9 @@ class DestinationDataImportService { /** * @param array $addresses */ - protected function setOrganizer(Array $addresses) { - foreach ($addresses as $address) - { + protected function setOrganizer(array $addresses) + { + foreach ($addresses as $address) { if ($address['rel'] == "organizer") { $tmpOrganizer = $this->organizerRepository->findOneByName($address['name']); if ($tmpOrganizer) { @@ -477,44 +478,55 @@ class DestinationDataImportService { /** * @param array $event */ - protected function setAddress(Array $event) { - if (!empty($event['name'])) + protected function setAddress(array $event) + { + if (!empty($event['name'])) { $this->tmpCurrentEvent->setName($event['name']); - if (!empty($event['street'])) + } + if (!empty($event['street'])) { $this->tmpCurrentEvent->setStreet($event['street']); - if (!empty($event['city'])) + } + if (!empty($event['city'])) { $this->tmpCurrentEvent->setCity($event['city']); - if (!empty($event['zip'])) + } + if (!empty($event['zip'])) { $this->tmpCurrentEvent->setZip($event['zip']); - if (!empty($event['country'])) + } + if (!empty($event['country'])) { $this->tmpCurrentEvent->setCountry($event['country']); - if (!empty($event['phone'])) + } + if (!empty($event['phone'])) { $this->tmpCurrentEvent->setPhone($event['phone']); - if (!empty($event['web'])) + } + if (!empty($event['web'])) { $this->tmpCurrentEvent->setWeb($event['web']); - } - - /** - * @param array $media - */ - protected function setSocial(Array $media) { - foreach ($media as $link) - { - if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook") - $this->tmpCurrentEvent->setFacebook($link['url']); - if ($link['rel'] == "socialmedia" && $link['value'] == "YouTube") - $this->tmpCurrentEvent->setYouTube($link['url']); - if ($link['rel'] == "socialmedia" && $link['value'] == "Instagram") - $this->tmpCurrentEvent->setInstagram($link['url']); } } /** * @param array $media */ - protected function setTickets(Array $media) { - foreach ($media as $link) - { + protected function setSocial(array $media) + { + foreach ($media as $link) { + if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook") { + $this->tmpCurrentEvent->setFacebook($link['url']); + } + if ($link['rel'] == "socialmedia" && $link['value'] == "YouTube") { + $this->tmpCurrentEvent->setYouTube($link['url']); + } + if ($link['rel'] == "socialmedia" && $link['value'] == "Instagram") { + $this->tmpCurrentEvent->setInstagram($link['url']); + } + } + } + + /** + * @param array $media + */ + protected function setTickets(array $media) + { + foreach ($media as $link) { if ($link['rel'] == "ticket") { $this->tmpCurrentEvent->setTicket($link['url']); break; @@ -531,14 +543,15 @@ class DestinationDataImportService { * @param string $needle * @param array $haystack */ - protected function multi_array_key_exists( $needle, $haystack ) { + protected function multi_array_key_exists($needle, $haystack) + { - foreach ( $haystack as $key => $value ) { - if ( $needle == $key ) { + foreach ($haystack as $key => $value) { + if ($needle == $key) { return true; } - if ( is_array( $value ) ) { - if ( $this->multi_array_key_exists( $needle, $value ) == true ) { + if (is_array($value)) { + if ($this->multi_array_key_exists($needle, $value) == true) { return true; } } @@ -550,7 +563,8 @@ class DestinationDataImportService { * @param string $lat * @param string $lng */ - protected function setLatLng(String $lat, String $lng) { + protected function setLatLng(string $lat, string $lng) + { $this->tmpCurrentEvent->setLatitude($lat); $this->tmpCurrentEvent->setLongitude($lng); } @@ -559,9 +573,9 @@ class DestinationDataImportService { * Set Texts * @param Array $texts */ - protected function setTexts(Array $texts) { - foreach ($texts as $text) - { + protected function setTexts(array $texts) + { + foreach ($texts as $text) { if ($text['rel'] == "details" && $text['type'] == "text/plain") { $this->tmpCurrentEvent->setDetails(str_replace('\n\n', '\n', $text['value'])); } @@ -579,7 +593,8 @@ class DestinationDataImportService { * @param String $globalId * @param String $title */ - protected function getOrCreateEvent(String $globalId, String $title) { + protected function getOrCreateEvent(string $globalId, string $title) + { $event = $this->eventRepository->findOneByGlobalId($globalId); @@ -605,16 +620,15 @@ class DestinationDataImportService { /** * @param array $assets */ - protected function setAssets(Array $assets) { + protected function setAssets(array $assets) + { $this->logger->info("Set assets"); $error = false; - foreach ($assets as $media_object) - { - if($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") { - + foreach ($assets as $media_object) { + if ($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") { $this->storage = $this->resourceFactory->getDefaultStorage(); $orgFileUrl = urldecode($media_object['url']); @@ -656,10 +670,9 @@ class DestinationDataImportService { $this->logger->info('No relation found'); $file = $this->storage->getFile($this->filesFolder . $orgFileNameSanitized); $this->metaDataRepository->update($file->getUid(), array('title' => $media_object['value'], 'description' => $media_object['description'], 'alternative' => 'DD Import')); - $this->createFileRelations($file->getUid(), 'tx_events_domain_model_event', $this->tmpCurrentEvent->getUid(), 'images', $this->storagePid); + $this->createFileRelations($file->getUid(), 'tx_events_domain_model_event', $this->tmpCurrentEvent->getUid(), 'images', $this->storagePid); } } - } $error = false; } @@ -670,7 +683,8 @@ class DestinationDataImportService { * @param string $file * @return string */ - protected function loadFile($file) { + protected function loadFile($file) + { $directory = $this->environment->getPublicPath() . "/uploads/tx_events/"; $filename = basename($file); $this->logger->info('Getting file ' . $file . ' as ' . $filename); @@ -692,7 +706,8 @@ class DestinationDataImportService { * @param string $storagePid * @return bool */ - protected function createFileRelations($uid_local, $tablenames, $uid_foreign, $fieldname, $storagePid) { + protected function createFileRelations($uid_local, $tablenames, $uid_foreign, $fieldname, $storagePid) + { $newId = 'NEW1234'; @@ -719,7 +734,7 @@ class DestinationDataImportService { return true; } - foreach($dataHandler->errorLog as $error) { + foreach ($dataHandler->errorLog as $error) { $this->logger->info($error); } return false; diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index 9231214..d7af5f8 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -2,8 +2,10 @@ namespace Wrm\Events\ViewHelpers; -class FormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper { - protected function renderHiddenReferrerFields(){ +class FormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper +{ + protected function renderHiddenReferrerFields() + { return ''; } -} \ No newline at end of file +} diff --git a/Tests/Unit/Controller/DateControllerTest.php b/Tests/Unit/Controller/DateControllerTest.php index e6cfc3c..d9769de 100644 --- a/Tests/Unit/Controller/DateControllerTest.php +++ b/Tests/Unit/Controller/DateControllerTest.php @@ -1,4 +1,5 @@ + + This project coding standard + + Classes/ + Tests/ + ext_localconf.php + ext_tables.php + + + + + + + + + + + /Tests/* + +