Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad-fouladgar committed Dec 4, 2023
1 parent ca16ea0 commit 424b964
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 107 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ jobs:
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
exclude:
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 8.0

steps:
- name: Checkout code
Expand All @@ -36,8 +34,8 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Run test suite
run: composer test
run: composer test
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

![alt text](./cover.jpg "EloquentBuilder")

![Test Status](https://img.shields.io/github/workflow/status/mohammad-fouladgar/laravel-mobile-verification/run-tests?label=tests)
[![Coverage Status](https://coveralls.io/repos/github/mohammad-fouladgar/laravel-mobile-verification/badge.svg)](https://coveralls.io/github/mohammad-fouladgar/laravel-mobile-verification)
![Code Style Status](https://img.shields.io/github/workflow/status/mohammad-fouladgar/laravel-mobile-verification/Check%20&%20fix%20styling?label=code%20style)
[![Latest Stable Version](https://poser.pugx.org/fouladgar/laravel-mobile-verification/v/stable)](https://packagist.org/packages/fouladgar/laravel-mobile-verification)
[![Total Downloads](https://poser.pugx.org/fouladgar/laravel-mobile-verification/downloads)](https://packagist.org/packages/fouladgar/laravel-mobile-verification)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/fouladgar/laravel-mobile-verification.svg)](https://packagist.org/packages/fouladgar/laravel-mobile-verification)
![Test Status](https://img.shields.io/github/actions/workflow/status/mohammad-fouladgar/laravel-mobile-verification/run-tests.yml?label=tests)
![Code Style Status](https://img.shields.io/github/actions/workflow/status/mohammad-fouladgar/laravel-mobile-verification/php-cs-fixer.yml?label=code%20style)
![Total Downloads](https://img.shields.io/packagist/dt/fouladgar/laravel-mobile-verification)

## Introduction
Many web applications require users to verify their mobile phone numbers before using the application. Rather than forcing you to re-implement this on each application, this package provides convenient methods for sending and verifying mobile phone verification requests.
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit --testdox --coverage-text",
"test-coverage": "vendor/bin/php-coveralls -v"
"test": "vendor/bin/phpunit --testdox --coverage-text"
},
"extra": {
"laravel": {
Expand Down
7 changes: 2 additions & 5 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
protected string $model = User::class;

/**
* Define the model's default state.
*
*/
public function definition(): array
{
return [
'name' => $this->faker->firstName(),
'name' => $this->faker->firstName(),
'mobile' => $this->faker->phoneNumber(),
];
}
Expand Down
5 changes: 1 addition & 4 deletions database/factories/VerifiableUserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ class VerifiableUserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = VerifiableUser::class;
protected string $model = VerifiableUser::class;

/**
* Define the model's default state.
*
*/
public function definition(): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Concerns/MustVerifyMobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

trait MustVerifyMobile
{
/**
* @inheritDoc
*/
public function getFillable()
{
$this->appendMobileFieldToFillableAttributes();
Expand Down
4 changes: 1 addition & 3 deletions src/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class EventServiceProvider extends ServiceProvider
{
/**
* Register any other events for your application.
*
* @return void
*/
public function boot()
public function boot(): void
{
if (config('mobile_verifier.queue.connection') === 'sync') {
Event::listen(Registered::class, SendMobileVerificationNotification::class);
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/InvalidTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

class InvalidTokenException extends Exception
{
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct(__('MobileVerification::mobile_verifier.expired_or_invalid'), 406);
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/SMSClientNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

class SMSClientNotFoundException extends Exception
{
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('SMS client is not specified in the config file.');
Expand Down
30 changes: 7 additions & 23 deletions src/Listeners/SendMobileVerificationNotificationQueueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@

class SendMobileVerificationNotificationQueueable extends AbstractMobileVerificationListener implements ShouldQueue
{
/**
* @param $name
* @return mixed
*/
public function __get($name)
public function __get(string $name): mixed
{
switch ($name) {
case 'tries':
return config('mobile_verifier.queue.tries');

break;
case 'timeout':
return config('mobile_verifier.queue.timeout');

break;
case 'connection':
return config('mobile_verifier.queue.connection');

break;
case 'queue':
return config('mobile_verifier.queue.queue');

break;
}
return match ($name) {
'tries' => config('mobile_verifier.queue.tries'),
'timeout' => config('mobile_verifier.queue.timeout'),
'connection' => config('mobile_verifier.queue.connection'),
'queue' => config('mobile_verifier.queue.queue'),
};
}
}
6 changes: 2 additions & 4 deletions src/Notifications/Messages/MobileVerificationMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

class MobileVerificationMessage
{
/** @var string */
protected $token;
protected string $token;

/** @var string */
protected $to;
protected string $to;

public function to(string $to): self
{
Expand Down
6 changes: 2 additions & 4 deletions src/Notifications/Messages/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

class Payload
{
/** @var string */
private $token;
private string $token;

/** @var string */
private $to;
private string $to;

public function getToken(): string
{
Expand Down
8 changes: 0 additions & 8 deletions src/Tokens/AbstractTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public function __construct(protected int $expires, protected int $tokenLength)
{
}

/**
* Set Expires token.
*/
public function setExpires(int $expires): self
{
$this->expires = $expires;
Expand All @@ -24,8 +21,6 @@ public function setExpires(int $expires): self
}

/**
* Create a new token for the user.
*
* @throws Exception
*/
protected function createNewToken(): string
Expand All @@ -35,9 +30,6 @@ protected function createNewToken(): string
return (string) random_int(10 ** ($tokenLength - 1), (10 ** $tokenLength) - 1);
}

/**
* Determine if the token has been expired.
*/
protected function tokenExpired(string $expiresAt): bool
{
return Carbon::parse($expiresAt)->isPast();
Expand Down
4 changes: 2 additions & 2 deletions tests/CacheTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function it_can_successfully_create_a_token(): void
/**
* @test
*/
public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exist()
public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exist(): void
{
$this->repository->setExpires(-5);
$token = $this->repository->create($this->user);
Expand All @@ -52,7 +52,7 @@ public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exi
/**
* @test
*/
public function it_can_return_latest_sent_at_as_date_time_string_if_token_exists()
public function it_can_return_latest_sent_at_as_date_time_string_if_token_exists(): void
{
$token = $this->repository->create($this->user);

Expand Down
4 changes: 2 additions & 2 deletions tests/DatabaseTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function it_can_successfully_create_a_token(): void
/**
* @test
*/
public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exist()
public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exist(): void
{
$this->repository->create($this->user);

Expand All @@ -57,7 +57,7 @@ public function it_can_return_latest_sent_at_as_empty_string_if_token_doesnt_exi
/**
* @test
*/
public function it_can_return_latest_sent_at_as_date_time_string_if_token_exists()
public function it_can_return_latest_sent_at_as_date_time_string_if_token_exists(): void
{
$token = $this->repository->create($this->user);

Expand Down
7 changes: 2 additions & 5 deletions tests/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class ListenerTest extends TestCase
{
private TokenBrokerInterface|m\LegacyMockInterface|m\MockInterface $tokenBroker;

/**
* @var m\Mock
*/
private $verifiableUser;
private m\Mock $verifiableUser;

public function setUp(): void
{
Expand Down Expand Up @@ -81,7 +78,7 @@ public function it_can_listen_successfully(): void
*
* @throws Exception
*/
public function it_should_not_queue()
public function it_should_not_queue(): void
{
Event::fake();

Expand Down
4 changes: 2 additions & 2 deletions tests/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class User extends Model implements AuthenticatableContract
use Notifiable;
use HasFactory;

public $timestamps = false;
public bool $timestamps = false;

protected $fillable = [
protected array $fillable = [
'name',
];
}
4 changes: 1 addition & 3 deletions tests/Models/VerifiableUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ class VerifiableUser extends Model implements AuthenticatableContract, IMustVeri
use Notifiable;
use HasFactory;

public $timestamps = false;
public bool $timestamps = false;

protected $fillable = [
'name',
];

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'users';
}
4 changes: 2 additions & 2 deletions tests/QueueableListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class QueueableListenerTest extends TestCase
{
/** @test * */
public function it_should_be_queueable()
/** @test **/
public function it_should_be_queueable(): void
{
Event::assertListening(
Registered::class,
Expand Down
11 changes: 2 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ protected function getEnvironmentSetUp($app): void

/**
* Call the given middleware.
*
* @param string|string[] $middleware
* @param string $method
* @param array $data
*/
protected function callMiddleware($middleware, string $method = 'GET', array $data = [])
protected function callMiddleware(string|array $middleware, string $method = 'GET', array $data = [])
{
return $this->call(
$method,
Expand All @@ -64,11 +60,8 @@ protected function callMiddleware($middleware, string $method = 'GET', array $da

/**
* Make a dummy route with the given middleware applied.
*
* @param string $method
* @param string|string[] $middleware
*/
protected function makeMiddlewareRoute(string $method, $middleware): string
protected function makeMiddlewareRoute(string $method, array|string $middleware): string
{
$method = strtolower($method);

Expand Down
8 changes: 1 addition & 7 deletions tests/TokenBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@

class TokenBrokerTest extends TestCase
{
/**
* @var m\Mock
*/
private $user;
private m\Mock $user;

/**
* @var TokenRepositoryInterface|m\LegacyMockInterface|m\MockInterface
*/
private m\LegacyMockInterface|m\MockInterface|TokenRepositoryInterface $repository;

public function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class CreateMobileVerificationTokensTestTable extends Migration
{
/** @var string */
private $userTable;
private string $userTable;

public function __construct()
{
Expand Down

0 comments on commit 424b964

Please sign in to comment.