Skip to content

Commit b342cb3

Browse files
authored
PHP 8 Support (#39)
* Remove unsed import * Remove unreachable return * Add null var card number * Fix php cs use order * Fix Tests * Ignore phpunit test results * Add php8 support * Remove unnecessary test If current month january, always return true * Revert "Fix php cs use order" This reverts commit c4a86a2. # Conflicts: # tests/Unit/Cards/BaseCardTests.php * Fix sort lines
1 parent 1cd607a commit b342cb3

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ phpunit.xml
55
coverage.xml
66
test-reports
77
composer.lock
8+
.phpunit.result.cache

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"type": "library",
55
"keywords": [ "laravel", "validation", "credit card", "validator" ],
66
"require": {
7-
"php": "7.*",
7+
"php": "7.*|8.*",
88
"illuminate/validation": "^5.5|^6.0|^7.0|^8.0",
9-
"illuminate/translation": "^5.5|^6.0|^7.0|^8.0"
9+
"illuminate/translation": "^5.5|^6.0|^7.0|^8.0",
10+
"illuminate/support": "^5.5|^6.0|^7.0|^8.0"
1011
},
1112
"require-dev": {
12-
"php": ">=7.0.0",
1313
"friendsofphp/php-cs-fixer": "~2.5",
14-
"phpunit/phpunit": "6.2.*",
14+
"phpunit/phpunit": "6.2.*|^8.5.8|^9.3.3",
1515
"orchestra/testbench": "^3.5|^4.0|^5.0"
1616
},
1717
"autoload": {
@@ -36,7 +36,6 @@
3636
}
3737
],
3838
"config": {
39-
"platform": {"php": "7.0"},
4039
"preferred-install": "dist",
4140
"sort-packages": true
4241
}

src/CardCvc.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace LVR\CreditCard;
44

55
use Illuminate\Contracts\Validation\Rule;
6-
use LVR\CreditCard\Cards\Card;
76

87
class CardCvc implements Rule
98
{

src/CardExpirationDate.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function passes($attribute, $value)
5757

5858
return false;
5959
}
60-
61-
return false;
6260
}
6361

6462
/**

src/Cards/Card.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class Card
6363
protected $checksum_test;
6464

6565
/**
66-
* @var string
66+
* @var string|null
6767
*/
6868
private $card_number;
6969

tests/Unit/CardExpirationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function it_checks_expiration_month()
5555
// Future month
5656
$this->assertTrue($this->monthValidator(Carbon::now()->addMonth()->month)->passes());
5757

58-
// Current year, past month
58+
// Past year, current month
5959
$this->assertFalse(
60-
$this->monthValidator(Carbon::now()->subMonth()->month, Carbon::now()->year)->passes()
60+
$this->monthValidator(Carbon::now()->month, Carbon::now()->subYear()->year)->passes()
6161
);
6262

6363
// Current year, current month
@@ -157,7 +157,7 @@ protected function yearValidator(string $year)
157157

158158
/**
159159
* @param string $month
160-
*
160+
* @param null $year
161161
* @return mixed
162162
*/
163163
protected function monthValidator(string $month, $year = null)

tests/Unit/Cards/BaseCardTests.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Foundation\Http\Middleware\TrimStrings;
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\Facades\Validator;
9+
use Illuminate\Support\Str;
910
use LVR\CreditCard\CardNumber;
1011
use LVR\CreditCard\Exceptions\CreditCardCharactersException;
1112
use LVR\CreditCard\Exceptions\CreditCardChecksumException;
@@ -57,7 +58,7 @@ public function it_checks_card_number()
5758
{
5859
$this->expectException(CreditCardException::class);
5960
(new $this->instance)
60-
->setCardNumber(str_random(16))
61+
->setCardNumber(Str::random(16))
6162
->isValidCardNumber();
6263
}
6364

@@ -92,7 +93,7 @@ public function it_recognises_invalid_card_numbers()
9293
$this->withoutMiddleware(ConvertEmptyStringsToNull::class);
9394

9495
collect([
95-
str_random(16),
96+
Str::random(16),
9697
])->each(function ($number) {
9798
$this->assertTrue(
9899
Validator::make(

0 commit comments

Comments
 (0)