Skip to content

Commit

Permalink
Adding updates to php stan and setting level to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed May 19, 2024
1 parent df2fe12 commit a5f86d6
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 151 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"orchestra/testbench": "^9.0",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-laravel": "^2.4",
"larastan/larastan": "^2.0",
"phpstan/phpstan": "^1.11"
},
"autoload": {
Expand Down
13 changes: 4 additions & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

services:
-
class: Devdojo\Auth\PHPStan\Extensions\ConfigExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
- vendor/larastan/larastan/extension.neon

parameters:
level: max
paths:
- src
- packages/devdojo/auth/src
- vendor/devdojo/auth/src
level: 1
excludePaths:
- /Users/tonylea/Sites/auth/vendor
7 changes: 4 additions & 3 deletions src/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class AuthServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
* @return void
*/
public function boot()
public function boot() : void
{

Route::middlewareGroup('two-factor-challenged', [TwoFactorChallenged::class]);
Expand Down Expand Up @@ -74,7 +75,7 @@ public function boot()
//app()->register(\October\Rain\Config\ServiceProvider::class);
}

private function registerAuthFolioDirectory()
private function registerAuthFolioDirectory() : void
{
$pagesDirectory = __DIR__.'/../resources/views/pages';
if (File::exists($pagesDirectory)) {
Expand All @@ -86,7 +87,7 @@ private function registerAuthFolioDirectory()
}
}

private function registerVoltDirectory()
private function registerVoltDirectory() : void
{
Volt::mount([
__DIR__.'/../resources/views/pages',
Expand Down
20 changes: 10 additions & 10 deletions src/Http/Controllers/SocialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Devdojo\Auth\Http\Controllers;

use App\Models\User;
use Devdojo\Auth\Models\User;
use Devdojo\Auth\Models\SocialProvider;
use Devdojo\Auth\Models\SocialProviderUser;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -35,7 +35,7 @@ public function callback(Request $request, $driver)
DB::transaction(function () use ($socialiteUser, $driver) {
// Attempt to find the user based on the social provider's ID and slug
$socialProviderUser = SocialProviderUser::where('provider_slug', $driver)
->where('provider_user_id', $socialiteUser->id)
->where('provider_user_id', $socialiteUser->getId())
->first();

if ($socialProviderUser) {
Expand All @@ -46,7 +46,7 @@ public function callback(Request $request, $driver)
}

// Check if the email from the social provider already exists in the User table
$user = User::where('email', $socialiteUser->email)->first();
$user = User::where('email', $socialiteUser->getEmail())->first();

if ($user) {
// Inform the user that an account with this email already exists
Expand All @@ -55,8 +55,8 @@ public function callback(Request $request, $driver)

// No user exists, register a new user
$newUser = User::create([
'name' => $socialiteUser->name,
'email' => $socialiteUser->email,
'name' => $socialiteUser->getName(),
'email' => $socialiteUser->getEmail(),
// Add other fields as necessary
]);

Expand All @@ -65,11 +65,11 @@ public function callback(Request $request, $driver)

// Now add the social provider info for this new user
$newUser->addOrUpdateSocialProviderUser($driver, [
'provider_user_id' => $socialiteUser->id,
'nickname' => $socialiteUser->nickname,
'name' => $socialiteUser->name,
'email' => $socialiteUser->email,
'avatar' => $socialiteUser->avatar,
'provider_user_id' => $socialiteUser->getId(),
'nickname' => $socialiteUser->getNickname(),
'name' => $socialiteUser->getName(),
'email' => $socialiteUser->getEmail(),
'avatar' => $socialiteUser->getAvatar(),
'provider_data' => json_encode($socialiteUser->user),
'token' => $socialiteUser->token,
'refresh_token' => $socialiteUser->refreshToken,
Expand Down
4 changes: 2 additions & 2 deletions src/Livewire/Setup/Logo.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function logoValue()

$logo = match ($this->logo_type) {
'image' => $this->logo_image,
'svg' => $this->logo_svg,
'text' => $this->logo_text
'svg' => $this->logo_svg_string,
'text' => $this->logo_image_src
};

return $logo;
Expand Down
6 changes: 6 additions & 0 deletions src/Models/SocialProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;

/**
* Class User
*
* @property string|null $client_id
* @property string|null $client_secret
*/
class SocialProvider extends Model
{
use Sushi;
Expand Down
17 changes: 13 additions & 4 deletions src/Models/SocialProviderUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SocialProviderUser extends Model
{
Expand Down Expand Up @@ -33,14 +34,22 @@ class SocialProviderUser extends Model
'provider_data' => 'array',
];

// Define a relationship to the User model
public function user()
/**
* Get the user that belongs to this SocialProvderUser
*
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}

// Define a relationship to the SocialProvider model via Sushi
public function socialProvider()
/**
* Get the social provider for the social provider user.
*
* @return BelongsTo
*/
public function socialProvider(): BelongsTo
{
return $this->belongsTo(SocialProvider::class, 'provider_slug', 'slug');
}
Expand Down
1 change: 1 addition & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property \Illuminate\Support\Carbon|null $two_factor_confirmed_at
* @property \Illuminate\Database\Eloquent\Relations\HasMany $socialProviders
*/
class User extends Authenticatable implements MustVerifyEmail
{
Expand Down
30 changes: 0 additions & 30 deletions src/PHPStan/Extensions/ConfigExtension.php

This file was deleted.

20 changes: 13 additions & 7 deletions src/Traits/HasSocialProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
namespace Devdojo\Auth\Traits;

use Devdojo\Auth\Models\SocialProviderUser;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Collection;

trait HasSocialProviders
{
/**
* Relationship with SocialProviderUser.
*
* @return HasMany
*/
public function socialProviders()
public function socialProviders(): HasMany
{
return $this->hasMany(SocialProviderUser::class);
}

/**
* Retrieve a list of social providers linked to the user.
*
* @return Collection
*/
public function getLinkedSocialProvidersAttribute()
public function getLinkedSocialProvidersAttribute(): Collection
{
return $this->socialProviders->map(function ($providerUser) {
return collect($this->socialProviders->get())->map(function (SocialProviderUser $providerUser) {
return $providerUser->socialProvider;
});
}
Expand All @@ -30,7 +36,7 @@ public function getLinkedSocialProvidersAttribute()
* @param string $providerSlug The slug of the social provider.
* @return SocialProviderUser|null
*/
public function getSocialProviderUser($providerSlug)
public function getSocialProviderUser(string $providerSlug): ?SocialProviderUser
{
return $this->socialProviders->firstWhere('provider_slug', $providerSlug);
}
Expand All @@ -41,7 +47,7 @@ public function getSocialProviderUser($providerSlug)
* @param string $providerSlug The slug of the social provider.
* @return bool
*/
public function hasSocialProvider($providerSlug)
public function hasSocialProvider(string $providerSlug): bool
{
return $this->getSocialProviderUser($providerSlug) !== null;
}
Expand All @@ -50,10 +56,10 @@ public function hasSocialProvider($providerSlug)
* Add or update social provider user information for a given provider.
*
* @param string $providerSlug The slug of the social provider.
* @param array $data Data to store/update for the provider.
* @param array<string, mixed> $data Data to store/update for the provider.
* @return SocialProviderUser
*/
public function addOrUpdateSocialProviderUser($providerSlug, array $data)
public function addOrUpdateSocialProviderUser(string $providerSlug, array $data): SocialProviderUser
{
$providerUser = $this->getSocialProviderUser($providerSlug);

Expand Down
86 changes: 0 additions & 86 deletions src/Traits/HasTwoFactorAuth.php

This file was deleted.

0 comments on commit a5f86d6

Please sign in to comment.