Add php code sniffer to follow PSR-12

Also apply ./vendor/bin/phpcbf to auto migrate what is possible.

Relates: #8092
This commit is contained in:
Daniel Siepmann 2021-01-07 08:50:43 +01:00
parent 9bb2b3963c
commit 59272afffd
29 changed files with 255 additions and 184 deletions

View file

@ -1,18 +1,18 @@
<?php
namespace Wrm\Events\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use Wrm\Events\Service\DestinationDataImportService;
class DestinationDataImportCommand extends Command {
class DestinationDataImportCommand extends Command
{
public function configure()
{
@ -31,12 +31,14 @@ class DestinationDataImportCommand extends Command {
'What is the region uid?',
'1'
);
$this->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/'

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Command;
use Symfony\Component\Console\Command\Command;

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Command;
use Symfony\Component\Console\Command\Command;

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Controller;
use Wrm\Events\Domain\Model\Date;

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Controller;
use Wrm\Events\Domain\Model\Dto\EventDemand;
@ -59,7 +60,6 @@ class EventController extends ActionController
$demand = $this->createDemandFromSettings();
$events = $this->eventRepository->findByDemand($demand);
$this->view->assign('events', $events);
}
/**
@ -96,7 +96,6 @@ class EventController extends ActionController
$this->view->assign('search', $search);
$this->view->assign('events', $this->eventRepository->findSearchWord($search));
}
/**

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/**
* Date
*/
@ -83,15 +85,16 @@ class Date 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;
}
}

View file

@ -4,7 +4,8 @@ namespace Wrm\Events\Domain\Model\Dto;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class DateDemand {
class DateDemand
{
/**
* @var string

View file

@ -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;
}
}

View file

@ -1,14 +1,15 @@
<?php
namespace Wrm\Events\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Domain\Model\Category;
use \Wrm\Events\Domain\Repository\DateRepository;
use \TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use Wrm\Events\Domain\Repository\DateRepository;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use \TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* Event
@ -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;
}
}

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/***
*
* This file is part of the "DD Events" Extension for TYPO3 CMS.
@ -273,14 +275,16 @@ class Organizer 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;
}
}

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/***
*
* This file is part of the "DD Events" Extension for TYPO3 CMS.
@ -77,14 +79,16 @@ class Region 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;
}
}

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
@ -67,7 +68,7 @@ class DateRepository extends Repository
$constraints['region'] = $query->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();
}
}

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* This file is part of the TYPO3 CMS project.
*
@ -143,5 +145,4 @@ class EventRepository extends Repository
$query->setLimit(20);
return $query->execute();
}
}

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* This file is part of the TYPO3 CMS project.
*

View file

@ -1,7 +1,9 @@
<?php
namespace Wrm\Events\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* This file is part of the TYPO3 CMS project.
*

View file

@ -15,21 +15,19 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\DataHandling\SlugHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use Wrm\Events\Domain\Repository\DateRepository;
use Wrm\Events\Domain\Repository\EventRepository;
use Wrm\Events\Domain\Repository\OrganizerRepository;
use Wrm\Events\Domain\Repository\RegionRepository;
class DestinationDataImportService {
class DestinationDataImportService
{
/**
* @var
@ -210,7 +208,8 @@ class DestinationDataImportService {
* @param $regionUid
* @param $filesFolder
*/
public function import($restExperience, $storagePid, $regionUid, $filesFolder) {
public function import($restExperience, $storagePid, $regionUid, $filesFolder)
{
$this->restExperience = $restExperience;
$this->storagePid = $storagePid;
@ -244,14 +243,14 @@ class DestinationDataImportService {
$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,11 +394,8 @@ 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']);
@ -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']);
@ -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)
protected function setSocial(array $media)
{
if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook")
foreach ($media as $link) {
if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook") {
$this->tmpCurrentEvent->setFacebook($link['url']);
if ($link['rel'] == "socialmedia" && $link['value'] == "YouTube")
}
if ($link['rel'] == "socialmedia" && $link['value'] == "YouTube") {
$this->tmpCurrentEvent->setYouTube($link['url']);
if ($link['rel'] == "socialmedia" && $link['value'] == "Instagram")
}
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 setTickets(array $media)
{
foreach ($media as $link) {
if ($link['rel'] == "ticket") {
$this->tmpCurrentEvent->setTicket($link['url']);
break;
@ -531,7 +543,8 @@ 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) {
@ -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)
{
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']);
@ -659,7 +673,6 @@ class DestinationDataImportService {
$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';

View file

@ -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 '';
}
}

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Controller;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Controller;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Controller;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Domain\Model;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Domain\Model;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Domain\Model;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Domain\Model;
/**

View file

@ -1,4 +1,5 @@
<?php
namespace Wrm\Events\Tests\Unit\Domain\Model;
/**

View file

@ -27,5 +27,8 @@
"typo3/cms": {
"extension-key": "events"
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5"
}
}

View file

@ -1,9 +1,9 @@
<?php
defined('TYPO3') || die('Access denied.');
call_user_func(
function()
{
function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Events',

View file

@ -1,9 +1,9 @@
<?php
defined('TYPO3') || die('Access denied.');
call_user_func(
function()
{
function () {
/*
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
@ -27,6 +27,5 @@ call_user_func(
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_events_domain_model_region', 'EXT:events/Resources/Private/Language/locallang_csh_tx_events_domain_model_region.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_events_domain_model_region');
}
);

21
phpcs.xml.dist Normal file
View file

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="project">
<description>This project coding standard</description>
<file>Classes/</file>
<file>Tests/</file>
<file>ext_localconf.php</file>
<file>ext_tables.php</file>
<!-- Set default settings -->
<arg value="sp"/>
<arg name="colors"/>
<arg name="encoding" value="utf-8" />
<arg name="extensions" value="php" />
<!-- Base rules -->
<rule ref="PSR12" />
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>/Tests/*</exclude-pattern>
</rule>
</ruleset>