Skip to content

Commit

Permalink
[TASK] Rector all the things!
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrodala committed Mar 25, 2024
1 parent 15acfd3 commit fc1ba8d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 57 deletions.
6 changes: 1 addition & 5 deletions Classes/Controller/FileVariantsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
class FileVariantsController
{
/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function ajaxResetFileVariant(ServerRequestInterface $request): ResponseInterface
Expand Down Expand Up @@ -101,7 +100,7 @@ public function ajaxResetFileVariant(ServerRequestInterface $request): ResponseI
->getQueryBuilderForTable('sys_file_metadata');
$queryBuilder->delete('sys_file_metadata')->where(
$queryBuilder->expr()
->in('uid', $metadataRecordsToBeDeleted, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY)
->in('uid', $metadataRecordsToBeDeleted)
)->execute();
}

Expand All @@ -116,7 +115,6 @@ public function ajaxResetFileVariant(ServerRequestInterface $request): ResponseI
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function ajaxReplaceFileVariant(ServerRequestInterface $request): ResponseInterface
Expand All @@ -125,7 +123,6 @@ public function ajaxReplaceFileVariant(ServerRequestInterface $request): Respons
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function ajaxUploadFileVariant(ServerRequestInterface $request): ResponseInterface
Expand Down Expand Up @@ -181,7 +178,6 @@ public function ajaxUploadFileVariant(ServerRequestInterface $request): Response
/**
* Returns an absolute file path to the given File resource
*
* @param File $file
* @return string
*/
protected function getAbsolutePathToFile(File $file): string
Expand Down
13 changes: 2 additions & 11 deletions Classes/DataHandler/DataHandlerHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public function __construct()
*
* replaces the uid of the default language sys_file record uid with the translated one
*
* @param string $status
* @param string $table
* @param $id
* @param array $fieldArray
*/
public function processDatamap_postProcessFieldArray(string $status, string $table, $id, array &$fieldArray)
{
Expand All @@ -85,17 +82,14 @@ public function processDatamap_postProcessFieldArray(string $status, string $tab
}

/**
* @param string $command
* @param string $table
* @param string|int $id recordUid
* @param mixed $value Command Value
* @param DataHandler $pObj
*/
public function processCmdmap_postProcess(
string $command,
string $table,
$id,
$value,
mixed $value,
DataHandler $pObj
) {

Expand Down Expand Up @@ -173,12 +167,11 @@ public function processCmdmap_postProcess(

/**
* @param string|int $id
* @param DataHandler $pObj
* @return int
*/
protected function substNewWithId($id, DataHandler $pObj): int
{
if (is_string($id) && strpos($id, 'NEW') !== false) {
if (is_string($id) && str_contains($id, 'NEW')) {
$id = $pObj->substNEWwithIDs[$id] ?? null;
}
if ($id === null) {
Expand All @@ -188,8 +181,6 @@ protected function substNewWithId($id, DataHandler $pObj): int
}

/**
* @param int $sys_language_uid
* @param int $currentFileId
* @return int
*/
protected function findLanguageVariantForLanguageAndParentFile(int $sys_language_uid, int $currentFileId): int
Expand Down
16 changes: 5 additions & 11 deletions Classes/Service/ResourcesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\ResourceStorageInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

Expand All @@ -48,15 +49,15 @@ public function prepareFileStorageEnvironment(): FolderInterface
/** @var ResourcesService $resourcesService */
$targetFolder = $extensionConfiguration['variantsFolder'];
try {
/** @var \TYPO3\CMS\Core\Resource\ResourceStorageInterface storage */
/** @var ResourceStorageInterface storage */
$storage = $this->retrieveStorageObject($storageUid);

if (!$storage->hasFolder($targetFolder)) {
$folder = $storage->createFolder($targetFolder);
} else {
$folder = $storage->getFolder($targetFolder);
}
} catch (\InvalidArgumentException $exception) {
} catch (\InvalidArgumentException) {
throw new \RuntimeException(
'storage with uid ' . $storageUid . ' is not available. Create it and check the given uid in extension configuration.',
1490480372
Expand All @@ -66,7 +67,6 @@ public function prepareFileStorageEnvironment(): FolderInterface
}

/**
* @param int $uid
* @return ResourceStorage
*/
protected function retrieveStorageObject(int $uid): ResourceStorage
Expand All @@ -79,7 +79,7 @@ protected function retrieveStorageObject(int $uid): ResourceStorage
} else {
try {
$storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($uid);
} catch (\Exception $e) {
} catch (\Exception) {
throw new \InvalidArgumentException('Storage with uid ' . $uid . ' is not available. Create it and/or adapt the extension configuration.', 1490480372);
}
}
Expand All @@ -88,9 +88,6 @@ protected function retrieveStorageObject(int $uid): ResourceStorage
}

/**
* @param int $fileUid
* @param int $width
* @param int $height
* @param $css_class
* @return string generatedHtml
*/
Expand All @@ -102,7 +99,7 @@ public function generatePreviewImageHtml(int $fileUid, $css_class = 't3-tceforms
$content = '';
if ($file->isMissing()) {
$content .= '<span class="label label-danger label-space-right">'
. htmlspecialchars(LocalizationUtility::translate(
. htmlspecialchars((string) LocalizationUtility::translate(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing',
'core'
))
Expand All @@ -119,8 +116,6 @@ public function generatePreviewImageHtml(int $fileUid, $css_class = 't3-tceforms

/**
* @param int $sys_language_uid
* @param array $metaDataRecord
* @param FolderInterface $folder
*/
public function copyOriginalFileAndUpdateAllConsumingReferencesToUseTheCopy(
$sys_language_uid,
Expand Down Expand Up @@ -186,7 +181,6 @@ public function copyOriginalFileAndUpdateAllConsumingReferencesToUseTheCopy(
* Filters away irrelevant tables and checks for free mode in tt_content records
* everything else is a valid reference in context of file variants update
*
* @param int $uid
* @return bool
*/
protected function isValidReference(int $uid): bool
Expand Down
2 changes: 1 addition & 1 deletion Classes/Updates/MetaDataRecordsUpdateWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MetaDataRecordsUpdateWizard implements UpgradeWizardInterface
*/
public function getIdentifier(): string
{
return __CLASS__;
return self::class;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/Overrides/manipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file that was distributed with this source code.
*/

defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

call_user_func(function () {

Expand Down
10 changes: 6 additions & 4 deletions Configuration/TCA/Overrides/sys_file.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/*
* This file is part of the package t3g/file_variants.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

call_user_func(function () {
$tempColumns = [
'sys_language_uid' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
'config' => version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11', '>') ? [
'config' => version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11', '>') ? [
'type' => 'language',
] : [
'type' => 'select',
Expand Down Expand Up @@ -54,8 +56,8 @@
],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $tempColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', 'sys_language_uid, l10n_parent');
ExtensionManagementUtility::addTCAcolumns('sys_file', $tempColumns);
ExtensionManagementUtility::addToAllTCAtypes('sys_file', 'sys_language_uid, l10n_parent');

$GLOBALS['TCA']['sys_file']['ctrl']['languageField'] = 'sys_language_uid';
$GLOBALS['TCA']['sys_file']['ctrl']['transOrigPointerField'] = 'l10n_parent';
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/Overrides/sys_file_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file that was distributed with this source code.
*/

defined('TYPO3_MODE') or die();
defined('TYPO3') or die();

call_user_func(function () {
$GLOBALS['TCA']['sys_file_metadata']['ctrl']['container'] = [
Expand Down
4 changes: 1 addition & 3 deletions Tests/Functional/ConcerningFileReferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

use TYPO3\CMS\Backend\Controller\File\FileController;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\ServerRequestFactory;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -60,10 +59,9 @@ public function deleteTranslatedMetadataResetsConsumingReferencesToDefaultFile()
],
],
]);
$response = GeneralUtility::makeInstance(Response::class);
/** @var FileController $fileController */
$fileController = GeneralUtility::makeInstance(FileController::class);
$fileController->mainAction($request, $response);
$fileController->mainAction($request);

$this->importAssertCSVScenario($scenarioName);
}
Expand Down
10 changes: 4 additions & 6 deletions Tests/Functional/ConcerningMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use TYPO3\CMS\Backend\Controller\File\FileController;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\ServerRequestFactory;
use TYPO3\CMS\Core\Resource\ResourceFactory;
Expand Down Expand Up @@ -126,7 +125,7 @@ public function uploadingVariantReplacesFileWithoutChangingUid()
$folder = $storage->getFolder('languageVariants');
$newFile = $storage->addFile($localFilePath, $folder);
$request = $request->withQueryParams(['file' => $newFile->getUid(), 'uid' => 12]);
$controller->ajaxUploadFileVariant($request, new Response());
$controller->ajaxUploadFileVariant($request);

$this->importAssertCSVScenario($scenarioName);
}
Expand Down Expand Up @@ -155,7 +154,7 @@ public function replacingVariantReplacesFileWithoutChangingUid()
$folder = $storage->getFolder('languageVariants');
$newFile = $storage->addFile($localFilePath, $folder);
$request = $request->withQueryParams(['file' => $newFile->getUid(), 'uid' => 12]);
$controller->ajaxReplaceFileVariant($request, new Response());
$controller->ajaxReplaceFileVariant($request);

$this->importAssertCSVScenario($scenarioName);
}
Expand All @@ -178,7 +177,7 @@ public function resetVariantReplacesFileWithoutChangingUid()
copy(Environment::getPublicPath() . '/typo3conf/ext/file_variants/Tests/Functional/Fixture/TestFiles/cat_2.jpg', Environment::getPublicPath() . '/languageVariants/languageVariants/cat_2.jpg');

$request = $request->withQueryParams(['uid' => 12]);
$controller->ajaxResetFileVariant($request, new Response());
$controller->ajaxResetFileVariant($request);

$this->importAssertCSVScenario($scenarioName);
}
Expand Down Expand Up @@ -208,10 +207,9 @@ public function fileDeletionRemovesAllRelatedFilesAndMetadata()
],
],
]);
$response = GeneralUtility::makeInstance(Response::class);
/** @var FileController $fileController */
$fileController = GeneralUtility::makeInstance(FileController::class);
$fileController->mainAction($request, $response);
$fileController->mainAction($request);

$this->importAssertCSVScenario($scenarioName);
}
Expand Down
11 changes: 3 additions & 8 deletions Tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\Connection;
Expand Down Expand Up @@ -52,7 +53,7 @@ abstract class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functiona
*/
protected $expectedErrorLogEntries = 0;
/**
* @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @var BackendUserAuthentication
*/
protected $backendUser;
/**
Expand Down Expand Up @@ -137,7 +138,7 @@ protected function cleanUpFilesAndRelatedRecords()
}
$recordsToDelete['sys_file_metadata'][] = (int)$metadata['uid'];
}
} catch (\Exception $exception) {
} catch (\Exception) {
// sometimes, there is no folder to empty. Let's ignore that.
}
$this->actionService->deleteRecords($recordsToDelete);
Expand Down Expand Up @@ -182,19 +183,13 @@ protected function assertErrorLogEntries()
}
}

/**
* @param string $scenarioName
*/
protected function importCsvScenario(string $scenarioName = '')
{
$scenarioFileName = $this->scenarioDataSetDirectory . $scenarioName . '.csv';
$scenarioFileName = GeneralUtility::getFileAbsFileName($scenarioFileName);
$this->importCSVDataSet($scenarioFileName);
}

/**
* @param string $scenarioName
*/
protected function importAssertCSVScenario(string $scenarioName = '')
{
$scenarioFileName = $this->assertionDataSetDirectory . $scenarioName . '.csv';
Expand Down
16 changes: 10 additions & 6 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
<?php

use T3G\AgencyPack\FileVariants\DataHandler\DataHandlerHook;
use T3G\AgencyPack\FileVariants\FormEngine\FileVariantInfoElement;
use T3G\AgencyPack\FileVariants\FormEngine\FieldWizard\FileVariantsOverviewWizard;
use T3G\AgencyPack\FileVariants\Updates\MetaDataRecordsUpdateWizard;
/*
* This file is part of the package t3g/file_variants.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

if (!defined('TYPO3_MODE')) {
if (!defined('TYPO3')) {
die('Access denied!');
}

// NEVER! use namespaces or use statements in this file!

call_user_func(function () {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['file_variants'] = \T3G\AgencyPack\FileVariants\DataHandler\DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['file_variants'] = \T3G\AgencyPack\FileVariants\DataHandler\DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['file_variants'] = DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['file_variants'] = DataHandlerHook::class;

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1489747688] = [
'nodeName' => 'fileInfo',
'priority' => 30,
'class' => \T3G\AgencyPack\FileVariants\FormEngine\FileVariantInfoElement::class,
'class' => FileVariantInfoElement::class,
];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1494415118] = [
'nodeName' => 'FileVariantsOverviewWizard',
'priority' => 40,
'class' => \T3G\AgencyPack\FileVariants\FormEngine\FieldWizard\FileVariantsOverviewWizard::class,
'class' => FileVariantsOverviewWizard::class,
];

// Upgrade Wizard
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\T3G\AgencyPack\FileVariants\Updates\MetaDataRecordsUpdateWizard::class] = \T3G\AgencyPack\FileVariants\Updates\MetaDataRecordsUpdateWizard::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][MetaDataRecordsUpdateWizard::class] = MetaDataRecordsUpdateWizard::class;
});

0 comments on commit fc1ba8d

Please sign in to comment.