Skip to content

Commit 2ab7983

Browse files
Add Support For Laravel 11 (#36)
* Add support for Laravel 11 * Add support for PHP 8.3 * Drop support for PHP 7.4 * Update package dependencies * Update PHP Unit configuration * Update the test codes from using doc-comment metadata to use PHP 8 attribute * Update Github actions workflow's configuration --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent b8f7ef2 commit 2ab7983

23 files changed

+168
-152
lines changed

.github/workflows/main.yml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,105 @@ name: Build
22

33
on:
44
push:
5-
paths-ignore: ['*.md']
5+
paths-ignore: ["*.md"]
66
pull_request:
7-
paths-ignore: ['*.md']
8-
branches: [ master, main ]
7+
paths-ignore: ["*.md"]
8+
branches: [main]
99

1010
jobs:
1111
analysis:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
php: [8.2]
15+
php: [8.3]
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
2121
php-version: ${{ matrix.php }}
22-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
22+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
2323
coverage: none
24+
- name: Get Composer Cache Directory
25+
id: composer-cache
26+
run: |
27+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2428
- name: Cache composer dependencies
25-
uses: actions/cache@v2
29+
uses: actions/cache@v4
2630
env:
2731
cache-name: laravel-i18n-analysis
2832
with:
29-
path: ~/.composer
33+
path: ${{ steps.composer-cache.outputs.dir }}
3034
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
3135
restore-keys: |
3236
php-${{ matrix.php }}-build-${{ env.cache-name }}-
33-
php-${{ matrix.php }}-build-
34-
php-${{ matrix.php }}-
3537
- name: Install composer dependencies
3638
run: composer install --prefer-dist
3739
- name: Run phpstan analysis
3840
run: composer phpstan-analysis
3941
- name: Run phpmd analysis
4042
run: composer phpmd-analysis
41-
- name: Run phpcpd analysis
42-
run: vendor/bin/phpcpd --min-lines=3 --min-tokens=36 src/
4343
test:
4444
name: Test (PHP ${{ matrix.php }})
45-
needs: [ analysis ]
45+
needs: [analysis]
4646
runs-on: ubuntu-latest
4747
strategy:
4848
matrix:
49-
php: [ 7.4, 8.0, 8.1 ]
49+
php: [8.0, 8.1, 8.2]
5050
steps:
5151
- name: Checkout repository
52-
uses: actions/checkout@v2
52+
uses: actions/checkout@v4
5353
- name: Set up PHP
5454
uses: shivammathur/setup-php@v2
5555
with:
5656
php-version: ${{ matrix.php }}
57-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
57+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
5858
coverage: none
59+
- name: Get Composer Cache Directory
60+
id: composer-cache
61+
run: |
62+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
5963
- name: Cache composer dependencies
60-
uses: actions/cache@v2
64+
uses: actions/cache@v4
6165
env:
6266
cache-name: laravel-i18n-test
6367
with:
64-
path: ~/.composer
68+
path: ${{ steps.composer-cache.outputs.dir }}
6569
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
6670
restore-keys: |
6771
php-${{ matrix.php }}-build-${{ env.cache-name }}-
68-
php-${{ matrix.php }}-build-
69-
php-${{ matrix.php }}-
7072
- name: Install composer dependencies
7173
run: composer install --no-interaction --prefer-dist
72-
- name: Run PHPUnit tests and generate code coverage
74+
- name: Run PHPUnit tests
7375
run: vendor/bin/phpunit
7476
test-coverage:
7577
name: Test (PHP ${{ matrix.php }})
76-
needs: [ analysis ]
78+
needs: [analysis]
7779
runs-on: ubuntu-latest
7880
strategy:
7981
matrix:
80-
php: [ 8.2 ]
82+
php: [8.3]
8183
steps:
8284
- name: Checkout repository
83-
uses: actions/checkout@v2
85+
uses: actions/checkout@v4
8486
- name: Set up PHP
8587
uses: shivammathur/setup-php@v2
8688
with:
8789
php-version: ${{ matrix.php }}
88-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
90+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
91+
- name: Get Composer Cache Directory
92+
id: composer-cache
93+
run: |
94+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
8995
- name: Cache composer dependencies
90-
uses: actions/cache@v2
96+
uses: actions/cache@v4
9197
env:
9298
cache-name: laravel-i18n-test
9399
with:
94-
path: ~/.composer
100+
path: ${{ steps.composer-cache.outputs.dir }}
95101
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
96102
restore-keys: |
97103
php-${{ matrix.php }}-build-${{ env.cache-name }}-
98-
php-${{ matrix.php }}-build-
99-
php-${{ matrix.php }}-
100104
- name: Install composer dependencies
101105
run: composer install --no-interaction --prefer-dist
102106
- name: Run PHPUnit tests and generate code coverage

composer.json

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,21 @@
2727
"source": "https://github.com/richan-fongdasen/laravel-i18n"
2828
},
2929
"require": {
30-
"php": "^7.4|^8.0",
31-
"illuminate/database": "^8.0|^9.0|^10.0",
32-
"illuminate/support": "^8.0|^9.0|^10.0",
33-
"nesbot/carbon": "^2.16"
30+
"php": "^8.0",
31+
"illuminate/database": "^8.0|^9.0|^10.0|^11.0",
32+
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
33+
"nesbot/carbon": "^2.16|^3.0"
3434
},
3535
"require-dev": {
3636
"ekino/phpstan-banned-code": "^1.0",
37-
"fakerphp/faker": "^1.19|^1.9.1",
38-
"mockery/mockery": "^1.5|^1.4.4",
39-
"nunomaduro/larastan": "^1.0|^2.0",
40-
"orchestra/database": "^6.0|dev-master",
41-
"orchestra/testbench": "^6.0|^7.0|^8.0",
37+
"fakerphp/faker": "^1.9",
38+
"mockery/mockery": "^1.4",
39+
"larastan/larastan": "^1.0|^2.0",
40+
"orchestra/testbench": "^6.0|^7.0|^8.0|9.x-dev",
4241
"phpmd/phpmd": "^2.11",
4342
"phpstan/phpstan-deprecation-rules": "^1.0",
4443
"phpstan/phpstan-strict-rules": "^1.0",
45-
"phpunit/phpunit": "^9.5",
46-
"sebastian/phpcpd": "^6.0"
44+
"phpunit/phpunit": "^9.5|^10.0|^11.0"
4745
},
4846
"config": {
4947
"sort-packages": true
@@ -73,8 +71,7 @@
7371
"analyse": [
7472
"composer check-syntax",
7573
"composer phpstan-analysis",
76-
"composer phpmd-analysis",
77-
"vendor/bin/phpcpd --min-lines=3 --min-tokens=36 src/"
74+
"composer phpmd-analysis"
7875
],
7976
"check-syntax": [
8077
"! find src -type f -name \"*.php\" -exec php -l {} \\; | grep -v 'No syntax errors'",

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
includes:
2-
- vendor/nunomaduro/larastan/extension.neon
2+
- vendor/larastan/larastan/extension.neon
33
- vendor/phpstan/phpstan-strict-rules/rules.neon
44
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
55
- vendor/ekino/phpstan-banned-code/extension.neon

phpunit.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
83
<testsuites>
94
<testsuite name="Laravel I18n Test Suite">
105
<directory suffix="Test.php">./tests/</directory>
116
</testsuite>
127
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">src/</directory>
11+
</include>
12+
</source>
1313
</phpunit>

readme.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build](https://github.com/richan-fongdasen/laravel-i18n/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/richan-fongdasen/laravel-i18n/actions/workflows/main.yml)
1+
[![Build](https://github.com/richan-fongdasen/laravel-i18n/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/laravel-i18n/actions/workflows/main.yml)
22
[![codecov](https://codecov.io/gh/richan-fongdasen/laravel-i18n/branch/master/graph/badge.svg)](https://codecov.io/gh/richan-fongdasen/laravel-i18n)
33
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/richan-fongdasen/laravel-i18n/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/richan-fongdasen/laravel-i18n/?branch=master)
44
[![StyleCI Analysis Status](https://github.styleci.io/repos/135787392/shield?branch=master)](https://github.styleci.io/repos/135787392)
@@ -12,36 +12,38 @@
1212
1313
## Synopsis
1414

15-
This package provides easy ways to setup database translation and route localization.
15+
This package provides easy ways to setup database translation and route localization.
1616

1717
## Table of contents
1818

19-
* [Setup](#setup)
20-
* [Publish package assets](#publish-package-assets)
21-
* [Configuration](#configuration)
22-
* [Documentation](#documentation)
23-
* [Credits](#credits)
24-
* [License](#license)
19+
- [Setup](#setup)
20+
- [Publish package assets](#publish-package-assets)
21+
- [Configuration](#configuration)
22+
- [Documentation](#documentation)
23+
- [Credits](#credits)
24+
- [License](#license)
2525

2626
## Setup
2727

2828
Install the package via Composer :
29+
2930
```sh
3031
$ composer require richan-fongdasen/laravel-i18n
3132
```
3233

3334
## Publish package assets
3435

35-
Publish the package asset files using this ``php artisan`` command
36+
Publish the package asset files using this `php artisan` command
3637

3738
```sh
3839
$ php artisan vendor:publish --provider="RichanFongdasen\I18n\ServiceProvider"
3940
```
4041

4142
The command above would create three new files in your application, such as:
42-
* New configuration file ``/config/i18n.php``
43-
* New database migration ``/database/migrations/0000_00_00_000000_create_languages_table.php``
44-
* New languages json file ``/storage/i18n/languages.json``
43+
44+
- New configuration file `/config/i18n.php`
45+
- New database migration `/database/migrations/0000_00_00_000000_create_languages_table.php`
46+
- New languages json file `/storage/i18n/languages.json`
4547

4648
## Configuration
4749

@@ -134,7 +136,7 @@ return [
134136
| e.g: http://my-application.app/en/home
135137
|
136138
*/
137-
139+
138140
'locale_url_segment' => 1,
139141

140142
/*
@@ -169,9 +171,9 @@ Please check the documentation here [https://laravel-i18n.richan.id/](https://la
169171

170172
## Credits
171173

172-
* [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization) - Route localization concepts in this repository was inspired by this package.
173-
* [Wico Chandra](https://github.com/wicochandra) - Database translation concepts in this repository was inspired by his `Model Translation` concept.
174-
* [dimsav/laravel-translatable](https://github.com/dimsav/laravel-translatable) - Some of database translation concepts in this repository was inspired by this package.
174+
- [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization) - Route localization concepts in this repository was inspired by this package.
175+
- [Wico Chandra](https://github.com/wicochandra) - Database translation concepts in this repository was inspired by his `Model Translation` concept.
176+
- [dimsav/laravel-translatable](https://github.com/dimsav/laravel-translatable) - Some of database translation concepts in this repository was inspired by this package.
175177

176178
## License
177179

src/Contracts/TranslatableModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function translateTo($locale): self;
102102
*
103103
* @param Locale|null $locale
104104
*
105-
*@throws \ErrorException
105+
* @throws \ErrorException
106106
*
107107
* @return Model
108108
*/

src/Eloquent/Models/Language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Language extends Model
2121
/**
2222
* The attributes that are mass assignable.
2323
*
24-
* @var array<string>
24+
* @var array<int, string>
2525
*/
2626
protected $fillable = [
2727
'name',

src/Middleware/NegotiateLanguage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function __construct(I18nService $service)
3030
/**
3131
* Handle an incoming request.
3232
*
33-
* @param \Illuminate\Http\Request $request
34-
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
33+
* @param \Illuminate\Http\Request $request
34+
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
3535
*
3636
* @throws ErrorException
3737
*

src/Middleware/TranslatesAPI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function __construct(I18nService $service)
2929
/**
3030
* Handle an incoming request.
3131
*
32-
* @param \Illuminate\Http\Request $request
33-
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
32+
* @param \Illuminate\Http\Request $request
33+
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
3434
*
3535
* @throws \ErrorException
3636
*

tests/DatabaseRepositoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace RichanFongdasen\I18n\Tests;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use Illuminate\Support\Facades\DB;
67
use RichanFongdasen\I18n\Contracts\LocaleRepository;
78
use RichanFongdasen\I18n\DatabaseRepository;
@@ -54,15 +55,15 @@ public function setUp(): void
5455
$this->repository = new DatabaseRepository;
5556
}
5657

57-
/** @test */
58+
#[Test]
5859
public function it_can_resolve_the_abstract_interface_as_json_repository()
5960
{
6061
$repository = app(LocaleRepository::class);
6162

6263
self::assertInstanceOf(DatabaseRepository::class, $repository);
6364
}
6465

65-
/** @test */
66+
#[Test]
6667
public function it_can_load_all_the_locale_from_the_datasource()
6768
{
6869
$collection = $this->repository->all();

0 commit comments

Comments
 (0)