Skip to content

Commit

Permalink
[TASK] Improve code by using PHP8 features
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer authored and dkd-kaehm committed Aug 15, 2023
1 parent 9f8c1a0 commit f16e4bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
11 changes: 4 additions & 7 deletions Classes/ContextMenu/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,10 @@ protected function canRender(string $itemName, string $type): bool
if (in_array($itemName, $this->disabledItems, true)) {
return false;
}
switch ($itemName) {
case 'tika_preview':
$canRender = true;
break;
default:
$canRender = false;
}
$canRender = match ($itemName) {
'tika_preview' => true,
default => false,
};
return $canRender;
}
}
23 changes: 9 additions & 14 deletions Classes/Service/Tika/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,15 @@ public static function getTika(string $tikaServiceType, array $configuration = n
$configuration = Util::getTikaExtensionConfiguration();
}

switch ($tikaServiceType) {
case 'jar':
case 'tika': // backwards compatibility only
return GeneralUtility::makeInstance(AppService::class, $configuration);
case 'server':
return GeneralUtility::makeInstance(ServerService::class, $configuration);
case 'solr':
return GeneralUtility::makeInstance(SolrCellService::class, $configuration);
default:
throw new InvalidArgumentException(
'Unknown Tika service type "' . $tikaServiceType . '". Must be one of jar, server, or solr.',
1423035119
);
}
return match ($tikaServiceType) {
'jar', 'tika' => GeneralUtility::makeInstance(AppService::class, $configuration),
'server' => GeneralUtility::makeInstance(ServerService::class, $configuration),
'solr' => GeneralUtility::makeInstance(SolrCellService::class, $configuration),
default => throw new InvalidArgumentException(
'Unknown Tika service type "' . $tikaServiceType . '". Must be one of jar, server, or solr.',
1423035119
),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileUtility
*/
public static function getAbsoluteFilePath(string $path): string
{
if (substr($path, 0, 1) === '/') {
if (str_starts_with($path, '/')) {
// if the path start with a "/" we thread it as absolute
return $path;
}
Expand Down

0 comments on commit f16e4bd

Please sign in to comment.