Skip to content

Commit a739249

Browse files
authored
Merge pull request #15 from worksome/feature/laravel-12
feat: add support for Laravel 12
2 parents 0953208 + de4afce commit a739249

18 files changed

+155
-94
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ root = true
22

33
[*]
44
charset = utf-8
5+
end_of_line = lf
56
indent_size = 4
67
indent_style = space
7-
end_of_line = lf
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

.gitattributes

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# Path-based git attributes
2-
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
2+
# https://git-scm.com/docs/gitattributes
3+
* text=auto
34

45
# Ignore all test and documentation with "export-ignore".
5-
/.github export-ignore
6-
/.gitattributes export-ignore
7-
/.gitignore export-ignore
8-
/phpunit.xml.dist export-ignore
9-
/art export-ignore
10-
/docs export-ignore
11-
/tests export-ignore
12-
/.editorconfig export-ignore
13-
/.php_cs.dist.php export-ignore
14-
/psalm.xml export-ignore
15-
/psalm.xml.dist export-ignore
16-
/testbench.yaml export-ignore
17-
/UPGRADING.md export-ignore
18-
/phpstan.neon.dist export-ignore
6+
/.github export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/phpunit.xml.dist export-ignore
10+
/art export-ignore
11+
/docs export-ignore
12+
/tests export-ignore
13+
/.editorconfig export-ignore
14+
/.php_cs.dist.php export-ignore
15+
/psalm.xml export-ignore
16+
/psalm.xml.dist export-ignore
17+
/testbench.yaml export-ignore
18+
/UPGRADING.md export-ignore
19+
/phpstan.neon.dist export-ignore
1920
/phpstan-baseline.neon export-ignore
21+
/docker export-ignore
22+
/docker-compose.yml export-ignore

.github/workflows/dependabot-auto-merge.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1
16+
uses: dependabot/fetch-metadata@v2
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/phpstan.yml

-27
This file was deleted.

.github/workflows/static.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'phpstan.neon.dist'
8+
9+
jobs:
10+
phpstan:
11+
name: PHPStan
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '8.3'
20+
coverage: none
21+
22+
- name: Install composer dependencies
23+
uses: ramsey/composer-install@v3
24+
25+
- name: Run PHPStan
26+
run: composer test:types
27+
28+
ecs:
29+
name: ECS
30+
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: '8.3'
41+
coverage: none
42+
43+
- name: Install Dependencies
44+
run: composer update --prefer-dist --no-interaction --no-progress --ansi
45+
46+
- name: Run ECS
47+
run: composer test:style

