Skip to content

Commit dee2aaa

Browse files
authored
Merge pull request #216 from prakash/master
PHP 8.4 compatibility
2 parents 9429773 + 0759959 commit dee2aaa

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ jobs:
2020
- "8.1"
2121
- "8.2"
2222
- "8.3"
23+
- "8.4"
2324
dependency-versions:
2425
- "lowest"
2526
- "highest"
2627

2728
steps:
2829
- name: Checkout
29-
uses: actions/checkout@v3
30+
uses: actions/checkout@v4
3031

3132
- name: Setup PHP
3233
uses: shivammathur/setup-php@v2
@@ -35,9 +36,7 @@ jobs:
3536
coverage: none
3637

3738
- name: Install composer dependencies
38-
uses: ramsey/composer-install@v2
39-
with:
40-
dependency-versions: ${{ matrix.dependency-versions }}
39+
run: composer install --prefer-dist --no-progress
4140

4241
- name: Run PHPUnit
4342
run: vendor/bin/phpunit

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/.idea/
12
/vendor/
2-
composer.lock
3+
composer.lock
4+
.phpunit.result.cache

src/GoogleTranslate.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ class GoogleTranslate
117117
* @param TokenProviderInterface|null $tokenProvider
118118
* @param bool|string $preserveParameters Boolean or custom regex pattern to match parameters
119119
*/
120-
public function __construct(string $target = 'en', string $source = null, array $options = [], TokenProviderInterface $tokenProvider = null, bool|string $preserveParameters = false)
120+
public function __construct(
121+
string $target = 'en',
122+
?string $source = null,
123+
array $options = [],
124+
?TokenProviderInterface $tokenProvider = null,
125+
bool|string $preserveParameters = false
126+
)
121127
{
122128
$this->client = new Client();
123129
$this->setTokenProvider($tokenProvider ?? new GoogleTokenGenerator)
@@ -145,7 +151,7 @@ public function setTarget(string $target): self
145151
* @param string|null $source Source language code (null for automatic language detection)
146152
* @return GoogleTranslate
147153
*/
148-
public function setSource(string $source = null): self
154+
public function setSource(?string $source = null): self
149155
{
150156
$this->source = $source ?? 'auto';
151157
return $this;
@@ -224,7 +230,14 @@ public function getLastDetectedSource(): ?string
224230
* @throws TranslationRequestException If any other HTTP related error occurs
225231
* @throws TranslationDecodingException If response JSON cannot be decoded
226232
*/
227-
public static function trans(string $string, string $target = 'en', string $source = null, array $options = [], TokenProviderInterface $tokenProvider = null, bool|string $preserveParameters = false): ?string
233+
public static function trans(
234+
string $string,
235+
string $target = 'en',
236+
?string $source = null,
237+
array $options = [],
238+
?TokenProviderInterface $tokenProvider = null,
239+
bool|string $preserveParameters = false
240+
): ?string
228241
{
229242
return (new self)
230243
->setTokenProvider($tokenProvider ?? new GoogleTokenGenerator)

tests/UtilityTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class UtilityTest extends TestCase
1414

1515
public ReflectionMethod $method;
1616

17+
private ReflectionClass $reflection;
18+
1719
public function setUp(): void
1820
{
1921
$this->tr = new GoogleTranslate();

0 commit comments

Comments
 (0)