Skip to content

Commit

Permalink
Merge pull request #21 from netlogix/feature/rector-update
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanowak authored Jun 17, 2024
2 parents 788a30f + 83a0b5b commit 0bacb59
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 274 deletions.
47 changes: 6 additions & 41 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,23 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 180

# TS/JS-Files
[*.{ts,js}]
indent_size = 2

# JSON-Files
[*.json]
indent_style = tab

# ReST-Files
[*.{rst,rst.txt}]
indent_size = 4
max_line_length = 80

# Markdown-Files
[*.md]
max_line_length = 80
[*.php]
max_line_length = 115

# YAML-Files
[*.{yaml,yml}]
[*.{ts,tsx,js,json}]
indent_size = 2

# NEON-Files
[*.neon]
indent_size = 2
indent_style = tab

# package.json
[package.json]
indent_size = 2

# TypoScript
[*.{typoscript,tsconfig}]
indent_size = 2

# XLF-Files
[*.xlf]
indent_style = tab

# SQL-Files
[*.sql]
indent_style = tab
[{*.yml,*.yaml}]
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab
5 changes: 5 additions & 0 deletions Classes/Command/BatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Netlogix\Nxgooglelocations\Domain\Model\Batch;
use Netlogix\Nxgooglelocations\Domain\Repository\BatchRepository;
use Netlogix\Nxgooglelocations\Enumerations\BatchState;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -15,6 +16,10 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;

