Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/testcore13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
- name: "Find duplicate exception codes"
run: "Build/Scripts/runTests.sh -t 13 -p ${{ matrix.php-version }} -s checkExceptionCodes"

# - name: "Run PHPStan"
# run: "Build/Scripts/runTests.sh -t 13 -p ${{ matrix.php-version }} -s phpstan"
- name: "Run PHPStan"
run: "Build/Scripts/runTests.sh -t 13 -p ${{ matrix.php-version }} -s phpstan"

# testsuite:
# name: all tests with core v13
Expand Down
16 changes: 8 additions & 8 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ Options:
-t <13>
Only with -s composerInstall|composerInstallMin|composerInstallMax
Specifies the TYPO3 CORE Version to be used
- 12: (default) use TYPO3 v13
- 13: (default) use TYPO3 v13

-p <8.1|8.2|8.3|8.4|8.5>
-p <8.2|8.3|8.4|8.5>
Specifies the PHP minor version to be used
- 8.2: (default) use PHP 8.2
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4
- 8.4: use PHP 8.5
- 8.5: use PHP 8.5
-x
Only with -s functional|functionalDeprecated|unit|unitDeprecated|unitRandom|acceptance|acceptanceInstall
Send information to host instance for test or system under test break points. This is especially
Expand Down Expand Up @@ -255,22 +255,22 @@ Options:
Show this help.

Examples:
# Run all core unit tests using PHP 8.1
# Run all core unit tests using PHP 8.2
./Build/Scripts/runTests.sh
./Build/Scripts/runTests.sh -s unit

# Run all core units tests and enable xdebug (have a PhpStorm listening on port 9003!)
./Build/Scripts/runTests.sh -x

# Run unit tests in phpunit verbose mode with xdebug on PHP 8.1 and filter for test canRetrieveValueWithGP
./Build/Scripts/runTests.sh -x -p 8.1 -e "-v --filter canRetrieveValueWithGP"
# Run unit tests in phpunit verbose mode with xdebug on PHP 8.2 and filter for test canRetrieveValueWithGP
./Build/Scripts/runTests.sh -x -p 8.2 -e "-v --filter canRetrieveValueWithGP"

# Run functional tests in phpunit with a filtered test method name in a specified file
# example will currently execute two tests, both of which start with the search term
./Build/Scripts/runTests.sh -s functional -e "--filter deleteContent" typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/ActionTest.php

# Run functional tests on postgres with xdebug, php 8.1 and execute a restricted set of tests
./Build/Scripts/runTests.sh -x -p 8.1 -s functional -d postgres typo3/sysext/core/Tests/Functional/Authentication
# Run functional tests on postgres with xdebug, php 8.2 and execute a restricted set of tests
./Build/Scripts/runTests.sh -x -p 8.2 -s functional -d postgres typo3/sysext/core/Tests/Functional/Authentication

# Run functional tests on postgres 11
./Build/Scripts/runTests.sh -s functional -d postgres -k 11
Expand Down
1 change: 1 addition & 0 deletions Build/phpstan/Core13/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:

paths:
- ../../../Classes/
- ../../../Core13/
- ../../../Tests/

excludePaths:
Expand Down
3 changes: 3 additions & 0 deletions Classes/Client/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(
) {
}

