Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: interest
name: interest4
type: php
docroot: ""
php_version: "8.2"
webserver_type: nginx-fpm
#router_http_port: "8081"
#router_https_port: "4434"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
Expand All @@ -15,7 +13,6 @@ mutagen_enabled: false
hooks:
post-start:
- exec: composer install --no-progress
- exec: export PHP_IDE_CONFIG="serverName=interest.ddev.site"
omit_containers: [ddev-ssh-agent]
webimage_extra_packages: [parallel]
use_dns_when_possible: true
Expand Down
2 changes: 1 addition & 1 deletion Classes/Authentication/HttpBackendUserAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getUserId(): int
return $this->user['uid'] ?? 0;
}

public function checkAuthentication(ServerRequestInterface $request)
public function checkAuthentication(ServerRequestInterface $request): void
{
$this->authenticateBearerToken($request);

Expand Down
4 changes: 2 additions & 2 deletions Classes/Command/AbstractRecordCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function handleStreamableData(InputInterface $input)
protected function parseData(InputInterface $input)
{
if ($input->getOption('data') !== null) {
$data = json_decode($input->getOption('data'), true);
$data = json_decode((string)$input->getOption('data'), true);

if (!is_array($data)) {
throw new InvalidOptionException(
Expand All @@ -129,7 +129,7 @@ protected function parseData(InputInterface $input)
protected function parseMetaData(InputInterface $input)
{
if ($input->getOption('metaData') !== null) {
$data = json_decode($input->getOption('metaData'), true);
$data = json_decode((string)$input->getOption('metaData'), true);

if (!is_array($data)) {
throw new InvalidOptionException(
Expand Down
2 changes: 1 addition & 1 deletion Classes/Configuration/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()
try {
$this->extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)
->get('interest');
} catch (ExtensionConfigurationExtensionNotConfiguredException $exception) {
} catch (ExtensionConfigurationExtensionNotConfiguredException) {
$this->extensionConfiguration = [];
}

Expand Down
14 changes: 7 additions & 7 deletions Classes/DataHandling/Operation/AbstractRecordOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class AbstractRecordOperation
*
* @var SiteLanguage|null
*/
protected ?SiteLanguage $language;
protected ?SiteLanguage $language = null;

/**
* @var ContentObjectRenderer
Expand Down Expand Up @@ -142,7 +142,7 @@ public function __invoke(): void
foreach (array_filter(array_values($this->messageQueue)) as $messageObject) {
if ($messageObject instanceof RequiredMessageInterface) {
throw new IncompleteOperationException(
'All required messages were not retrieved. Found: ' . get_class($messageObject),
'All required messages were not retrieved. Found: ' . $messageObject::class,
1695260831
);
}
Expand All @@ -161,7 +161,7 @@ public function getArguments(): array
$this->getTable(),
$this->getRemoteId(),
// @extensionScannerIgnoreLine
$this->getLanguage() === null ? null : $this->getLanguage()->getHreflang(),
$this->getLanguage() instanceof SiteLanguage ? $this->getLanguage()->getHreflang() : null,
null,
$this->getMetaData(),
];
Expand Down Expand Up @@ -411,16 +411,16 @@ public function getDataHandler(): DataHandler
public function dispatchMessage(MessageInterface $message): void
{
if ($message instanceof ReplacesPreviousMessageInterface) {
$this->messageQueue[get_class($message)] = [$message];
$this->messageQueue[$message::class] = [$message];

return;
}

if (!isset($this->messageQueue[get_class($message)])) {
$this->messageQueue[get_class($message)] = [];
if (!isset($this->messageQueue[$message::class])) {
$this->messageQueue[$message::class] = [];
}

$this->messageQueue[get_class($message)][] = $message;
$this->messageQueue[$message::class][] = $message;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(AbstractRecordOperationEvent $event): void
foreach (
$settings['transformations.'][$recordOperation->getTable() . '.'] ?? [] as $fieldName => $configuration
) {
$fieldName = substr($fieldName, 0, -1);
$fieldName = substr((string)$fieldName, 0, -1);

$recordOperation->setDataFieldForDataHandler(
$fieldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function orderOnForeignSideOfRelation(string $table, int $relationId):
$fieldConfiguration['type'] === 'group'
&& (
$fieldConfiguration['allowed'] === '*'
|| str_contains($fieldConfiguration['foreign_table'], ',')
|| str_contains((string)$fieldConfiguration['foreign_table'], ',')
)
);

Expand Down Expand Up @@ -200,7 +200,7 @@ protected function generateSortingData(): array
if (
$fieldConfiguration['type'] === 'group'
&& $fieldConfiguration['allowed'] !== '*'
&& !str_contains($fieldConfiguration['allowed'], ',')
&& !str_contains((string)$fieldConfiguration['allowed'], ',')
) {
$foreignTable = $fieldConfiguration['allowed'];
}
Expand Down Expand Up @@ -263,9 +263,7 @@ protected function flattenRelations(array $relations, bool $prefixTable): array
}

$flattenedRelations = array_map(
function (int $item) use ($relationTable) {
return $relationTable . '_' . $item;
},
fn(int $item) => $relationTable . '_' . $item,
array_column($relation, 'uid')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GenerateRecordOperationHash implements RecordOperationEventHandlerInterfac
public function __invoke(AbstractRecordOperationEvent $event): void
{
$event->getRecordOperation()->setHash(
md5(get_class($event->getRecordOperation()) . serialize($event->getRecordOperation()->getArguments()))
md5($event->getRecordOperation()::class . serialize($event->getRecordOperation()->getArguments()))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use FriendsOfTYPO3\Interest\DataHandling\Operation\Event\RecordOperationEventHandlerInterface;
use FriendsOfTYPO3\Interest\Domain\Repository\RemoteIdMappingRepository;
use FriendsOfTYPO3\Interest\Utility\TcaUtility;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -25,10 +26,10 @@ public function __invoke(AbstractRecordOperationEvent $event): void

if (
// @extensionScannerIgnoreLine
$recordOperation->getLanguage() === null
!$recordOperation->getLanguage() instanceof SiteLanguage
|| (
// @extensionScannerIgnoreLine
$recordOperation->getLanguage() !== null
$recordOperation->getLanguage() instanceof SiteLanguage
// @extensionScannerIgnoreLine
&& $recordOperation->getLanguage()->getLanguageId() === 0
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
*/
class DataHandlerSuccessMessage implements ReplacesPreviousMessageInterface
{
private bool $success;

/**
* @param bool $success
*/
public function __construct(bool $success)
public function __construct(private readonly bool $success)
{
$this->success = $success;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@
*/
class PendingRelationMessage implements RequiredMessageInterface
{
private string $table;

private string $field;

/**
* @var string[]
*/
private array $remoteIds;

/**
* @param string $table
* @param string $field
* @param string[] $remoteIds The pointing remote IDs in a pending relation to record $uid in $field of $table.
*/
public function __construct(string $table, string $field, array $remoteIds)
{
$this->table = $table;
$this->field = $field;
$this->remoteIds = $remoteIds;
public function __construct(
private readonly string $table,
private readonly string $field,
private readonly array $remoteIds
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,18 @@
*/
class RelationFieldValueMessage implements RequiredMessageInterface
{
private string $table;

private string $field;

/**
* @var int|string
*/
private $id;

/**
* @var int|string|float|array
*/
private $value;

/**
* @param string $table
* @param string $field
* @param int|string $id
* @param int|string|float|array $value
*/
public function __construct(string $table, string $field, $id, $value)
{
$this->table = $table;
$this->field = $field;
// @extensionScannerIgnoreLine
$this->id = $id;
$this->value = $value;
public function __construct(
private readonly string $table,
private readonly string $field,
private $id,
private $value
) {
}

/**
Expand Down
39 changes: 19 additions & 20 deletions Classes/DataHandling/Operation/Event/Handler/PersistFileData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class PersistFileData implements RecordOperationEventHandlerInterface
{
protected RemoteIdMappingRepository $mappingRepository;

protected ResourceFactory $resourceFactory;

protected AbstractRecordOperationEvent $event;
public function __construct(
protected ResourceFactory $resourceFactory,
private readonly OnlineMediaHelperRegistry $onlineMediaHelperRegistry
) {
}

/**
* @param AbstractRecordOperationEvent $event
Expand Down Expand Up @@ -80,7 +83,7 @@ public function __invoke(AbstractRecordOperationEvent $event): void
$settings['persistence.']['fileUploadFolderPath.'] ?? []
);

$this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$this->resourceFactory = $this->resourceFactory;

$storage = GeneralUtility::makeInstance(StorageRepository::class)->findByCombinedIdentifier($storagePath);

Expand All @@ -89,7 +92,7 @@ public function __invoke(AbstractRecordOperationEvent $event): void
$replaceFile = null;

if (
get_class($this->event->getRecordOperation()) === CreateRecordOperation::class
$this->event->getRecordOperation()::class === CreateRecordOperation::class
&& $storage->hasFileInFolder($fileBaseName, $downloadFolder)
) {
[$fileBaseName, $replaceFile] = $this->handleExistingFile(
Expand Down Expand Up @@ -145,15 +148,15 @@ protected function createFileObject(
Folder $downloadFolder,
string $fileBaseName
): File {
if (get_class($this->event->getRecordOperation()) === CreateRecordOperation::class) {
if ($this->event->getRecordOperation()::class === CreateRecordOperation::class) {
return $downloadFolder->createFile($fileBaseName);
}

try {
$file = $this->resourceFactory->getFileObject(
$this->mappingRepository->get($this->event->getRecordOperation()->getRemoteId())
);
} catch (FileDoesNotExistException $exception) {
} catch (FileDoesNotExistException) {
if ($this->mappingRepository->get($this->event->getRecordOperation()->getRemoteId()) === 0) {
throw new NotFoundException(
'The file with remote ID "' . $this->event->getRecordOperation()->getRemoteId()
Expand Down Expand Up @@ -232,7 +235,8 @@ protected function fetchContentFromUrl(string $url): ?string
if ($exception->getCode() >= 400) {
throw new NotFoundException(
'Request failed. URL: "' . $url . '" Message: "' . $exception->getMessage() . '"',
1634667759711
1634667759711,
$exception
);
}

Expand Down Expand Up @@ -284,7 +288,7 @@ protected function getDownloadFolder(
) {
try {
$downloadFolder = $this->resourceFactory->getFolderObjectFromCombinedIdentifier($storagePath);
} catch (FolderDoesNotExistException $exception) {
} catch (FolderDoesNotExistException) {
[, $folderPath] = explode(':', $storagePath);

$downloadFolder = $storage->createFolder($folderPath);
Expand All @@ -296,12 +300,7 @@ protected function getDownloadFolder(
);

if ($hashedSubfolders > 0) {
if ($fileBaseName === '') {
$fileNameHash = bin2hex(random_bytes($hashedSubfolders));
} else {
$fileNameHash = md5($fileBaseName);
}

$fileNameHash = $fileBaseName === '' ? bin2hex(random_bytes($hashedSubfolders)) : md5($fileBaseName);
for ($i = 0; $i < $hashedSubfolders; $i++) {
$subfolderName = substr($fileNameHash, $i, 1);

Expand All @@ -328,7 +327,7 @@ protected function getDownloadFolder(
*/
protected function getFileFromMediaUrl(string $url, Folder $downloadFolder, string $fileBaseName): ?File
{
$onlineMediaHelperRegistry = GeneralUtility::makeInstance(OnlineMediaHelperRegistry::class);
$onlineMediaHelperRegistry = $this->onlineMediaHelperRegistry;

$file = $onlineMediaHelperRegistry->transformUrlToFile(
$url,
Expand Down Expand Up @@ -363,26 +362,26 @@ protected function getFileWithContent(array $data, Folder $downloadFolder, strin
} elseif (($data['url'] ?? '') !== '') {
$file = $this->getFileFromMediaUrl($data['url'], $downloadFolder, $fileBaseName);

if ($file === null) {
if (!$file instanceof File) {
$fileContent = $this->fetchContentFromUrl($data['url']);
}
} else {
$fileContent = '';
}

// @extensionScannerIgnoreLine
if ($fileContent === '' || ($file !== null && $file->getSize() > 0)) {
if ($fileContent === '' || ($file instanceof File && $file->getSize() > 0)) {
$this->handleEmptyFile();
}

if ($fileBaseName === '' && $file === null) {
if ($fileBaseName === '' && !$file instanceof File) {
throw new InvalidFileNameException(
'Empty file name.',
1643987693168
);
}

if ($file === null) {
if (!$file instanceof File) {
$file = $this->createFileObject($downloadFolder, $fileBaseName);

$file->setContents($fileContent);
Expand All @@ -409,7 +408,7 @@ protected function getUniqueFileName(string $fileName, Folder $folder): string

$fileInfo = PathUtility::pathinfo($fileName);

$originalExtension = strlen($fileInfo['extension'] ?? '') > 0 ? '.' . $fileInfo['extension'] : '';
$originalExtension = ($fileInfo['extension'] ?? '') !== '' ? '.' . $fileInfo['extension'] : '';

$fileName = $fileInfo['filename'];

Expand Down
Loading
Loading