Skip to content

Commit

Permalink
Merge pull request #4 from Laravel-Lang/code-style-sewr4jb
Browse files Browse the repository at this point in the history
The code style has been fixed
  • Loading branch information
andrey-helldar authored Jun 28, 2024
2 parents a0fec5b + 35a68dc commit 14cabc6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Contracts/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface Translator
public function can(Locale|string $to): bool;

public function translate(
iterable|string|int|float|bool|null $text,
bool|float|int|iterable|string|null $text,
Locale|string|null $to,
Locale|string|null $from = null
): array|string|int|float|bool|null;
): array|bool|float|int|string|null;
}
8 changes: 4 additions & 4 deletions src/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ abstract class Integration implements Translator
{
use Extractable;

public static string $integration;

protected array $map = [];

public static string $integration;

abstract protected function request(
array|string $text,
Locale|string $to,
Expand All @@ -29,10 +29,10 @@ public function can(Locale|string $to): bool
}

public function translate(
iterable|string|int|float|bool|null $text,
bool|float|int|iterable|string|null $text,
Locale|string|null $to,
Locale|string|null $from = null
): array|string|int|float|bool|null {
): array|bool|float|int|string|null {
if (! is_iterable($text) && ! is_string($text)) {
return $text;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Services/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
class Translate
{
public function text(
iterable|string|int|float|bool|null $text,
bool|float|int|iterable|string|null $text,
Locale|string $to,
Locale|string|null $from = null
): array|string|int|float|bool|null {
): array|bool|float|int|string|null {
foreach ($this->translators() as $service) {
if ($translated = $this->translate($service->translator, $text, $to, $from)) {
return $translated;
Expand All @@ -32,7 +32,7 @@ public function text(
return $text;
}

public function __call(string $name, array $arguments): array|string|int|float|bool|null
public function __call(string $name, array $arguments): array|bool|float|int|string|null
{
if (Str::startsWith($name, 'via')) {
$provider = Str::of($name)->substr(3)->lower()->toString();
Expand All @@ -45,19 +45,19 @@ public function __call(string $name, array $arguments): array|string|int|float|b

protected function via(
string $translator,
iterable|string|int|float|bool|null $text,
bool|float|int|iterable|string|null $text,
Locale|string $to,
Locale|string|null $from = null
): array|string|int|float|bool|null {
): array|bool|float|int|string|null {
return $this->translate($translator, $text, $to, $from) ?: $text;
}

protected function translate(
string $translator,
iterable|string|int|float|bool|null $text,
bool|float|int|iterable|string|null $text,
Locale|string $to,
Locale|string|null $from = null
): array|string|int|float|bool|null {
): array|bool|float|int|string|null {
$translator = $this->initialize($translator);

if ($translator->can($to)) {
Expand Down
12 changes: 6 additions & 6 deletions tests/Helpers/Mocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
use LaravelLang\Translator\Integrations\Yandex;
use Tests\Constants\Value;

function mockTranslators(array|string|int|float|null $text = null): void
function mockTranslators(array|float|int|string|null $text = null): void
{
mockDeeplTranslator($text);
mockGoogleTranslator($text);
mockYandexTranslator($text);
}

function mockDeeplTranslator(array|string|int|float|null $text = null): void
function mockDeeplTranslator(array|float|int|string|null $text = null): void
{
$mock = mock(Deepl::$integration);

$text ??= Value::Text1French;

$result = fn (string|int|float|null $text) => new TextResult((string) $text, 'fr');
$result = fn (float|int|string|null $text) => new TextResult((string) $text, 'fr');

$values = is_array($text) ? array_map(fn (string|int|float|null $value) => $result($value), $text) : $result($text);
$values = is_array($text) ? array_map(fn (float|int|string|null $value) => $result($value), $text) : $result($text);

$mock->shouldReceive('translateText')->andReturn($values);

mockTranslator(Deepl::class, $mock);
}

function mockGoogleTranslator(array|string|int|float|null $text = null): void
function mockGoogleTranslator(array|float|int|string|null $text = null): void
{
$mock = mock(Google::$integration);

Expand All @@ -45,7 +45,7 @@ function mockGoogleTranslator(array|string|int|float|null $text = null): void
mockTranslator(Google::class, $mock);
}

function mockYandexTranslator(array|string|int|float|null $text = null): void
function mockYandexTranslator(array|float|int|string|null $text = null): void
{
$mock = mock(Yandex::$integration);

Expand Down

0 comments on commit 14cabc6

Please sign in to comment.