Skip to content

Commit ad6cb36

Browse files
mnoconadriendupuis
andauthored
Updated code samples to Symfony 7.2 (#2864)
--------- Co-authored-by: Adrien Dupuis <[email protected]>
1 parent 4f208aa commit ad6cb36

File tree

174 files changed

+745
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+745
-1509
lines changed

.github/workflows/code_samples.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
- name: Run PHPStan analysis
3939
run: composer phpstan
4040

41+
- name: Run rector
42+
run: vendor/bin/rector process --dry-run --ansi
43+
4144
code-samples-inclusion-check:
4245
name: Check code samples inclusion
4346
runs-on: ubuntu-latest

code_samples/ai_actions/src/AI/Action/TranscribeAudioAction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
final class TranscribeAudioAction extends Action
1111
{
12-
private Audio $audio;
13-
14-
public function __construct(Audio $audio)
12+
public function __construct(private readonly Audio $audio)
1513
{
16-
$this->audio = $audio;
1714
}
1815

1916
public function getParameters(): array

code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
use Ibexa\Contracts\ConnectorAi\DataType;
1313
use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
1414

15-
final class TranscribeAudioActionType implements ActionTypeInterface
15+
final readonly class TranscribeAudioActionType implements ActionTypeInterface
1616
{
17-
public const IDENTIFIER = 'transcribe_audio';
18-
19-
/** @var iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> */
20-
private iterable $actionHandlers;
17+
public const string IDENTIFIER = 'transcribe_audio';
2118

2219
/** @param iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> $actionHandlers*/
23-
public function __construct(iterable $actionHandlers)
20+
public function __construct(private iterable $actionHandlers)
2421
{
25-
$this->actionHandlers = $actionHandlers;
2622
}
2723

2824
public function getIdentifier(): string

code_samples/ai_actions/src/AI/DataType/Audio.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
*/
1212
final class Audio implements DataType
1313
{
14-
/** @var non-empty-array<string> */
15-
private array $base64;
16-
1714
/**
1815
* @param non-empty-array<string> $base64
1916
*/
20-
public function __construct(array $base64)
17+
public function __construct(private array $base64)
2118
{
22-
$this->base64 = $base64;
2319
}
2420

2521
public function getBase64(): string

code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
use Ibexa\Contracts\ConnectorAi\ActionResponseInterface;
1313
use Symfony\Contracts\HttpClient\HttpClientInterface;
1414

15-
final class LLaVaTextToTextActionHandler implements ActionHandlerInterface
15+
final readonly class LLaVaTextToTextActionHandler implements ActionHandlerInterface
1616
{
17-
private HttpClientInterface $client;
17+
public const string IDENTIFIER = 'LLaVATextToText';
1818

19-
private string $host;
20-
21-
public const IDENTIFIER = 'LLaVATextToText';
22-
23-
public function __construct(HttpClientInterface $client, string $host = 'http://localhost:8080')
24-
{
25-
$this->client = $client;
26-
$this->host = $host;
19+
public function __construct(
20+
private HttpClientInterface $client,
21+
private string $host = 'http://localhost:8080'
22+
) {
2723
}
2824

2925
public function supports(ActionInterface $action): bool
@@ -63,7 +59,7 @@ public function handle(ActionInterface $action, array $context = []): ActionResp
6359
]
6460
);
6561

66-
$output = strip_tags(json_decode($response->getContent(), true)['choices'][0]['message']['content']);
62+
$output = strip_tags((string) json_decode($response->getContent(), true)['choices'][0]['message']['content']);
6763

6864
return new TextResponse(new Text([$output]));
6965
}

code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
final class WhisperAudioToTextActionHandler implements ActionHandlerInterface
1717
{
18-
private const TIMESTAMP_FORMAT = '/^\[\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}\.\d{3}]\s*/';
18+
private const string TIMESTAMP_FORMAT = '/^\[\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}\.\d{3}]\s*/';
1919

2020
public function supports(ActionInterface $action): bool
2121
{
@@ -33,7 +33,7 @@ public function handle(ActionInterface $action, array $context = []): ActionResp
3333

3434
$language = $action->getRuntimeContext()?->get('languageCode');
3535
if ($language !== null) {
36-
$arguments[] = sprintf('--language=%s', substr($language, 0, 2));
36+
$arguments[] = sprintf('--language=%s', substr((string) $language, 0, 2));
3737
}
3838

3939
$arguments[] = '--output_format=txt';
@@ -72,9 +72,7 @@ private function removeTimestamps(string $text): string
7272
{
7373
$lines = explode(PHP_EOL, $text);
7474

75-
$processedLines = array_map(static function (string $line): string {
76-
return preg_replace(self::TIMESTAMP_FORMAT, '', $line) ?? '';
77-
}, $lines);
75+
$processedLines = array_map(static fn (string $line): string => preg_replace(self::TIMESTAMP_FORMAT, '', $line) ?? '', $lines);
7876

7977
return implode(PHP_EOL, $processedLines);
8078
}

code_samples/ai_actions/src/AI/REST/Input/Parser/TranscribeAudio.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
final class TranscribeAudio extends BaseParser
1515
{
16-
public const AUDIO_KEY = 'Audio';
17-
public const BASE64_KEY = 'base64';
16+
public const string AUDIO_KEY = 'Audio';
17+
public const string BASE64_KEY = 'base64';
1818

1919
/** @param array<mixed> $data */
2020
public function parse(array $data, ParsingDispatcher $parsingDispatcher): TranscribeAudioAction

code_samples/ai_actions/src/AI/REST/Output/ValueObjectVisitor/AudioText.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
final class AudioText extends ValueObjectVisitor
1212
{
13-
private const OBJECT_IDENTIFIER = 'AudioText';
13+
private const string OBJECT_IDENTIFIER = 'AudioText';
1414

15+
/**
16+
* @param \App\AI\REST\Value\AudioText $data
17+
*/
1518
public function visit(Visitor $visitor, Generator $generator, $data): void
1619
{
1720
$mediaType = 'ai.' . self::OBJECT_IDENTIFIER;

code_samples/ai_actions/src/AI/REST/Value/TranscribeAudioAction.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
use App\AI\DataType\Audio;
88
use Ibexa\Contracts\ConnectorAi\Action\RuntimeContext;
99

10-
final class TranscribeAudioAction
10+
final readonly class TranscribeAudioAction
1111
{
12-
private Audio $input;
13-
14-
private RuntimeContext $runtimeContext;
15-
1612
public function __construct(
17-
Audio $input,
18-
RuntimeContext $runtimeContext
13+
private Audio $input,
14+
private RuntimeContext $runtimeContext
1915
) {
20-
$this->input = $input;
21-
$this->runtimeContext = $runtimeContext;
2216
}
2317

2418
public function getInput(): Audio

code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,13 @@
2424
)]
2525
final class ActionConfigurationCreateCommand extends Command
2626
{
27-
private ActionConfigurationServiceInterface $actionConfigurationService;
28-
29-
private PermissionResolver $permissionResolver;
30-
31-
private UserService $userService;
32-
33-
private ActionServiceInterface $actionService;
34-
35-
private ActionTypeRegistryInterface $actionTypeRegistry;
36-
3727
public function __construct(
38-
ActionConfigurationServiceInterface $actionConfigurationService,
39-
PermissionResolver $permissionResolver,
40-
UserService $userService,
41-
ActionServiceInterface $actionService,
42-
ActionTypeRegistryInterface $actionTypeRegistry
28+
private readonly ActionConfigurationServiceInterface $actionConfigurationService,
29+
private readonly PermissionResolver $permissionResolver,
30+
private readonly UserService $userService,
31+
private readonly ActionServiceInterface $actionService,
32+
private readonly ActionTypeRegistryInterface $actionTypeRegistry
4333
) {
44-
$this->actionConfigurationService = $actionConfigurationService;
45-
$this->permissionResolver = $permissionResolver;
46-
$this->userService = $userService;
47-
$this->actionService = $actionService;
48-
$this->actionTypeRegistry = $actionTypeRegistry;
49-
5034
parent::__construct();
5135
}
5236

0 commit comments

Comments
 (0)