.github/workflows/run-tests.yml .github/workflows/tests.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
os: [ubuntu-latest, windows-latest]
16-
php: [8.2, 8.3]
17-
laravel: [10.*, 11.*]
15+
os: [ubuntu-latest]
16+
php: [8.4, 8.3]
17+
laravel: [12.*, 11.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20-
- laravel: 10.*
21-
testbench: 8.*
20+
- laravel: 12.*
21+
testbench: 10.*
2222
- laravel: 11.*
2323
testbench: 9.*
2424

25-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
25+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2626

2727
steps:
2828
- name: Checkout code
@@ -32,7 +32,6 @@ jobs:
3232
uses: shivammathur/setup-php@v2
3333
with:
3434
php-version: ${{ matrix.php }}
35-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
3635
coverage: none
3736

3837
- name: Setup problem matchers
@@ -42,7 +41,7 @@ jobs:
4241
4342
- name: Install dependencies
4443
run: |
45-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
44+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --ansi
4645
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --ansi
4746
4847
- name: Execute tests

.gitignore

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
.idea
1+
/.idea
2+
/build
3+
/vendor
4+
/.php_cs.cache
5+
/composer.lock
6+
/phpunit.xml
7+
/phpstan.neon
28
.php_cs
39
.php_cs.cache
410
.phpunit.cache
5-
build
6-
composer.lock
11+
.php-cs-fixer.cache
712
coverage
813
docs
9-
phpunit.xml
10-
phpstan.neon
11-
testbench.yaml
12-
vendor
1314
node_modules
14-
.php-cs-fixer.cache
15+
testbench.yaml

CHANGELOG.md

-7
This file was deleted.

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ php artisan vendor:publish --tag="translator-config"
2424
## Usage
2525

2626
```php
27-
$translator = new Worksome\Translator\TranslationManager();
27+
$translator = new \Worksome\Translator\TranslationManager();
2828

2929
$translator->driver('google_cloud_translate')->translate('Text to translate', 'en', 'da'); // TranslationDTO
3030
$translator->driver('google_cloud_translate')->detectLanguage('Text to detect'); // DetectedLanguageDTO
31+
```
32+
33+
### Via the Facade
3134

32-
// Via the Facade
33-
use Worksome\Translator\Facades\Translator;
35+
```php
36+
// Use the default driver
37+
\Worksome\Translator\Facades\Translator::translate('');
3438

35-
Translator::translate(''); // Use the default driver
36-
Translator::driver('google_cloud_translate')->translate('', 'en', 'da'); // Use a custom driver
39+
// Use a custom driver
40+
\Worksome\Translator\Facades\Translator::driver('google_cloud_translate')->translate('', 'en', 'da');
3741
```
3842

3943
Test suites can utilise the [`null` driver](src/Drivers/NullDriver.php), this will always return the same string value as provided for translations.
@@ -46,7 +50,7 @@ composer test
4650

4751
## Changelog
4852

49-
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
53+
Please see [GitHub Releases](https://github.com/worksome/translator/releases) for more information on what has changed recently.
5054

5155
## Credits
5256

composer.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.2",
20-
"google/cloud-translate": "^1.17",
21-
"illuminate/support": "^10.0 || ^11.0",
22-
"spatie/laravel-package-tools": "^1.16"
19+
"php": "^8.3",
20+
"google/cloud-translate": "^1.21",
21+
"illuminate/support": "^11.0 || ^12.0",
22+
"spatie/laravel-package-tools": "^1.19"
2323
},
2424
"require-dev": {
2525
"guzzlehttp/guzzle": "^7.8",
26-
"nunomaduro/collision": "^7.0 || ^8.1",
27-
"larastan/larastan": "^2.6",
28-
"orchestra/testbench": "^8.0 || ^9.0",
29-
"pestphp/pest": "^2.33",
30-
"pestphp/pest-plugin-laravel": "^2.2",
31-
"worksome/coding-style": "^2.8"
26+
"larastan/larastan": "^3.1",
27+
"nunomaduro/collision": "^7.10 || ^8.1.1",
28+
"orchestra/testbench": "^9.12 || ^10.1",
29+
"pestphp/pest": "^3.7",
30+
"pestphp/pest-plugin-laravel": "^3.1",
31+
"worksome/coding-style": "^3.2"
3232
},
3333
"autoload": {
3434
"psr-4": {

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
php:
3+
build: ./docker
4+
volumes:
5+
- .:/var/www/html
6+
environment:
7+
- XDEBUG_MODE=${XDEBUG_MODE:-off}
8+
- XDEBUG_CONFIG=${XDEBUG_CONFIG:-client_host=host.docker.internal}
9+
composer:
10+
build: ./docker
11+
entrypoint: ["composer"]
12+
volumes:
13+
- .:/var/www/html

docker/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM php:8.3-cli-alpine
2+
3+
RUN apk add --no-cache $PHPIZE_DEPS linux-headers
4+
RUN pecl install xdebug
5+
RUN docker-php-ext-enable xdebug
6+
7+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
8+
9+
WORKDIR /var/www/html
10+
11+
ENTRYPOINT ["php"]

phpstan.neon.dist

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ parameters:
1111
checkModelProperties: true
1212
parallel:
1313
processTimeout: 300.0
14+
15+
ignoreErrors:
16+
-
17+
identifier: larastan.noEnvCallsOutsideOfConfig
18+
path: config
19+
reportUnmatched: false

phpunit.xml.dist

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
cacheDirectory=".phpunit.cache"
88
>
99
<testsuites>
10-
<testsuite name="Worksome Test Suite">
10+
<testsuite name="Test Suite">
1111
<directory>tests</directory>
1212
</testsuite>
1313
</testsuites>
14+
<source>
15+
<include>
16+
<directory suffix=".php">./src</directory>
17+
</include>
18+
</source>
1419
</phpunit>

src/Contracts/Translator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
interface Translator
1111
{
12-
public function translate(string $string, string $fromLanguage, string $toLanguage): ?TranslationDTO;
12+
public function translate(string $string, string $fromLanguage, string $toLanguage): TranslationDTO|null;
1313

14-
public function detectLanguage(string $string): ?DetectedLanguageDTO;
14+
public function detectLanguage(string $string): DetectedLanguageDTO|null;
1515
}

src/Drivers/GoogleCloudTranslateDriver.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ class GoogleCloudTranslateDriver implements Translator
1313
{
1414
protected TranslateClient $client;
1515

16-
public function __construct(?string $projectId, ?string $key)
16+
public function __construct(string|null $projectId, string|null $key)
1717
{
1818
$this->client = new TranslateClient([
1919
'projectId' => $projectId,
2020
'key' => $key,
2121
]);
2222
}
2323

24-
public function translate(string $string, string $fromLanguage, string $toLanguage): ?TranslationDTO
24+
public function translate(string $string, string $fromLanguage, string $toLanguage): TranslationDTO|null
2525
{
26-
return ($response = $this->client->translate($string, [
26+
/** @var array{source: string, input: string, text: string}|null $response */
27+
$response = $this->client->translate($string, [
2728
'source' => $fromLanguage,
2829
'target' => $toLanguage,
29-
'format' => 'text'
30-
]))
30+
'format' => 'text',
31+
]);
32+
33+
return $response
3134
? new TranslationDTO(
3235
source: $response['source'],
3336
input: $response['input'],
@@ -36,9 +39,12 @@ public function translate(string $string, string $fromLanguage, string $toLangua
3639
: null;
3740
}
3841

39-
public function detectLanguage(string $string): ?DetectedLanguageDTO
42+
public function detectLanguage(string $string): DetectedLanguageDTO|null
4043
{
41-
return ($response = $this->client->detectLanguage($string))
44+
/** @var array{languageCode: string, confidence: float}|null $response */
45+
$response = $this->client->detectLanguage($string);
46+
47+
return $response
4248
? new DetectedLanguageDTO(
4349
languageCode: $response['languageCode'],
4450
confidence: $response['confidence']
File renamed without changes.

tests/Pest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
use Worksome\Translator\Tests\TestCase;
66

7-
uses(TestCase::class)->in(__DIR__);
7+
uses(TestCase::class)->in('Feature');

0 commit comments

Comments
 (0)