Skip to content

Commit 63c2503

Browse files
authored
Merge pull request #3 from sdiaz-utrace/master
upgrade to php 81 laravel 9+
2 parents 4d5c6ab + a11ed66 commit 63c2503

6 files changed

Lines changed: 50 additions & 24 deletions

File tree

‎composer.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.3|^8.0",
27-
"illuminate/support": "^6.0|^7.0|^8.0"
26+
"php": "^8.1",
27+
"illuminate/support": "^9.0|^10.0|^11.0|^12.0"
2828
},
2929
"require-dev": {
30-
"friendsofphp/php-cs-fixer": "^3.2",
31-
"orchestra/testbench": "^4.5|^5.0|^6.0",
32-
"phpunit/phpunit": "^8.0|^9.0"
30+
"friendsofphp/php-cs-fixer": "^3.64",
31+
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
32+
"phpunit/phpunit": "^9.5|^10.0|^11.0"
3333
},
3434
"autoload": {
3535
"psr-4": {

‎phpunit.xml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
colors="true"
7+
verbose="true"
8+
convertErrorsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
processIsolation="false"
12+
stopOnFailure="false"
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd">
314
<coverage>
415
<include>
516
<directory suffix=".php">src/</directory>

‎src/CuitValidatorProvider.php‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,36 @@
99

1010
class CuitValidatorProvider extends ServiceProvider
1111
{
12-
public function boot()
12+
public function boot(): void
1313
{
1414
$this->publishes([
15-
__DIR__.'/../resources/lang' => resource_path('lang/vendor/iutrace'),
16-
]);
15+
__DIR__.'/../resources/lang' => $this->getLanguagePath(),
16+
], 'lang');
1717

1818
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'iutrace');
1919

20-
Validator::extend('cuit', Cuit::class . '@passes');
20+
Validator::extend('cuit', [Cuit::class, 'passes']);
2121
Validator::replacer('cuit', function ($message, $attribute) {
2222
return Cuit::replacerMessage($attribute);
2323
});
2424

25-
Validator::extend('cuil', Cuil::class . '@passes');
25+
Validator::extend('cuil', [Cuil::class, 'passes']);
2626
Validator::replacer('cuil', function ($message, $attribute) {
2727
return Cuil::replacerMessage($attribute);
2828
});
2929
}
30+
31+
/**
32+
* Get the language path for publishing translations.
33+
*
34+
* @return string
35+
*/
36+
private function getLanguagePath(): string
37+
{
38+
if (method_exists($this->app, 'langPath')) {
39+
return $this->app->langPath('vendor/iutrace');
40+
}
41+
42+
return resource_path('lang/vendor/iutrace');
43+
}
3044
}

‎src/Rules/Cuil.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Cuil extends Cuit
1313
27,
1414
];
1515

16-
public static function replacerMessage($attribute)
16+
public static function replacerMessage(string $attribute): string
1717
{
1818
return __('iutrace::validation.cuil', [
1919
'attribute' => $attribute,

‎src/Rules/Cuit.php‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class Cuit implements Rule
1919
34,
2020
];
2121

22-
/* @var $attribute String */
23-
protected $attribute;
22+
protected string $attribute;
2423

2524
/**
2625
* @inheritDoc
@@ -35,18 +34,18 @@ public function passes($attribute, $value): bool
3534
/**
3635
* @inheritDoc
3736
*/
38-
public function message()
37+
public function message(): string
3938
{
4039
return static::replacerMessage($this->attribute);
4140
}
4241

43-
public static function validate($value): bool
42+
public static function validate(mixed $value): bool
4443
{
45-
if (strlen($value) != 11) {
44+
if (!is_string($value) || strlen($value) !== 11) {
4645
return false;
4746
}
4847

49-
if (! Str::startsWith($value, static::TYPES)) {
48+
if (!Str::startsWith($value, static::TYPES)) {
5049
return false;
5150
}
5251

@@ -59,24 +58,24 @@ public static function validate($value): bool
5958
$multiplier = 2;
6059
$accumulator = 0;
6160
foreach ($digits as $digit) {
62-
$accumulator += $digit * $multiplier;
61+
$accumulator += (int) $digit * $multiplier;
6362

6463
$multiplier = ($multiplier + 1) % 8;
6564
$multiplier = $multiplier === 0 ? 2 : $multiplier;
6665
}
6766

6867
$calculatedVerifier = 11 - ($accumulator % 11);
6968

70-
if ($calculatedVerifier == 11) {
69+
if ($calculatedVerifier === 11) {
7170
$calculatedVerifier = 0;
72-
} elseif ($calculatedVerifier == 10) {
71+
} elseif ($calculatedVerifier === 10) {
7372
$calculatedVerifier = 1;
7473
}
7574

76-
return $verifier == $calculatedVerifier;
75+
return (int) $verifier === $calculatedVerifier;
7776
}
7877

79-
public static function replacerMessage($attribute)
78+
public static function replacerMessage(string $attribute): string
8079
{
8180
return __('iutrace::validation.cuit', [
8281
'attribute' => $attribute,

‎tests/TestCase.php‎

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

33
namespace Iutrace\Validation\Tests;
44

5+
use Illuminate\Cache\CacheServiceProvider;
56
use Illuminate\Filesystem\FilesystemServiceProvider;
67
use Illuminate\Translation\TranslationServiceProvider;
78
use Illuminate\Validation\ValidationServiceProvider;
@@ -10,9 +11,10 @@
1011

1112
class TestCase extends OrchestraTest
1213
{
13-
protected function getApplicationProviders($app)
14+
protected function getPackageProviders($app): array
1415
{
1516
return [
17+
CacheServiceProvider::class,
1618
ValidationServiceProvider::class,
1719
TranslationServiceProvider::class,
1820
FilesystemServiceProvider::class,

0 commit comments

Comments
 (0)