/**
* @param array<string, mixed> $options
*/
public function buildDeeplClient(array $options = []): DeepLClient
{
if ($this->configuration->getApiKey() === '') {
Expand Down
14 changes: 9 additions & 5 deletions Classes/Controller/CkEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ public function deeplConfiguredAction(ServerRequestInterface $request): Response
public function optimizeTextAction(ServerRequestInterface $request): ResponseInterface
{
$data = $request->getParsedBody();
$splittedText = $this->htmlParser->splitHtml($data['text']);
foreach ($splittedText as $node => $text) {
$data = is_array($data) ? $data : [];
$text = (string)($data['text'] ?? '');
$style = (string)($data['style'] ?? '');
$tone = (string)($data['tone'] ?? '');
$splittedText = $this->htmlParser->splitHtml($text);
foreach ($splittedText as $node => $value) {
$optimizedText = $this->deeplService->rephraseText(
$data['text'],
$text,
null,
RephraseWritingStyleDeepL::tryFrom($data['style']),
RephraseToneDeepL::tryFrom($data['tone'])
RephraseWritingStyleDeepL::tryFrom($style),
RephraseToneDeepL::tryFrom($tone)
);
$splittedText[$node] = $optimizedText;
}
Expand Down
7 changes: 5 additions & 2 deletions Classes/Domain/Enum/RephraseSupportedDeepLLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ final class RephraseSupportedDeepLLanguage
],
];

/**
* @return list<string>
*/
public static function getAllLanguages(): array
{
return array_keys(self::LANGUAGES);
Expand All @@ -66,14 +69,14 @@ public static function isWritingStyleSupported(string $language): bool
if (!array_key_exists($language, self::LANGUAGES)) {
return false;
}
return self::LANGUAGES[$language]['writing_style'] ?? false;
return self::LANGUAGES[$language]['writing_style'];
}

public static function isToneSupportedByLanguage(string $language): bool
{
if (!array_key_exists($language, self::LANGUAGES)) {
return false;
}
return self::LANGUAGES[$language]['tone'] ?? false;
return self::LANGUAGES[$language]['tone'];
}
}
3 changes: 3 additions & 0 deletions Classes/FieldType/AbstractFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

abstract class AbstractFieldType implements FieldTypeInterface
{
/**
* @param array<string, mixed> $configuration
*/
final public function __construct(
protected readonly array $configuration,
protected readonly string $table,
Expand Down
3 changes: 3 additions & 0 deletions Classes/FieldType/FieldTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

interface FieldTypeInterface
{
/**
* @param array<string, mixed> $configuration
*/
public function __construct(
array $configuration,
string $table,
Expand Down
7 changes: 5 additions & 2 deletions Classes/FieldType/FieldTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
final class FieldTypeRegistry
{
/**
* @var array<string, FieldTypeInterface>
* @var array<string, class-string<FieldTypeInterface>>
*/
private static array $fieldTypes = [
'input' => Input::class,
'text' => Text::class,
];

/**
* @param array<string, mixed> $tcaConfig
*/
public static function getFieldProcessingTypeByRenderType(
array $tcaConfig,
string $table,
string $fieldName,
?string $type = null
): FieldTypeInterface {
$renderType = $tcaConfig['renderType'] ?? $tcaConfig['type'];
$renderType = (string)($tcaConfig['renderType'] ?? $tcaConfig['type'] ?? '');
return new self::$fieldTypes[$renderType](
$tcaConfig,
$table,
Expand Down
2 changes: 1 addition & 1 deletion Classes/FieldType/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class Input extends AbstractFieldType
public function getTextForProcessing(
string|int $value
): array {
return [$value];
return [(string)$value];
}

public function getValueForDatabase(array $processedText): int|string
Expand Down
1 change: 1 addition & 0 deletions Classes/FieldType/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class Text extends AbstractFieldType
public function getTextForProcessing(
string|int $value
): array {
$value = (string)$value;
if ($this->isRteField()) {
$processing = $this->getHtmlParser()->splitHtml($value);
} else {
Expand Down
11 changes: 10 additions & 1 deletion Classes/Form/UserFunc/WriteSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

final class WriteSupport
{
/**
* @param array<string, mixed> $configuration
*/
public function getSupportedLanguageForField(array &$configuration): void
{
foreach (RephraseSupportedDeepLLanguage::getAllLanguages() as $supportedLanguage) {
Expand All @@ -21,6 +24,9 @@ public function getSupportedLanguageForField(array &$configuration): void
}
}

/**
* @param array<string, mixed> $configuration
*/
public function getSupportedToneForField(array &$configuration): void
{
foreach (RephraseToneDeepL::cases() as $supportedTone) {
Expand All @@ -31,6 +37,9 @@ public function getSupportedToneForField(array &$configuration): void
}
}

/**
* @param array<string, mixed> $configuration
*/
public function getSupportedWritingStyleForField(array &$configuration): void
{
foreach (RephraseWritingStyleDeepL::cases() as $supportedWritingStyle) {
Expand All @@ -42,7 +51,7 @@ public function getSupportedWritingStyleForField(array &$configuration): void
}

/**
* @param array{record?: array{deeplTargetLanguage?: array<int, string>|string|null}} $params
* @param array{record?: array{deeplWriteLanguage?: array<int, string>|string|null}} $params
*/
public function languageIsRephraseSupported(array $params, EvaluateDisplayConditions $conditions): bool
{
Expand Down
13 changes: 10 additions & 3 deletions Classes/Hooks/WriteHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public function processCmdmap(
return;
}

$recordId = $dataHandler->localize($table, $id, $value);
$recordId = $dataHandler->localize($table, (int)$id, $value);
// localization went wrong
if ($recordId === false) {
return;
}

$originalRecord = BackendUtility::getRecord($table, $id);
$translatedRecord = BackendUtility::getRecordLocalization($table, $id, $value);
$originalRecord = BackendUtility::getRecord($table, (int)$id);
if ($originalRecord === null) {
return;
}
$translatedRecord = BackendUtility::getRecordLocalization($table, (int)$id, $value);

if ($translatedRecord === null) {
return;
Expand All @@ -66,6 +69,10 @@ public function processCmdmap(
$commandIsProcessed = true;
}

/**
* @param array<string, mixed> $translatedRecord
* @param array<string, mixed> $originalRecord
*/
private function processRecordFieldsAndUpdate(string $table, array $translatedRecord, array $originalRecord, int|string $languageId): void
{
$pid = ($table === 'pages') ? $originalRecord['uid'] : $originalRecord['pid'];
Expand Down
13 changes: 8 additions & 5 deletions Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
final class DeeplService
{
private const SENTENCE_SPLIT = '/([.?!]\s)/';
private ?DeepLClient $deeplClient;
private DeepLClient $deeplClient;

public function __construct(
ClientFactory $clientFactory,
Expand Down Expand Up @@ -76,10 +76,7 @@ public function rephraseText(
}

/**
* @param array{
* writing_style?: string,
* tone?: string
* }|empty $options
* @param array<string, string> $options
* @throws DeepLException
*/
private function optimizeText(
Expand All @@ -92,6 +89,9 @@ private function optimizeText(
$targetLanguage,
$options
);
if (is_array($rephrased)) {
$rephrased = $rephrased[0];
}

return (string)$rephrased;
}
Expand All @@ -107,6 +107,9 @@ private function splitTextToMaxSize(string $text): array
}

$sentences = preg_split(self::SENTENCE_SPLIT, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
if ($sentences === false) {
return [$text];
}
$countResult = count($sentences);

$snippets = [];
Expand Down
Loading