Skip to content

Commit caa4a76

Browse files
authored
Merge pull request #11 from ageekdev/laravel-12-support
Support Laravel 12
2 parents 1c82d99 + ff6948f commit caa4a76

File tree

9 files changed

+60
-48
lines changed

9 files changed

+60
-48
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
jobs:
66
php-code-styling:
7-
runs-on: ubuntu-22.04
7+
runs-on: ubuntu-latest
88

99
strategy:
1010
fail-fast: true

.github/workflows/phpstan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
phpstan:
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-latest
1212

1313
strategy:
1414
fail-fast: true
@@ -22,12 +22,12 @@ jobs:
2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2
2424
with:
25-
php-version: 8.2
25+
php-version: 8.4
2626
tools: composer:v2
2727
coverage: none
2828

2929
- name: Install composer dependencies
30-
uses: nick-fields/retry@v2
30+
uses: nick-fields/retry@v3
3131
with:
3232
timeout_minutes: 3
3333
max_attempts: 5

.github/workflows/run-tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-latest
1212

1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [ 8.1, 8.2, 8.3 ]
17-
laravel: [ 10, 11 ]
16+
php: [ 8.4, 8.3, 8.2, 8.1 ]
17+
laravel: ["^12.0", "^11.0", "^10.0", "^9.0"]
1818
exclude:
1919
- php: 8.1
20-
laravel: 11
20+
laravel: "^12.0"
21+
- php: 8.1
22+
laravel: "^11.0"
23+
- php: 8.4
24+
laravel: "^9.0"
2125

2226
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
2327

