Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove support for php 7.x #31

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,9 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0, 8.1, 8.2]
laravel: [7.*, 8.*, 9.*, 10.*]
php: [8.1, 8.2]
laravel: [10.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- php: 8.2
laravel: 9.*
dependency-version: prefer-lowest
- php: 8.2
laravel: 8.*
- php: 8.2
laravel: 7.*
- php: 8.1
laravel: 8.*
dependency-version: prefer-lowest
- php: 8.1
laravel: 7.*
- php: 8.0
laravel: 8.*
dependency-version: prefer-lowest
- php: 8.0
laravel: 7.*
dependency-version: prefer-lowest
- php: 8.0
laravel: 10.*
- php: 7.4
gdebrauwer marked this conversation as resolved.
Show resolved Hide resolved
laravel: 10.*
- php: 7.3
laravel: 10.*
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 9.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"require": {
"php": "^7.3|^7.4|^8.0|^8.1|^8.2",
"php": "^8.1|^8.2",
"illuminate/database": "^7.0|^8.0|^9.0|^10.0",
"illuminate/notifications": "^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^7.0|^8.0|^9.0|^10.0"
Expand Down
14 changes: 2 additions & 12 deletions database/migrations/create_verification_codes_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ use Illuminate\Support\Facades\Schema;

class CreateVerificationCodesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up() : void
{
Schema::create('verification_codes', function (Blueprint $table) {
$table->bigIncrements('id');
Expand All @@ -22,12 +17,7 @@ class CreateVerificationCodesTable extends Migration
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down() : void
{
Schema::dropIfExists('verification_codes');
}
Expand Down
49 changes: 4 additions & 45 deletions src/Models/VerificationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,27 @@

namespace NextApps\VerificationCode\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use NextApps\VerificationCode\Support\CodeGenerator;

class VerificationCode extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'code',
'verifiable',
'expires_at',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'code',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'expires_at' => 'datetime',
];

/**
* The "booting" method of the model.
*
* @return void
*/
public static function boot()
{
parent::boot();
Expand Down Expand Up @@ -74,14 +55,7 @@ public static function boot()
});
}

/**
* Create a verification code for the verifiable.
*
* @param string $verifiable
*
* @return string
*/
public static function createFor(string $verifiable)
public static function createFor(string $verifiable) : string
{
self::create([
'code' => $code = app(CodeGenerator::class)->generate(),
Expand All @@ -91,27 +65,12 @@ public static function createFor(string $verifiable)
return $code;
}

/**
* Scope a query to only include verification codes for the provided verifiable.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $verifiable
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFor($query, string $verifiable)
public function scopeFor(Builder $query, string $verifiable) : Builder
{
return $query->where('verifiable', $verifiable);
}

/**
* Scope a query to only include verification codes that have not expired.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotExpired($query)
public function scopeNotExpired(Builder $query) : Builder
{
return $query->where('expires_at', '>=', now());
}
Expand Down
22 changes: 2 additions & 20 deletions src/Notifications/VerificationCodeCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,19 @@ class VerificationCodeCreated extends Notification implements ShouldQueue, Verif
{
use Queueable;

/**
* @var string
*/
public $code;

/**
* Create a new message instance.
*
* @param string $code
*/
public function __construct(string $code)
{
$this->code = $code;
}

/**
* Get the notification's delivery channels.
*
* @return array
*/
public function via()
public function via() : array
{
return ['mail'];
}

/**
* Build the mail representation of the notification.
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail()
public function toMail() : MailMessage
{
return (new MailMessage())
->subject(__('Your verification code'))
Expand Down
5 changes: 0 additions & 5 deletions src/Notifications/VerificationCodeCreatedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@

interface VerificationCodeCreatedInterface
{
/**
* Create a new notification instance.
*
* @param string $code
*/
public function __construct(string $code);
}
25 changes: 3 additions & 22 deletions src/Support/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@

class CodeGenerator
{
/**
* Generate a random code.
*
* @return string
*/
public function generate()
public function generate() : string
{
$length = $this->getLength();
$characters = $this->getCharacters();
Expand All @@ -23,14 +18,7 @@ public function generate()
->join('');
}

/**
* Get the required length.
*
* @throws \RuntimeException
*
* @return int
*/
protected function getLength()
protected function getLength() : int
{
$length = config('verification-code.length');

Expand All @@ -41,14 +29,7 @@ protected function getLength()
return $length;
}

/**
* Get the allowed characters.
*
* @throws \RuntimeException
*
* @return string
*/
protected function getCharacters()
protected function getCharacters() : string
{
$characters = config('verification-code.characters');

Expand Down
7 changes: 1 addition & 6 deletions src/VerificationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
*/
class VerificationCode extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor() : string
{
return 'verification-code';
}
Expand Down
45 changes: 5 additions & 40 deletions src/VerificationCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ class VerificationCodeManager
{
/**
* Create and send a verification code.
*
* @param string $verifiable
* @param string $channel
*
* @return void
*/
public function send(string $verifiable, string $channel = 'mail')
public function send(string $verifiable, string $channel = 'mail') : void
{
if ($this->isTestVerifiable($verifiable)) {
return;
Expand All @@ -38,16 +33,7 @@ public function send(string $verifiable, string $channel = 'mail')
Notification::route($channel, $verifiable)->notify($notification);
}

/**
* Verify the code.
*
* @param string $code
* @param string $verifiable
* @param bool $deleteAfterVerification
*
* @return bool
*/
public function verify(string $code, string $verifiable, bool $deleteAfterVerification = true)
public function verify(string $code, string $verifiable, bool $deleteAfterVerification = true) : bool
{
if ($this->isTestVerifiable($verifiable)) {
return $this->isTestCode($code);
Expand All @@ -72,14 +58,7 @@ public function verify(string $code, string $verifiable, bool $deleteAfterVerifi
return true;
}

/**
* Check if the verifiable is a test verifiable.
*
* @param string $verifiable
*
* @return bool
*/
protected function isTestVerifiable(string $verifiable)
protected function isTestVerifiable(string $verifiable) : bool
{
$testVerifiables = config('verification-code.test_verifiables', []);

Expand All @@ -90,14 +69,7 @@ protected function isTestVerifiable(string $verifiable)
return in_array(strtolower($verifiable), $testVerifiables);
}

/**
* Check if the code is the test code.
*
* @param string $code
*
* @return bool
*/
protected function isTestCode(string $code)
protected function isTestCode(string $code) : bool
{
if (empty(config('verification-code.test_code'))) {
return false;
Expand All @@ -106,14 +78,7 @@ protected function isTestCode(string $code)
return $code === config('verification-code.test_code');
}

/**
* Get the notification class.
*
* @throws \RuntimeException
*
* @return string
*/
protected function getNotificationClass()
protected function getNotificationClass() : string
{
$notificationClass = config('verification-code.notification', VerificationCodeCreated::class);

Expand Down
6 changes: 0 additions & 6 deletions src/VerificationCodeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

class VerificationCodeServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
$this->publishes([
Expand All @@ -23,9 +20,6 @@ public function boot()
}
}

/**
* Register the application services.
*/
public function register()
{
$this->app->bind('verification-code', function () {
Expand Down
Loading