Skip to content

Commit 2891310

Browse files
committed
Parameter names and increment
1 parent 74c197f commit 2891310

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/GoogleTranslate.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,13 @@ protected function extractParameters(string $string): string
359359

360360
// Replace all matches of our pattern with #{\d} for replacement later
361361
return preg_replace_callback(
362-
$this->pattern,
363-
function ($matches) {
364-
static $index = -1;
362+
pattern: $this->pattern,
363+
callback: static function ($matches) {
364+
static $index = 0;
365365

366-
$index++;
367-
368-
return '#{' . $index . '}';
366+
return '#{' . $index++ . '}';
369367
},
370-
$string
368+
subject: $string
371369
);
372370
}
373371

@@ -384,9 +382,9 @@ protected function injectParameters(string $string, array $replacements): string
384382
$string = preg_replace('/#\{\s*(\d+)\s*\}/', '#{$1}', $string);
385383

386384
return preg_replace_callback(
387-
'/\#{(\d+)}/',
388-
fn($matches) => $replacements[$matches[1]],
389-
$string
385+
pattern: '/\#{(\d+)}/',
386+
callback: static fn($matches) => $replacements[$matches[1]],
387+
subject: $string
390388
);
391389
}
392390

@@ -424,10 +422,10 @@ protected function getParameters(string $string): array
424422
public function getResponse(string $string): array
425423
{
426424
$queryArray = array_merge($this->urlParams, [
427-
'sl' => $this->source,
428-
'tl' => $this->target,
429-
'tk' => $this->tokenProvider->generateToken($this->source, $this->target, $string),
430-
'q' => $string
425+
'sl' => $this->source,
426+
'tl' => $this->target,
427+
'tk' => $this->tokenProvider->generateToken($this->source, $this->target, $string),
428+
'q' => $string
431429
]);
432430

433431
// Remove array indexes from URL so that "&dt[2]=" turns into "&dt=" and so on.

0 commit comments

Comments
 (0)