Skip to content

Commit

Permalink
refactor: apply strict types and return types across tests and models
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Mar 1, 2025
1 parent 920eca4 commit 45564d7
Show file tree
Hide file tree
Showing 26 changed files with 279 additions and 203 deletions.
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"laravel/socialite": "~5.2"
},
"require-dev": {
"laravel/pint": "^1.2",
"larastan/larastan": "^2.4.0",
"sampoyigi/testbench": "dev-main as 1.0",
"pestphp/pest-plugin-laravel": "^3.0"
"laravel/pint": "^1.2",
"pestphp/pest-plugin-laravel": "^3.0",
"rector/rector": "*",
"sampoyigi/testbench": "dev-main as 1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -51,10 +52,17 @@
}
},
"scripts": {
"test": "vendor/bin/pest --coverage --exactly=100",
"test-coverage": "vendor/bin/pest --coverage",
"test": "vendor/bin/pest --compact",
"test-coverage": "vendor/bin/pest --coverage --exactly=100 --compact",
"type-coverage": "vendor/bin/pest --type-coverage --min=100",
"format": "vendor/bin/pint",
"static": "vendor/bin/phpstan analyse --ansi --memory-limit 1056M"
"refactor": "vendor/bin/rector process --dry-run",
"static": "vendor/bin/phpstan analyse --ansi --memory-limit 1056M",
"test-suite": [
"@refactor",
"@static",
"@test-coverage"
]
},
"config": {
"allow-plugins": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
public function up(): void
{
Schema::create('igniter_socialite_providers', function(Blueprint $table) {
Schema::create('igniter_socialite_providers', function(Blueprint $table): void {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('user_id')->unsigned()->index()->nullable();
Expand All @@ -19,7 +21,7 @@ public function up()
});
}

public function down()
public function down(): void
{
Schema::dropIfExists('igniter_socialite_providers');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
public function up(): void
{
Schema::table('igniter_socialite_providers', function(Blueprint $table) {
Schema::table('igniter_socialite_providers', function(Blueprint $table): void {
$table->string('user_type')->nullable();
});

Expand All @@ -18,7 +20,7 @@ public function up()
]);
}

public function down()
public function down(): void
{
Schema::dropIfExists('igniter_socialite_providers');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Socialite\Database\Migrations;

use Illuminate\Database\Migrations\Migration;
Expand All @@ -8,15 +10,15 @@

return new class extends Migration
{
public function up()
public function up(): void
{
Schema::table('igniter_socialite_providers', function(Blueprint $table) {
Schema::table('igniter_socialite_providers', function(Blueprint $table): void {
$table->string('provider', 255)->change();
$table->string('provider_id', 255)->change();
$table->string('token', 255)->change();
$table->string('user_type', 255)->change();
});
}

public function down() {}
public function down(): void {}
};
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ parameters:
count: 1
path: src/Classes/BaseProvider.php

-
message: "#^Call to an undefined static method Laravel\\\\Socialite\\\\Facades\\\\Socialite\\:\\:extend\\(\\)\\.$#"
count: 1
path: src/Classes/BaseProvider.php

-
message: "#^Access to an undefined property object\\:\\:\\$id\\.$#"
count: 1
Expand All @@ -20,37 +15,7 @@ parameters:
count: 1
path: src/Classes/ProviderManager.php

-
message: "#^Call to an undefined method Illuminate\\\\Support\\\\Optional\\:\\:getKey\\(\\)\\.$#"
count: 1
path: src/Classes/ProviderManager.php

-
message: "#^Call to an undefined static method Igniter\\\\Socialite\\\\Models\\\\Provider\\:\\:find\\(\\)\\.$#"
count: 1
path: src/Classes/ProviderManager.php

-
message: "#^Call to an undefined static method Igniter\\\\Socialite\\\\Models\\\\Provider\\:\\:firstOrNew\\(\\)\\.$#"
count: 1
path: src/Classes/ProviderManager.php

-
message: "#^Call to an undefined static method Illuminate\\\\Support\\\\Str\\:\\:getClassId\\(\\)\\.$#"
count: 1
path: src/Classes/ProviderManager.php

-
message: "#^Call to an undefined method Laravel\\\\Socialite\\\\Contracts\\\\Provider\\:\\:scopes\\(\\)\\.$#"
count: 1
path: src/SocialiteProviders/Facebook.php

-
message: "#^Call to static method driver\\(\\) on an unknown class Socialite\\.$#"
count: 2
path: src/SocialiteProviders/Google.php

-
message: "#^Call to static method driver\\(\\) on an unknown class Socialite\\.$#"
count: 2
path: src/SocialiteProviders/Twitter.php
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- phpstan-baseline.neon

parameters:
Expand Down
33 changes: 33 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return RectorConfig::configure()
->withPaths([
__DIR__.'/database',
__DIR__.'/routes',
__DIR__.'/src',
__DIR__.'/tests',
])
->withImportNames(removeUnusedImports: true)
->withRules([
DeclareStrictTypesRector::class,
])
->withSkip([
CatchExceptionNameMatchingTypeRector::class,
ReturnNeverTypeRector::class,
ReturnTypeFromStrictNewArrayRector::class,
])
->withPhpSets(php83: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
);
10 changes: 6 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

use Igniter\Socialite\Classes\ProviderManager;

Route::group([
'prefix' => 'igniter/socialite',
'middleware' => ['web'],
], function() {
Route::any('{provider}/{action}', function($provider, $action) {
return \Igniter\Socialite\Classes\ProviderManager::runEntryPoint($provider, $action);
})->name('igniter_socialite_provider')->where('provider', '[a-zA-Z-]+')->where('action', '[a-zA-Z]+');
], function(): void {
Route::any('{provider}/{action}', fn($provider, $action) => (new ProviderManager())->runEntryPoint($provider, $action))->name('igniter_socialite_provider')->where('provider', '[a-zA-Z-]+')->where('action', '[a-zA-Z]+');
});
20 changes: 10 additions & 10 deletions src/Classes/BaseProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

declare(strict_types=1);

namespace Igniter\Socialite\Classes;

use Exception;
use Throwable;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Laravel\Socialite\AbstractUser;
use Igniter\Admin\Widgets\Form;
use Igniter\Socialite\Models\Settings;
use Illuminate\Support\Facades\Log;
Expand All @@ -12,18 +16,14 @@

abstract class BaseProvider
{
protected $driver;

protected $provider;

protected $settings;

protected static $configCallbacks = [];

public function __construct($driver = null)
public function __construct(protected $driver = null)
{
$this->driver = $driver;

$this->initialize();
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public function shouldConfirmEmail($providerUser)
return false;
}

public function handleProviderException(Exception $ex)
public function handleProviderException(Throwable $ex): void
{
if ($ex instanceof InvalidStateException) {
flash()->error('Invalid State');
Expand Down Expand Up @@ -140,18 +140,18 @@ abstract public function extendSettingsForm(Form $form);
/**
* Redirect the user to the OAuth Provider.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @return RedirectResponse
*/
abstract public function redirectToProvider();

/**
* Obtain the user information from provider.
*
* @return \Laravel\Socialite\AbstractUser
* @return AbstractUser
*/
abstract public function handleProviderCallback();

public static function extendConfig(callable $callback)
public static function extendConfig(callable $callback): void
{
self::$configCallbacks[] = $callback;
}
Expand Down
Loading

0 comments on commit 45564d7

Please sign in to comment.