#[AsCommand(
name: 'nxgooglelocations:runscheduledjobs',
description: 'Run batch processing for Google Locations'
)]
class BatchCommand extends Command
{
public function __construct(
Expand Down
8 changes: 4 additions & 4 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class ModuleController extends ActionController
{
protected array $pageRecord = [];

protected ?ModuleTemplate $moduleTemplate;
protected ?ModuleTemplate $moduleTemplate = null;

public function __construct(
private readonly ModuleTemplateFactory $moduleTemplateFactory,
Expand Down Expand Up @@ -129,7 +129,7 @@ public function importAction(int $id, bool $deleteUnused, bool $cancelPrevious,
try {
$batch->validate();
} catch (Exception $exception) {
$this->addFlashMessage($exception->getMessage(), '', AbstractMessage::ERROR);
$this->addFlashMessage($exception->getMessage(), '', \TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::ERROR);
return $this->redirect('index');
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public function exportAction(): ResponseInterface
return $this->htmlResponse();
}

public function errorAction(): ResponseInterface
protected function errorAction(): ResponseInterface
{
return $this->getModuleTemplateResponse()
->withStatus(400);
Expand All @@ -174,7 +174,7 @@ protected function forwardToErrorWithCannedMessage(string $reason): ResponseInte
$this->addFlashMessage(
LocalizationUtility::translate(sprintf('module.flash-messages.%s.content', $reason), $extensionName),
LocalizationUtility::translate(sprintf('module.flash-messages.%s.title', $reason), $extensionName),
AbstractMessage::ERROR
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::ERROR
);
return $this->redirect('error');
}
Expand Down
17 changes: 7 additions & 10 deletions Classes/Domain/Model/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class Batch extends AbstractEntity

protected string $fileHash;

protected bool $deleteUnused;

#[TYPO3\Transient]
protected ?BackendUserImpersonator $impersonator = null;

Expand All @@ -51,7 +49,7 @@ class Batch extends AbstractEntity

protected int $geocodingRequests = 0;

protected ?DateTime $tstamp;
protected ?DateTime $tstamp = null;

/**
* @var string[]
Expand All @@ -69,12 +67,11 @@ public function __construct(
protected int $backendUserId,
string $filePath,
string $fileName = '',
bool $deleteUnused = true
protected bool $deleteUnused = true
) {
$this->fileName = pathinfo($fileName ?: $filePath, PATHINFO_BASENAME);
$this->fileContent = base64_encode(file_get_contents(GeneralUtility::getFileAbsFileName($filePath)));
$this->fileHash = sha1($this->fileContent);
$this->deleteUnused = $deleteUnused;
}

public function getFileName(): string
Expand Down Expand Up @@ -161,7 +158,7 @@ protected function collectTcaRecords(): array
return $tcaRecords;
}

protected function executeDataHandler($tcaRecords): void
protected function executeDataHandler(array $tcaRecords): void
{
$backendUserId = $this->backendUserId;
$storagePageId = $this->storagePageId;
Expand Down Expand Up @@ -243,19 +240,19 @@ protected function getLocationFactory(): LocationFactory

protected function initializeServices(): void
{
if (!$this->impersonator) {
if (!$this->impersonator instanceof \Netlogix\Nxgooglelocations\Service\BackendUserImpersonator) {
$this->impersonator = GeneralUtility::makeInstance(BackendUserImpersonator::class);
}

if (!$this->geoCoder) {
if (!$this->geoCoder instanceof \Netlogix\Nxgooglelocations\Service\GeoCoder) {
$this->geoCoder = GeneralUtility::makeInstance($this->serviceClasses[GeoCoder::class], $this->apiKey);
}

if (!$this->importer) {
if (!$this->importer instanceof \Netlogix\Nxgooglelocations\Service\Importer) {
$this->importer = GeneralUtility::makeInstance($this->serviceClasses[Importer::class], $this->storagePageId);
}

if (!$this->locationFactory) {
if (!$this->locationFactory instanceof \Netlogix\Nxgooglelocations\Service\LocationFactory) {
$this->locationFactory = GeneralUtility::makeInstance($this->serviceClasses[LocationFactory::class]);
}
}
Expand Down
12 changes: 6 additions & 6 deletions Classes/Enumerations/BatchState.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ final class BatchState extends Enumeration
/**
* @var string
*/
final public const __default = self::NEW;
public const __default = self::NEW;

/**
* @var string
*/
final public const NEW = 'new';
public const NEW = 'new';

/**
* @var string
*/
final public const VALIDATING = 'validating';
public const VALIDATING = 'validating';

/**
* @var string
*/
final public const GEOCODING = 'running';
public const GEOCODING = 'running';

/**
* @var string
*/
final public const PERSISTING = 'persisting';
public const PERSISTING = 'persisting';

/**
* @var string
*/
final public const CLOSED = 'closed';
public const CLOSED = 'closed';
}
6 changes: 3 additions & 3 deletions Classes/Enumerations/CodingResultProbability.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ final class CodingResultProbability extends Enumeration
/**
* @var int
*/
final public const ZERO_RESULTS = -1;
public const ZERO_RESULTS = -1;

/**
* @var int
*/
final public const MANUALLY_IMPORT = -255;
public const MANUALLY_IMPORT = -255;

/**
* @var int
*/
final public const MANUALLY_EDITOR = -256;
public const MANUALLY_EDITOR = -256;
}
4 changes: 2 additions & 2 deletions Classes/Enumerations/GeoCoderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ final class GeoCoderStatus extends Enumeration
/**
* @var string
*/
final public const OK = 'OK';
public const OK = 'OK';

/**
* @var string
*/
final public const ZERO_RESULTS = 'ZERO_RESULTS';
public const ZERO_RESULTS = 'ZERO_RESULTS';
}
1 change: 1 addition & 0 deletions Classes/Service/ExcelServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
trait ExcelServiceTrait
{
protected ?Worksheet $templateSheet;

protected ?Worksheet $contentSheet;

public function resetTemplateSheet(string $templateFileName): void
Expand Down
14 changes: 3 additions & 11 deletions Classes/Service/GeoCoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@

abstract class GeoCoder
{
/**
* @var string
*/

final public const FETCH_URL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s';

/**
* @var FieldMap
*/
protected $fieldMap;
protected FieldMap $fieldMap;

/**
* @var string
*/
protected $fieldMapClassName = FieldMap::class;
protected string $fieldMapClassName = FieldMap::class;

/**
* The number of geocoding results must be lower than this in order to make an existing
Expand Down
21 changes: 6 additions & 15 deletions Classes/Service/LocationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ abstract class LocationFactory
{
use ExcelServiceTrait;

protected $templateFileName = '/dev/null';
protected string $templateFileName = '/dev/null';

/**
* @var FieldMap
*/
protected $fieldMap;
protected FieldMap $fieldMap;

/**
* @var string
*/
protected $fieldMapClassName = FieldMap::class;
protected string $fieldMapClassName = FieldMap::class;

/**
* @var string
*/
protected $recordTableName = '';
protected string $recordTableName = '';

protected array $columnNameMap = [
'A' => 'title',
Expand All @@ -40,7 +31,7 @@ abstract class LocationFactory
'E' => 'longitude',
];

protected ?Worksheet $templateSheet;
protected ?Worksheet $templateSheet = null;

public function __construct()
{
Expand Down Expand Up @@ -110,7 +101,7 @@ public function writeCoordinatesToTcaRecord(array $tcaRecord, CodingResult $codi
{
$map = ['rawData', 'addressResultFromGeocoding', 'latitude', 'longitude', 'position', 'probability'];
foreach ($map as $fieldName) {
if ($this->fieldMap->__get($fieldName)) {
if ($this->fieldMap->__get($fieldName) !== '' && $this->fieldMap->__get($fieldName) !== '0') {
$tcaRecord[$this->fieldMap->__get($fieldName)] = $codingResult->__get($fieldName);
if (in_array($fieldName, ['rawData', 'position'], true)) {
$tcaRecord[$this->fieldMap->__get($fieldName)] = json_encode(
Expand Down
8 changes: 6 additions & 2 deletions Classes/ViewHelpers/Be/TableListViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class TableListViewHelper extends AbstractBackendViewHelper
* @var bool
*/
protected $escapeOutput = false;

protected ConfigurationManagerInterface $configurationManager;

public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
Expand Down Expand Up @@ -82,7 +83,7 @@ public function initializeArguments(): void
$this->registerArgument(
'readOnly',
'bool',
'if TRUE, the edit icons won\'t be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!',
"if TRUE, the edit icons won't be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!",
false,
false
);
Expand Down Expand Up @@ -118,7 +119,7 @@ protected function render(): string
$clickTitleMode = $this->arguments['clickTitleMode'];
$enableControlPanels = $this->arguments['enableControlPanels'];

$languageService = $this->getLanguageService();
$this->getLanguageService();
$backendUser = $this->getBackendUser();
/** @var RenderingContext $renderingContext */
$renderingContext = $this->renderingContext;
Expand Down Expand Up @@ -161,12 +162,14 @@ protected function render(): string
$dbList->displayRecordDownload = false;
$dbList->setRequest($request);
$dbList->setModuleData($moduleData);

$dbList->pageRow = $pageInfo;
if ($readOnly) {
$dbList->setIsEditable(false);
} else {
$dbList->calcPerms = new Permission($backendUser->calcPerms($pageInfo));
}

$dbList->disableSingleTableView = true;
$dbList->clickTitleMode = $clickTitleMode;
$dbList->clickMenuEnabled = $enableClickMenu;
Expand All @@ -176,6 +179,7 @@ protected function render(): string
);
$storagePid = $frameworkConfiguration['persistence']['storagePid'];
}

$dbList->start($storagePid, $tableName, $pointer, $filter, $levels, $recordsPerPage);
// Column selector is disabled since fields are defined by the "fieldList" argument
$dbList->displayColumnSelector = false;
Expand Down
10 changes: 10 additions & 0 deletions Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;

return [
'ext-nxgooglelocations-batch-type-default'=> [
'provider' => SvgIconProvider::class,
'source' => 'EXT:nxgooglelocations/Resources/Public/Icons/tx_nxgooglelocations_domain_model_batch.svg',
],
];
Loading

0 comments on commit 0bacb59

Please sign in to comment.