@@ -40,7 +44,7 @@ jobs:
4044
4145
- name: Install dependencies
4246
run: |
43-
composer require "laravel/framework:^${{ matrix.laravel }}" --no-update
47+
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:>=2.72" --dev --no-interaction --no-update
4448
composer update --prefer-dist --no-interaction --no-progress
4549
4650
- name: Execute tests

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.x-red.svg?style=flat-square)](https://laravel.com/docs/9.x)
55
[![Laravel 10.x](https://img.shields.io/badge/Laravel-10.x-red.svg?style=flat-square)](https://laravel.com/docs/10.x)
66
[![Laravel 11.x](https://img.shields.io/badge/Laravel-11.x-red.svg?style=flat-square)](https://laravel.com/docs/11.x)
7+
[![Laravel 12.x](https://img.shields.io/badge/Laravel-12.x-red.svg?style=flat-square)](https://laravel.com/docs/12.x)
78
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ageekdev/laravel-num/run-tests.yml?label=tests&style=flat-square)](https://github.com/ageekdev/laravel-num/actions/workflows/run-tests.yml)
89
[![Total Downloads](https://img.shields.io/packagist/dt/ageekdev/laravel-num.svg?style=flat-square)](https://packagist.org/packages/ageekdev/laravel-num)
910

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
],
2020
"require": {
2121
"php": "^8.1",
22-
"illuminate/support": "^9.0|^10.0|^11.0"
22+
"illuminate/support": "^9.0|^10.0|^11.0|^12.0"
2323
},
2424
"require-dev": {
2525
"laravel/pint": "^1.5",
26-
"phpstan/extension-installer": "^1.1",
27-
"phpstan/phpstan-deprecation-rules": "^1.0",
28-
"phpstan/phpstan-phpunit": "^1.0",
29-
"larastan/larastan": "^2.0",
30-
"orchestra/testbench": "^7.31|^8.11|^9.0",
31-
"pestphp/pest": "^1.21|^2.0",
32-
"pestphp/pest-plugin-laravel": "^1.4|^2.0",
26+
"phpstan/extension-installer": "^1.1|^2.0",
27+
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
28+
"phpstan/phpstan-phpunit": "^1.0|^2.0",
29+
"larastan/larastan": "^2.0|^3.0",
30+
"orchestra/testbench": "^7.31|^8.11|^9.0|^10.0",
31+
"pestphp/pest": "^1.21|^2.0|^3.0",
32+
"pestphp/pest-plugin-laravel": "^1.4|^2.0|^3.0",
3333
"roave/security-advisories": "dev-latest"
3434
},
3535
"autoload": {

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
52
level: 4
63
paths:
74
- src
85
tmpDir: build/phpstan
9-
checkMissingIterableValueType: false

src/Num.php

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,85 @@ class Num
1010
{
1111
use Macroable;
1212

13+
private const LANG_EN = 'en';
14+
15+
private const LANG_MM = 'mm';
16+
17+
private const LANG_TH = 'th';
18+
1319
/**
1420
* Convert the number to another language.
1521
*
16-
* Supported Languages: "Myanmar", "English", "Thai"
22+
* @param int|string|null $string Number to convert
23+
* @param string $to Target language code (en|mm|th)
24+
* @param string|null $from Source language code
25+
*
26+
* @throws InvalidArgumentException
1727
*/
18-
public function convert(int|string|null $string, string $to = 'en', ?string $from = null): ?string
28+
public function convert(int|string|null $string, string $to = self::LANG_EN, ?string $from = null): ?string
1929
{
2030
if ($string === null || $string === '') {
2131
return $string;
2232
}
2333

2434
$zeros = config('num.zeros');
2535

26-
if (Arr::has($zeros, $to)) {
27-
$toZero = $zeros[$to];
28-
} else {
29-
throw new InvalidArgumentException("\$to zero language [{$to}] is not defined.");
36+
if (! Arr::has($zeros, $to)) {
37+
throw new InvalidArgumentException("Target language [{$to}] is not configured in num.zeros config.");
3038
}
3139

40+
$toZero = $zeros[$to];
3241
$toNumber = num_range($toZero);
3342

34-
unset($zeros[$to]);
35-
3643
if ($from !== null) {
37-
if (Arr::has($zeros, $from)) {
38-
$fromZero = $zeros[$from];
39-
} else {
40-
throw new InvalidArgumentException("\$from zero language [{$from}] is not defined.");
44+
if (! Arr::has($zeros, $from)) {
45+
throw new InvalidArgumentException("Source language [{$from}] is not configured in num.zeros config.");
4146
}
4247

43-
return $this->replaceNumber($string, $fromZero, $toNumber);
48+
return $this->replaceNumber((string) $string, $zeros[$from], $toNumber);
4449
}
4550

46-
foreach ($zeros as $zero) {
47-
$string = $this->replaceNumber($string, $zero, $toNumber);
51+
$result = (string) $string;
52+
foreach (Arr::except($zeros, $to) as $zero) {
53+
$result = $this->replaceNumber($result, $zero, $toNumber);
4854
}
4955

50-
return $string;
56+
return $result;
5157
}
5258

53-
private function replaceNumber($string, $zero, $toNumber): string
59+
/**
60+
* Replace numbers between number systems.
61+
*
62+
* @param string $string Input string or number
63+
* @param string $fromZero Source zero character
64+
* @param array<int,string> $toNumber Target number array
65+
*/
66+
private function replaceNumber(string $string, string $fromZero, array $toNumber): string
5467
{
55-
$fromNumbers = num_range($zero);
56-
57-
return str_replace($fromNumbers, $toNumber, $string);
68+
return str_replace(num_range($fromZero), $toNumber, $string);
5869
}
5970

6071
/**
61-
* Convert to the myanmar number.
72+
* Convert to Myanmar number.
6273
*/
6374
public function toMyanmar(int|string|null $string): ?string
6475
{
65-
return $this->convert($string, 'mm');
76+
return $this->convert($string, self::LANG_MM);
6677
}
6778

6879
/**
69-
* Convert to the thai number.
80+
* Convert to Thai number.
7081
*/
7182
public function toThai(int|string|null $string): ?string
7283
{
73-
return $this->convert($string, 'th');
84+
return $this->convert($string, self::LANG_TH);
7485
}
7586

7687
/**
77-
* Convert to the english number.
88+
* Convert to English number.
7889
*/
7990
public function toEnglish(int|string|null $string): ?string
8091
{
81-
return $this->convert($string);
92+
return $this->convert($string, self::LANG_EN);
8293
}
8394
}

src/NumServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function register(): void
1818
$this->mergeConfigFrom(__DIR__.'/../config/num.php', 'num');
1919

2020
$this->app->singleton('num', function ($app) {
21-
return new Num();
21+
return new Num;
2222
});
2323
}
2424
}

0 commit comments

Comments
 (0)