Skip to content

Commit 7296593

Browse files
committed
Added php v8 compatibility
1 parent 68b597c commit 7296593

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: [push]
3+
on: [ push ]
44

55
jobs:
66
build:
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111

1212
- name: Install composer
13-
uses: php-actions/composer@v1
13+
uses: php-actions/composer@v4
1414

1515
- name: Run PHPUnit
1616
uses: php-actions/phpunit@v9

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A domain validator rule for Laravel",
44
"type": "library",
55
"require": {
6-
"php": "^7.2",
6+
"php": "^7.2|^8.0",
77
"illuminate/validation": "^6.0|^7.0|^8.0"
88
},
99
"require-dev": {

src/LaravelDomainValidationServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LaravelDomainValidationServiceProvider extends ServiceProvider
1717
*
1818
* @return void
1919
*/
20-
public function boot()
20+
public function boot(): void
2121
{
2222
Validator::extend('domain', Domain::class);
2323
}

src/Validator/Domain.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ class Domain implements Rule
1313
/**
1414
* Determine if the validation rule passes.
1515
*
16-
* @param string $attribute
17-
* @param mixed $value
16+
* @param string $attribute
17+
* @param mixed $value
1818
* @return bool
1919
*/
20-
public function passes($attribute, $value)
20+
public function passes($attribute, $value): bool
2121
{
22-
if (stristr($value, 'localhost') !== false) {
22+
if (stripos($value, 'localhost') !== false) {
2323
return true;
2424
}
2525

26-
return !!preg_match('/^(?:[a-z0-9](?:[a-z0-9-æøå]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/isu', $value);
26+
return (bool) preg_match('/^(?:[a-z0-9](?:[a-z0-9-æøå]{0,61}[a-z0-9])?\.)+.[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/isu', $value);
2727
}
2828

2929
/**
3030
* Get the validation error message.
3131
*
3232
* @return string
3333
*/
34-
public function message()
34+
public function message(): string
3535
{
3636
return trans('The :attribute is not a valid domain.');
3737
}

tests/DomainTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ protected function setUp(): void
1616
$this->validator = new Domain();
1717
}
1818

19-
public function testPasses()
19+
public function testPasses(): void
2020
{
21-
$this->assertTrue($this->validator->passes('domain', 'dacoto.com'));
22-
$this->assertTrue($this->validator->passes('domain', 'www.dacoto.com'));
21+
self::assertTrue($this->validator->passes('domain', 'dacoto.com'));
22+
self::assertTrue($this->validator->passes('domain', 'www.dacoto.com'));
2323
}
2424

25-
public function testFails()
25+
public function testFails(): void
2626
{
27-
$this->assertFalse($this->validator->passes('domain', 'https://dacoto.com'));
28-
$this->assertFalse($this->validator->passes('domain', 'https://www.dacoto.com'));
27+
self::assertFalse($this->validator->passes('domain', '.'));
28+
self::assertFalse($this->validator->passes('domain', 'empty'));
29+
self::assertFalse($this->validator->passes('domain', 'empty.'));
30+
self::assertFalse($this->validator->passes('domain', '.empty'));
31+
self::assertFalse($this->validator->passes('domain', 'https://dacoto.com'));
32+
self::assertFalse($this->validator->passes('domain', 'https://www.dacoto.com'));
2933
}
3034
}

0 commit comments

Comments
 (0)