diff --git a/resources/views/auth/confirm-password.blade.php b/resources/views/auth/confirm-password.blade.php index 8e074a2..8ce0226 100644 --- a/resources/views/auth/confirm-password.blade.php +++ b/resources/views/auth/confirm-password.blade.php @@ -10,9 +10,10 @@ @csrf
- - + + +
diff --git a/resources/views/auth/forgot-password.blade.php b/resources/views/auth/forgot-password.blade.php index 4f6430e..ea89b1d 100644 --- a/resources/views/auth/forgot-password.blade.php +++ b/resources/views/auth/forgot-password.blade.php @@ -20,9 +20,10 @@ @csrf
- - + + +
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 4fab6d0..26f78cd 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -17,7 +17,7 @@
+ :value="old('name')" required autofocus autocomplete="on" />
diff --git a/resources/views/auth/verify-email.blade.php b/resources/views/auth/verify-email.blade.php index 80e9674..98590b1 100644 --- a/resources/views/auth/verify-email.blade.php +++ b/resources/views/auth/verify-email.blade.php @@ -4,7 +4,7 @@ {{ __('filament-companies::default.headings.auth.verify_email.verification_link_not_sent') }}
- @if (session('status') == 'verification-link-sent') + @if (session('status') === 'verification-link-sent')
{{ __('filament-companies::default.headings.auth.verify_email.verification_link_sent') }}
diff --git a/resources/views/companies/company-employee-manager.blade.php b/resources/views/companies/company-employee-manager.blade.php index fff8699..1ad2a79 100644 --- a/resources/views/companies/company-employee-manager.blade.php +++ b/resources/views/companies/company-employee-manager.blade.php @@ -44,11 +44,11 @@ class="{{ isset($addCompanyEmployeeForm['role']) && $addCompanyEmployeeForm['rol
+ class="{{ $addCompanyEmployeeForm['role'] === $role->key ? 'font-semibold' : '' }} text-sm text-gray-600 dark:text-gray-400"> {{ $role->name }}
- @if ($addCompanyEmployeeForm['role'] == $role->key) + @if ($addCompanyEmployeeForm['role'] === $role->key)
+ class="{{ $currentRole === $role->key ? 'font-semibold' : '' }} text-sm text-gray-600 dark:text-gray-400"> {{ $role->name }}
- @if ($currentRole == $role->key) + @if ($currentRole === $role->key) - +
diff --git a/resources/views/components/banner.blade.php b/resources/views/components/banner.blade.php index 3dcd8fa..6c62763 100644 --- a/resources/views/components/banner.blade.php +++ b/resources/views/components/banner.blade.php @@ -1,10 +1,10 @@ @props(['style' => session('flash.bannerStyle', 'success'), 'message' => session('flash.banner')]) -
true, 'style' => $style, 'message' => $message], JSON_THROW_ON_ERROR) }}" + :class="{ 'bg-primary-500': style == 'success', 'bg-red-700': style == 'danger', 'bg-gray-500': style != 'success' && style != 'danger' }" + style="display: none;" + x-show="show && message" + x-init=" document.addEventListener('banner-message', event => { style = event.detail.style; message = event.detail.message; @@ -14,15 +14,23 @@
- - - + + + - - + + - - + + @@ -36,8 +44,9 @@ class="-mr-1 flex p-2 rounded-md focus:outline-none sm:-mr-2 transition" :class="{ 'hover:bg-primary-600 focus:bg-primary-600': style == 'success', 'hover:bg-red-600 focus:bg-red-600': style == 'danger' }" aria-label="Dismiss" x-on:click="show = false"> - - + +
diff --git a/resources/views/components/modal.blade.php b/resources/views/components/modal.blade.php index 6cb1115..5304e96 100644 --- a/resources/views/components/modal.blade.php +++ b/resources/views/components/modal.blade.php @@ -13,7 +13,7 @@ @endphp
+ diff --git a/resources/views/filament/pages/companies/company_settings.blade.php b/resources/views/filament/pages/companies/company_settings.blade.php index 507ff56..2f7f2cb 100644 --- a/resources/views/filament/pages/companies/company_settings.blade.php +++ b/resources/views/filament/pages/companies/company_settings.blade.php @@ -8,7 +8,7 @@ - @if (Gate::check('delete', $company) && !$company->personal_company) + @if (!$company->personal_company && Gate::check('delete', $company))
@livewire(\Wallo\FilamentCompanies\Http\Livewire\DeleteCompanyForm::class, ['company' => $company])
diff --git a/resources/views/filament/pages/user/api-tokens.blade.php b/resources/views/filament/pages/user/api-tokens.blade.php index 87c5bb8..bb0e022 100644 --- a/resources/views/filament/pages/user/api-tokens.blade.php +++ b/resources/views/filament/pages/user/api-tokens.blade.php @@ -15,8 +15,8 @@ class="flex items-center justify-center space-x-2 rtl:space-x-reverse"> {{ __('filament-companies::default.modal_descriptions.api_token') }}
- diff --git a/resources/views/filament/pages/user/profile.blade.php b/resources/views/filament/pages/user/profile.blade.php index 3fbcfa5..179f814 100644 --- a/resources/views/filament/pages/user/profile.blade.php +++ b/resources/views/filament/pages/user/profile.blade.php @@ -5,48 +5,48 @@ @livewire(\Wallo\FilamentCompanies\Http\Livewire\UpdateProfileInformationForm::class)
- + @endif - @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()) && !is_null($user->password)) + @if (!is_null($user->password) && Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()))
@livewire(\Wallo\FilamentCompanies\Http\Livewire\UpdatePasswordForm::class)
- + @else
@livewire(\Wallo\FilamentCompanies\Http\Livewire\SetPasswordForm::class)
- + @endif - @if (Laravel\Fortify\Features::canManageTwoFactorAuthentication() && !is_null($user->password)) + @if (!is_null($user->password) && Laravel\Fortify\Features::canManageTwoFactorAuthentication())
@livewire(\Wallo\FilamentCompanies\Http\Livewire\TwoFactorAuthenticationForm::class)
- + @endif @if (Wallo\FilamentCompanies\Socialite::show())
@livewire(\Wallo\FilamentCompanies\Http\Livewire\ConnectedAccountsForm::class)
+ + @endif @if (!is_null($user->password)) - -
@livewire(\Wallo\FilamentCompanies\Http\Livewire\LogoutOtherBrowserSessionsForm::class)
- @endif - @if (Wallo\FilamentCompanies\FilamentCompanies::hasAccountDeletionFeatures() && is_null($user->password)) - + + @endif + @if (!is_null($user->password) && Wallo\FilamentCompanies\FilamentCompanies::hasAccountDeletionFeatures())
@livewire(\Wallo\FilamentCompanies\Http\Livewire\DeleteUserForm::class)
diff --git a/resources/views/profile/connected-accounts-form.blade.php b/resources/views/profile/connected-accounts-form.blade.php index 0f93d8f..3522ce8 100644 --- a/resources/views/profile/connected-accounts-form.blade.php +++ b/resources/views/profile/connected-accounts-form.blade.php @@ -10,7 +10,7 @@

- @if (count($this->accounts) == 0) + @if (count($this->accounts) === 0) {{ __('filament-companies::default.headings.profile.connected_accounts.no_connected_accounts') }} @else {{ __('filament-companies::default.headings.profile.connected_accounts.has_connected_accounts') }} @@ -25,7 +25,6 @@ @foreach ($this->providers as $provider) @php - $account = null; $account = $this->accounts->where('provider', $provider)->first(); @endphp @@ -35,7 +34,7 @@ @if (!is_null($account))
- @if (Wallo\FilamentCompanies\FilamentCompanies::managesProfilePhotos() && !is_null($account->avatar_path)) + @if (!is_null($account->avatar_path) && Wallo\FilamentCompanies\FilamentCompanies::managesProfilePhotos()) {{ __('filament-companies::default.buttons.use_avatar_as_profile_photo') }} @@ -43,7 +42,7 @@ @endif - @if ($this->accounts->count() > 1 || !is_null($this->user->password)) + @if (!is_null($this->user->password) || $this->accounts->count() > 1) diff --git a/resources/views/profile/logout-other-browser-sessions-form.blade.php b/resources/views/profile/logout-other-browser-sessions-form.blade.php index 15dfa25..2d8d533 100644 --- a/resources/views/profile/logout-other-browser-sessions-form.blade.php +++ b/resources/views/profile/logout-other-browser-sessions-form.blade.php @@ -36,9 +36,9 @@
- {{ $session->agent->platform() ? $session->agent->platform() : 'filament-companies::default.labels.unknown' }} + {{ $session->agent->platform() ?: 'filament-companies::default.labels.unknown' }} - - {{ $session->agent->browser() ? $session->agent->browser() : 'filament-companies::default.labels.unknown' }} + {{ $session->agent->browser() ?: 'filament-companies::default.labels.unknown' }}
diff --git a/resources/views/profile/two-factor-authentication-form.blade.php b/resources/views/profile/two-factor-authentication-form.blade.php index 3dce9a3..3b9f15f 100644 --- a/resources/views/profile/two-factor-authentication-form.blade.php +++ b/resources/views/profile/two-factor-authentication-form.blade.php @@ -42,7 +42,8 @@

- {{ __('filament-companies::default.labels.setup_key') }}: {{ decrypt($this->user->two_factor_secret) }} + {{ __('filament-companies::default.labels.setup_key') }} + : {{ decrypt($this->user->two_factor_secret) }}

@@ -50,7 +51,7 @@
+ value="{{ __('filament-companies::default.fields.code') }}"/> + wire:keydown.enter="confirmTwoFactorAuthentication"/> + class="mt-2"/>
@endif @endif @@ -76,8 +78,9 @@ class="mt-2" />

-
- @foreach (json_decode(decrypt($this->user->two_factor_recovery_codes), true) as $code) +
+ @foreach (json_decode(decrypt($this->user->two_factor_recovery_codes), true, 512, JSON_THROW_ON_ERROR) as $code)
{{ $code }}
@endforeach
diff --git a/resources/views/profile/update-profile-information-form.blade.php b/resources/views/profile/update-profile-information-form.blade.php index c212ab3..9ee1c0d 100644 --- a/resources/views/profile/update-profile-information-form.blade.php +++ b/resources/views/profile/update-profile-information-form.blade.php @@ -69,7 +69,7 @@ class="h-20 w-20 rounded-full object-cover"> wire:model.defer="state.email" /> - @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()) && ! $this->user->hasVerifiedEmail()) + @if (! $this->user->hasVerifiedEmail() && Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()))

{{ __('filament-companies::default.headings.profile.update_profile_information.verification_link_not_sent') }} diff --git a/src/Actions/GenerateRedirectForProvider.php b/src/Actions/GenerateRedirectForProvider.php index 2338ee3..039758d 100644 --- a/src/Actions/GenerateRedirectForProvider.php +++ b/src/Actions/GenerateRedirectForProvider.php @@ -2,6 +2,7 @@ namespace Wallo\FilamentCompanies\Actions; +use Symfony\Component\HttpFoundation\RedirectResponse; use Wallo\FilamentCompanies\Contracts\GeneratesProviderRedirect; use Laravel\Socialite\Facades\Socialite; @@ -11,9 +12,9 @@ class GenerateRedirectForProvider implements GeneratesProviderRedirect * Generates the redirect for a given provider. * * @param string $provider - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return RedirectResponse */ - public function generate(string $provider) + public function generate(string $provider): RedirectResponse { return Socialite::driver($provider)->redirect(); } diff --git a/src/Actions/UpdateCompanyEmployeeRole.php b/src/Actions/UpdateCompanyEmployeeRole.php index c832a81..1a4ac7d 100644 --- a/src/Actions/UpdateCompanyEmployeeRole.php +++ b/src/Actions/UpdateCompanyEmployeeRole.php @@ -2,6 +2,7 @@ namespace Wallo\FilamentCompanies\Actions; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Wallo\FilamentCompanies\Events\CompanyEmployeeUpdated; @@ -13,13 +14,14 @@ class UpdateCompanyEmployeeRole /** * Update the role for the given company employee. * - * @param mixed $user - * @param mixed $company - * @param int $companyEmployeeId - * @param string $role + * @param mixed $user + * @param mixed $company + * @param int $companyEmployeeId + * @param string $role * @return void + * @throws AuthorizationException */ - public function update($user, $company, $companyEmployeeId, string $role) + public function update(mixed $user, mixed $company, int $companyEmployeeId, string $role): void { Gate::forUser($user)->authorize('updateCompanyEmployee', $company); diff --git a/src/Actions/ValidateCompanyDeletion.php b/src/Actions/ValidateCompanyDeletion.php index c4a43be..b8ded6d 100644 --- a/src/Actions/ValidateCompanyDeletion.php +++ b/src/Actions/ValidateCompanyDeletion.php @@ -2,6 +2,7 @@ namespace Wallo\FilamentCompanies\Actions; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Facades\Gate; use Illuminate\Validation\ValidationException; @@ -10,11 +11,12 @@ class ValidateCompanyDeletion /** * Validate that the company can be deleted by the given user. * - * @param mixed $user - * @param mixed $company + * @param mixed $user + * @param mixed $company * @return void + * @throws AuthorizationException */ - public function validate($user, $company) + public function validate(mixed $user, mixed $company): void { Gate::forUser($user)->authorize('delete', $company); diff --git a/src/Company.php b/src/Company.php index 077dbb5..7f7338f 100644 --- a/src/Company.php +++ b/src/Company.php @@ -2,36 +2,41 @@ namespace Wallo\FilamentCompanies; +use App\Models\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Collection; abstract class Company extends Model { /** * Get the owner of the company. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function owner() + public function owner(): BelongsTo { return $this->belongsTo(FilamentCompanies::userModel(), 'user_id'); } /** - * Get all of the company's users including its owner. + * Get all the company's users including its owner. * - * @return \Illuminate\Support\Collection + * @return Collection */ - public function allUsers() + public function allUsers(): Collection { return $this->users->merge([$this->owner]); } /** - * Get all of the users that belong to the company. + * Get all the users that belong to the company. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function users() + public function users(): BelongsToMany { return $this->belongsToMany(FilamentCompanies::userModel(), FilamentCompanies::employeeshipModel()) ->withPivot('role') @@ -42,10 +47,10 @@ public function users() /** * Determine if the given user belongs to the company. * - * @param \App\Models\User $user + * @param User $user * @return bool */ - public function hasUser($user) + public function hasUser(User $user): bool { return $this->users->contains($user) || $user->ownsCompany($this); } @@ -56,7 +61,7 @@ public function hasUser($user) * @param string $email * @return bool */ - public function hasUserWithEmail(string $email) + public function hasUserWithEmail(string $email): bool { return $this->allUsers()->contains(function ($user) use ($email) { return $user->email === $email; @@ -66,21 +71,21 @@ public function hasUserWithEmail(string $email) /** * Determine if the given user has the given permission on the company. * - * @param \App\Models\User $user - * @param string $permission + * @param User $user + * @param string $permission * @return bool */ - public function userHasPermission($user, $permission) + public function userHasPermission(User $user, string $permission): bool { return $user->hasCompanyPermission($this, $permission); } /** - * Get all of the pending user invitations for the company. + * Get all the pending user invitations for the company. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function companyInvitations() + public function companyInvitations(): HasMany { return $this->hasMany(FilamentCompanies::companyInvitationModel()); } @@ -88,10 +93,10 @@ public function companyInvitations() /** * Remove the given user from the company. * - * @param \App\Models\User $user + * @param User $user * @return void */ - public function removeUser($user) + public function removeUser(User $user): void { if ($user->current_company_id === $this->id) { $user->forceFill([ @@ -103,11 +108,11 @@ public function removeUser($user) } /** - * Purge all of the company's resources. + * Purge all the company's resources. * * @return void */ - public function purge() + public function purge(): void { $this->owner()->where('current_company_id', $this->id) ->update(['current_company_id' => null]); diff --git a/src/CompanyInvitation.php b/src/CompanyInvitation.php deleted file mode 100644 index 4e2f9c1..0000000 --- a/src/CompanyInvitation.php +++ /dev/null @@ -1,28 +0,0 @@ -belongsTo(FilamentCompanies::companyModel()); - } -} diff --git a/src/ConfirmsPasswords.php b/src/ConfirmsPasswords.php index a7821b9..7f96ed2 100644 --- a/src/ConfirmsPasswords.php +++ b/src/ConfirmsPasswords.php @@ -14,21 +14,21 @@ trait ConfirmsPasswords * * @var bool */ - public $confirmingPassword = false; + public bool $confirmingPassword = false; /** * The ID of the operation being confirmed. * * @var string|null */ - public $confirmableId = null; + public ?string $confirmableId = null; /** * The user's password. * * @var string */ - public $confirmablePassword = ''; + public string $confirmablePassword = ''; /** * Start confirming the user's password. @@ -58,7 +58,7 @@ public function startConfirmingPassword(string $confirmableId) * * @return void */ - public function stopConfirmingPassword() + public function stopConfirmingPassword(): void { $this->confirmingPassword = false; $this->confirmableId = null; @@ -70,7 +70,7 @@ public function stopConfirmingPassword() * * @return void */ - public function confirmPassword() + public function confirmPassword(): void { if (! app(ConfirmPassword::class)(app(StatefulGuard::class), Auth::user(), $this->confirmablePassword)) { throw ValidationException::withMessages([ @@ -90,10 +90,10 @@ public function confirmPassword() /** * Ensure that the user's password has been recently confirmed. * - * @param int|null $maximumSecondsSinceConfirmation + * @param int|null $maximumSecondsSinceConfirmation * @return void */ - protected function ensurePasswordIsConfirmed($maximumSecondsSinceConfirmation = null) + protected function ensurePasswordIsConfirmed(int $maximumSecondsSinceConfirmation = null): void { $maximumSecondsSinceConfirmation = $maximumSecondsSinceConfirmation ?: config('auth.password_timeout', 900); @@ -103,10 +103,10 @@ protected function ensurePasswordIsConfirmed($maximumSecondsSinceConfirmation = /** * Determine if the user's password has been recently confirmed. * - * @param int|null $maximumSecondsSinceConfirmation + * @param int|null $maximumSecondsSinceConfirmation * @return bool */ - protected function passwordIsConfirmed($maximumSecondsSinceConfirmation = null) + protected function passwordIsConfirmed(int $maximumSecondsSinceConfirmation = null): bool { $maximumSecondsSinceConfirmation = $maximumSecondsSinceConfirmation ?: config('auth.password_timeout', 900); diff --git a/src/ConnectedAccount.php b/src/ConnectedAccount.php index ed44520..4caa97c 100644 --- a/src/ConnectedAccount.php +++ b/src/ConnectedAccount.php @@ -3,16 +3,16 @@ namespace Wallo\FilamentCompanies; use Illuminate\Database\Eloquent\Model; -use Wallo\FilamentCompanies\FilamentCompanies; +use Illuminate\Database\Eloquent\Relations\BelongsTo; abstract class ConnectedAccount extends Model { /** * Get the credentials used for authenticating services. * - * @return \Wallo\FilamentCompanies\Credentials + * @return Credentials */ - public function getCredentials() + public function getCredentials(): Credentials { return new Credentials($this); } @@ -20,21 +20,11 @@ public function getCredentials() /** * Get user of the connected account. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user() + public function user(): BelongsTo { - return $this->belongsTo(FilamentCompanies::userModel(), 'user_id'); - } - - /** - * Get the data that should be shared with Inertia. - * - * @return array - */ - public function getSharedInertiaData() - { - return $this->getSharedData(); + return $this->belongsTo(FilamentCompanies::userModel(), 'user_id', (FilamentCompanies::newUserModel())->getAuthIdentifierName()); } /** @@ -42,7 +32,7 @@ public function getSharedInertiaData() * * @return array */ - public function getSharedData() + public function getSharedData(): array { return [ 'id' => $this->id, diff --git a/src/Contracts/CreatesConnectedAccounts.php b/src/Contracts/CreatesConnectedAccounts.php index 976aaf7..fac9a48 100644 --- a/src/Contracts/CreatesConnectedAccounts.php +++ b/src/Contracts/CreatesConnectedAccounts.php @@ -2,18 +2,15 @@ namespace Wallo\FilamentCompanies\Contracts; -use Illuminate\Contracts\Auth\Authenticatable; use Laravel\Socialite\Contracts\User as ProviderUser; +/** + * @method \Illuminate\Database\Eloquent\Model create(\Illuminate\Foundation\Auth\User $user, \Illuminate\Database\Eloquent\Model $connectedAccount, string $provider, ProviderUser $providerUser) + */ interface CreatesConnectedAccounts { - /** - * Create a connected account for a given user. - * - * @param \Illuminate\Contracts\Auth\Authenticatable $user - * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \Wallo\FilamentCompanies\ConnectedAccount - */ - public function create(Authenticatable $user, string $provider, ProviderUser $providerUser); + // } + + + diff --git a/src/Contracts/CreatesUserFromProvider.php b/src/Contracts/CreatesUserFromProvider.php index 6dd0307..3b2de20 100644 --- a/src/Contracts/CreatesUserFromProvider.php +++ b/src/Contracts/CreatesUserFromProvider.php @@ -4,14 +4,10 @@ use Laravel\Socialite\Contracts\User as ProviderUserContract; +/** + * @method \Illuminate\Database\Eloquent\Model create(string $provider, ProviderUserContract $providerUser) + */ interface CreatesUserFromProvider { - /** - * Create a new user from a social provider user. - * - * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \App\Models\User - */ - public function create(string $provider, ProviderUserContract $providerUser); + // } diff --git a/src/Contracts/Credentials.php b/src/Contracts/Credentials.php index 72a6f34..cb74e4d 100644 --- a/src/Contracts/Credentials.php +++ b/src/Contracts/Credentials.php @@ -11,33 +11,33 @@ interface Credentials * * @return string */ - public function getId(); + public function getId(): string; /** * Get token for the credentials. * * @return string */ - public function getToken(); + public function getToken(): string; /** * Get the token secret for the credentials. * * @return string|null */ - public function getTokenSecret(); + public function getTokenSecret(): ?string; /** * Get the refresh token for the credentials. * * @return string|null */ - public function getRefreshToken(); + public function getRefreshToken(): ?string; /** * Get the expiry date for the credentials. * * @return DateTimeInterface|null */ - public function getExpiry(); + public function getExpiry(): ?DateTimeInterface; } diff --git a/src/Contracts/GeneratesProviderRedirect.php b/src/Contracts/GeneratesProviderRedirect.php index d48a198..f5f610f 100644 --- a/src/Contracts/GeneratesProviderRedirect.php +++ b/src/Contracts/GeneratesProviderRedirect.php @@ -2,13 +2,15 @@ namespace Wallo\FilamentCompanies\Contracts; +use Symfony\Component\HttpFoundation\RedirectResponse; + interface GeneratesProviderRedirect { /** * Generates the redirect for a given provider. * * @param string $provider - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return RedirectResponse */ - public function generate(string $provider); + public function generate(string $provider): RedirectResponse; } diff --git a/src/Contracts/HandlesInvalidState.php b/src/Contracts/HandlesInvalidState.php index fff6b92..ff299b8 100644 --- a/src/Contracts/HandlesInvalidState.php +++ b/src/Contracts/HandlesInvalidState.php @@ -9,8 +9,8 @@ interface HandlesInvalidState /** * Handle an invalid state exception from a Socialite provider. * - * @param \Laravel\Socialite\Two\InvalidStateException $exception - * @param callable $callback + * @param InvalidStateException $exception + * @param callable|null $callback */ public function handle(InvalidStateException $exception, callable $callback = null); } diff --git a/src/Contracts/ResolvesSocialiteUsers.php b/src/Contracts/ResolvesSocialiteUsers.php index 2a8e012..7d526bd 100644 --- a/src/Contracts/ResolvesSocialiteUsers.php +++ b/src/Contracts/ResolvesSocialiteUsers.php @@ -2,13 +2,15 @@ namespace Wallo\FilamentCompanies\Contracts; +use Laravel\Socialite\Contracts\User; + interface ResolvesSocialiteUsers { /** * Resolve the user for a given provider. * - * @param string $provider - * @return \Laravel\Socialite\Contracts\User + * @param string $provider + * @return User */ - public function resolve($provider); + public function resolve(string $provider): User; } diff --git a/src/Contracts/SetsUserPasswords.php b/src/Contracts/SetsUserPasswords.php index 287af81..7775205 100644 --- a/src/Contracts/SetsUserPasswords.php +++ b/src/Contracts/SetsUserPasswords.php @@ -2,14 +2,10 @@ namespace Wallo\FilamentCompanies\Contracts; +/** + * @method void set(\Illuminate\Foundation\Auth\User $user, array $input) + */ interface SetsUserPasswords { - /** - * Validate and sets the user's password. - * - * @param mixed $user - * @param array $input - * @return void - */ - public function set($user, array $input); + // } diff --git a/src/Contracts/UpdatesConnectedAccounts.php b/src/Contracts/UpdatesConnectedAccounts.php index 03ea6c3..d86b003 100644 --- a/src/Contracts/UpdatesConnectedAccounts.php +++ b/src/Contracts/UpdatesConnectedAccounts.php @@ -11,10 +11,10 @@ interface UpdatesConnectedAccounts * Update a given connected account. * * @param mixed $user - * @param \Wallo\FilamentCompanies\ConnectedAccount $connectedAccount + * @param ConnectedAccount $connectedAccount * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \Wallo\FilamentCompanies\ConnectedAccount + * @param User $providerUser + * @return ConnectedAccount */ - public function update($user, ConnectedAccount $connectedAccount, string $provider, User $providerUser); + public function update(mixed $user, ConnectedAccount $connectedAccount, string $provider, User $providerUser): ConnectedAccount; } diff --git a/src/Credentials.php b/src/Credentials.php index 133de6f..4942437 100644 --- a/src/Credentials.php +++ b/src/Credentials.php @@ -4,8 +4,10 @@ use DateTime; use DateTimeInterface; +use Exception; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; +use ReturnTypeWillChange; use Wallo\FilamentCompanies\Contracts\Credentials as CredentialsContract; use JsonSerializable; @@ -16,40 +18,40 @@ class Credentials implements CredentialsContract, Arrayable, Jsonable, JsonSeria * * @var string */ - protected $id; + protected mixed $id; /** * The credentials token. * * @var string */ - protected $token; + protected mixed $token; /** * The credentials token secret. * * @var string|null */ - protected $tokenSecret; + protected mixed $tokenSecret; /** * The credentials refresh token. * * @var string|null */ - protected $refreshToken; + protected mixed $refreshToken; /** - * The credentials expiry. + * The credentials' expiry. * * @var DateTimeInterface|null */ - protected $expiry; + protected mixed $expiry; /** * Create a new credentials instance. * - * @param \Wallo\FilamentCompanies\ConnectedAccount $connectedAccount + * @param ConnectedAccount $connectedAccount */ public function __construct(ConnectedAccount $connectedAccount) { @@ -65,7 +67,7 @@ public function __construct(ConnectedAccount $connectedAccount) * * @return string */ - public function getId() + public function getId(): string { return $this->id; } @@ -75,7 +77,7 @@ public function getId() * * @return string */ - public function getToken() + public function getToken(): string { return $this->token; } @@ -85,7 +87,7 @@ public function getToken() * * @return string|null */ - public function getTokenSecret() + public function getTokenSecret(): ?string { return $this->tokenSecret; } @@ -95,7 +97,7 @@ public function getTokenSecret() * * @return string|null */ - public function getRefreshToken() + public function getRefreshToken(): ?string { return $this->refreshToken; } @@ -103,9 +105,10 @@ public function getRefreshToken() /** * Get the expiry date for the credentials. * - * @return DateTimeInterface|null + * @return DateTime|DateTimeInterface|null + * @throws Exception */ - public function getExpiry() + public function getExpiry(): DateTime|DateTimeInterface|null { if (is_null($this->expiry)) { return null; @@ -118,8 +121,9 @@ public function getExpiry() * Get the instance as an array. * * @return array + * @throws Exception */ - public function toArray() + public function toArray(): array { return [ 'id' => $this->getId(), @@ -133,10 +137,11 @@ public function toArray() /** * Convert the object to its JSON representation. * - * @param int $options - * @return string + * @param int $options + * @return array|string + * @throws Exception */ - public function toJson($options = 0) + public function toJson($options = 0): array|string { return $this->toArray(); } @@ -144,9 +149,10 @@ public function toJson($options = 0) /** * Specify data which should be serialized to JSON. * - * @return mixed + * @return array + * @throws Exception */ - public function jsonSerialize() + #[ReturnTypeWillChange] public function jsonSerialize(): array { return $this->toArray(); } @@ -155,9 +161,10 @@ public function jsonSerialize() * Convert the object instance to a string. * * @return string + * @throws Exception */ - public function __toString() + public function __toString(): string { - return json_encode($this->toJson()); + return json_encode($this->toJson(), JSON_THROW_ON_ERROR); } } diff --git a/src/Events/AddingCompany.php b/src/Events/AddingCompany.php index 75524f0..9960df0 100644 --- a/src/Events/AddingCompany.php +++ b/src/Events/AddingCompany.php @@ -13,7 +13,7 @@ class AddingCompany * * @var mixed */ - public $owner; + public mixed $owner; /** * Create a new event instance. @@ -21,7 +21,7 @@ class AddingCompany * @param mixed $owner * @return void */ - public function __construct($owner) + public function __construct(mixed $owner) { $this->owner = $owner; } diff --git a/src/Events/AddingCompanyEmployee.php b/src/Events/AddingCompanyEmployee.php index 04519fb..9d02b0e 100644 --- a/src/Events/AddingCompanyEmployee.php +++ b/src/Events/AddingCompanyEmployee.php @@ -13,14 +13,14 @@ class AddingCompanyEmployee * * @var mixed */ - public $company; + public mixed $company; /** * The company employee being added. * * @var mixed */ - public $user; + public mixed $user; /** * Create a new event instance. @@ -29,7 +29,7 @@ class AddingCompanyEmployee * @param mixed $user * @return void */ - public function __construct($company, $user) + public function __construct(mixed $company, mixed $user) { $this->company = $company; $this->user = $user; diff --git a/src/Events/CompanyEmployeeAdded.php b/src/Events/CompanyEmployeeAdded.php index 3bb7728..6f24ba7 100644 --- a/src/Events/CompanyEmployeeAdded.php +++ b/src/Events/CompanyEmployeeAdded.php @@ -13,14 +13,14 @@ class CompanyEmployeeAdded * * @var mixed */ - public $company; + public mixed $company; /** * The company employee that was added. * * @var mixed */ - public $user; + public mixed $user; /** * Create a new event instance. @@ -29,7 +29,7 @@ class CompanyEmployeeAdded * @param mixed $user * @return void */ - public function __construct($company, $user) + public function __construct(mixed $company, mixed $user) { $this->company = $company; $this->user = $user; diff --git a/src/Events/CompanyEmployeeRemoved.php b/src/Events/CompanyEmployeeRemoved.php index d3f7b80..4e55fc0 100644 --- a/src/Events/CompanyEmployeeRemoved.php +++ b/src/Events/CompanyEmployeeRemoved.php @@ -13,14 +13,14 @@ class CompanyEmployeeRemoved * * @var mixed */ - public $company; + public mixed $company; /** * The company employee that was removed. * * @var mixed */ - public $user; + public mixed $user; /** * Create a new event instance. @@ -29,7 +29,7 @@ class CompanyEmployeeRemoved * @param mixed $user * @return void */ - public function __construct($company, $user) + public function __construct(mixed $company, mixed $user) { $this->company = $company; $this->user = $user; diff --git a/src/Events/CompanyEmployeeUpdated.php b/src/Events/CompanyEmployeeUpdated.php index 4c1229c..4796968 100644 --- a/src/Events/CompanyEmployeeUpdated.php +++ b/src/Events/CompanyEmployeeUpdated.php @@ -13,14 +13,14 @@ class CompanyEmployeeUpdated * * @var mixed */ - public $company; + public mixed $company; /** * The company employee that was updated. * * @var mixed */ - public $user; + public mixed $user; /** * Create a new event instance. @@ -29,7 +29,7 @@ class CompanyEmployeeUpdated * @param mixed $user * @return void */ - public function __construct($company, $user) + public function __construct(mixed $company, mixed $user) { $this->company = $company; $this->user = $user; diff --git a/src/Events/CompanyEvent.php b/src/Events/CompanyEvent.php index d85d509..3b886af 100644 --- a/src/Events/CompanyEvent.php +++ b/src/Events/CompanyEvent.php @@ -2,6 +2,7 @@ namespace Wallo\FilamentCompanies\Events; +use App\Models\Company; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -13,17 +14,17 @@ abstract class CompanyEvent /** * The company instance. * - * @var \App\Models\Company + * @var Company */ - public $company; + public Company $company; /** * Create a new event instance. * - * @param \App\Models\Company $company + * @param Company $company * @return void */ - public function __construct($company) + public function __construct(Company $company) { $this->company = $company; } diff --git a/src/Events/ConnectedAccountEvent.php b/src/Events/ConnectedAccountEvent.php index cc9468c..9ead5d0 100644 --- a/src/Events/ConnectedAccountEvent.php +++ b/src/Events/ConnectedAccountEvent.php @@ -2,6 +2,7 @@ namespace Wallo\FilamentCompanies\Events; +use App\Models\ConnectedAccount; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -13,17 +14,17 @@ abstract class ConnectedAccountEvent /** * The connected account instance. * - * @var \App\Models\ConnectedAccount + * @var ConnectedAccount */ - public $connectedAccount; + public ConnectedAccount $connectedAccount; /** * Create a new event instance. * - * @param \App\Models\ConnectedAccount $connectedAccount + * @param ConnectedAccount $connectedAccount * @return void */ - public function __construct($connectedAccount) + public function __construct(ConnectedAccount $connectedAccount) { $this->connectedAccount = $connectedAccount; } diff --git a/src/Events/InvitingCompanyEmployee.php b/src/Events/InvitingCompanyEmployee.php index 2a72aa6..3a63327 100644 --- a/src/Events/InvitingCompanyEmployee.php +++ b/src/Events/InvitingCompanyEmployee.php @@ -13,21 +13,21 @@ class InvitingCompanyEmployee * * @var mixed */ - public $company; + public mixed $company; /** * The email address of the invitee. * * @var mixed */ - public $email; + public mixed $email; /** * The role of the invitee. * * @var mixed */ - public $role; + public mixed $role; /** * Create a new event instance. @@ -37,7 +37,7 @@ class InvitingCompanyEmployee * @param mixed $role * @return void */ - public function __construct($company, $email, $role) + public function __construct(mixed $company, mixed $email, mixed $role) { $this->company = $company; $this->email = $email; diff --git a/src/Events/RemovingCompanyEmployee.php b/src/Events/RemovingCompanyEmployee.php index 6ea81f4..348b0ef 100644 --- a/src/Events/RemovingCompanyEmployee.php +++ b/src/Events/RemovingCompanyEmployee.php @@ -13,14 +13,14 @@ class RemovingCompanyEmployee * * @var mixed */ - public $company; + public mixed $company; /** * The company employee being removed. * * @var mixed */ - public $user; + public mixed $user; /** * Create a new event instance. @@ -29,7 +29,7 @@ class RemovingCompanyEmployee * @param mixed $user * @return void */ - public function __construct($company, $user) + public function __construct(mixed $company, mixed $user) { $this->company = $company; $this->user = $user; diff --git a/src/Features.php b/src/Features.php index e0c65a4..d8fcd43 100644 --- a/src/Features.php +++ b/src/Features.php @@ -10,9 +10,9 @@ class Features * @param string $feature * @return bool */ - public static function enabled(string $feature) + public static function enabled(string $feature): bool { - return in_array($feature, config('filament-companies.features', [])); + return in_array($feature, config('filament-companies.features', []), true); } /** @@ -22,7 +22,7 @@ public static function enabled(string $feature) * @param string $option * @return bool */ - public static function optionEnabled(string $feature, string $option) + public static function optionEnabled(string $feature, string $option): bool { return static::enabled($feature) && config("filament-companies-options.{$feature}.{$option}") === true; @@ -33,7 +33,7 @@ public static function optionEnabled(string $feature, string $option) * * @return bool */ - public static function managesProfilePhotos() + public static function managesProfilePhotos(): bool { return static::enabled(static::profilePhotos()); } @@ -43,7 +43,7 @@ public static function managesProfilePhotos() * * @return bool */ - public static function hasApiFeatures() + public static function hasApiFeatures(): bool { return static::enabled(static::api()); } @@ -53,7 +53,7 @@ public static function hasApiFeatures() * * @return bool */ - public static function hasCompanyFeatures() + public static function hasCompanyFeatures(): bool { return static::enabled(static::companies()); } @@ -63,7 +63,7 @@ public static function hasCompanyFeatures() * * @return bool */ - public static function sendsCompanyInvitations() + public static function sendsCompanyInvitations(): bool { return static::optionEnabled(static::companies(), 'invitations'); } @@ -73,7 +73,7 @@ public static function sendsCompanyInvitations() * * @return bool */ - public static function hasTermsAndPrivacyPolicyFeature() + public static function hasTermsAndPrivacyPolicyFeature(): bool { return static::enabled(static::termsAndPrivacyPolicy()); } @@ -83,7 +83,7 @@ public static function hasTermsAndPrivacyPolicyFeature() * * @return bool */ - public static function hasAccountDeletionFeatures() + public static function hasAccountDeletionFeatures(): bool { return static::enabled(static::accountDeletion()); } @@ -93,7 +93,7 @@ public static function hasAccountDeletionFeatures() * * @return bool */ - public static function generatesMissingEmails() + public static function generatesMissingEmails(): bool { return static::enabled(static::generateMissingEmails()); } @@ -104,19 +104,19 @@ public static function generatesMissingEmails() * * @return bool */ - public static function hasCreateAccountOnFirstLoginFeatures() + public static function hasCreateAccountOnFirstLoginFeatures(): bool { return static::enabled(static::createAccountOnFirstLogin()); } /** * Determine if the application supports logging into existing - * accounts when registering with a provider who's email address + * accounts when registering with a provider whose email address * is already registered. * * @return bool */ - public static function hasLoginOnRegistrationFeatures() + public static function hasLoginOnRegistrationFeatures(): bool { return static::enabled(static::loginOnRegistration()); } @@ -126,17 +126,17 @@ public static function hasLoginOnRegistrationFeatures() * * @return bool */ - public static function hasProviderAvatarsFeature() + public static function hasProviderAvatarsFeature(): bool { return static::enabled(static::providerAvatars()); } /** - * Determine if the application should remember the users session om login. + * Determine if the application should remember the users session on login. * * @return bool */ - public static function hasRememberSessionFeatures() + public static function hasRememberSessionFeatures(): bool { return static::enabled(static::rememberSession()); } @@ -146,7 +146,7 @@ public static function hasRememberSessionFeatures() * * @return string */ - public static function profilePhotos() + public static function profilePhotos(): string { return 'profile-photos'; } @@ -156,7 +156,7 @@ public static function profilePhotos() * * @return string */ - public static function api() + public static function api(): string { return 'api'; } @@ -167,7 +167,7 @@ public static function api() * @param array $options * @return string */ - public static function companies(array $options = []) + public static function companies(array $options = []): string { if (! empty($options)) { config(['filament-companies-options.companies' => $options]); @@ -181,7 +181,7 @@ public static function companies(array $options = []) * * @return string */ - public static function termsAndPrivacyPolicy() + public static function termsAndPrivacyPolicy(): string { return 'terms'; } @@ -191,17 +191,17 @@ public static function termsAndPrivacyPolicy() * * @return string */ - public static function accountDeletion() + public static function accountDeletion(): string { return 'account-deletion'; } /** - * Enabled the generate missing emails feature. + * Enabled to generate missing emails feature. * * @return string */ - public static function generateMissingEmails() + public static function generateMissingEmails(): string { return 'generate-missing-emails'; } @@ -211,7 +211,7 @@ public static function generateMissingEmails() * * @return string */ - public static function createAccountOnFirstLogin() + public static function createAccountOnFirstLogin(): string { return 'create-account-on-first-login'; } @@ -221,7 +221,7 @@ public static function createAccountOnFirstLogin() * * @return string */ - public static function loginOnRegistration() + public static function loginOnRegistration(): string { return 'login-on-registration'; } @@ -231,7 +231,7 @@ public static function loginOnRegistration() * * @return string */ - public static function providerAvatars() + public static function providerAvatars(): string { return 'provider-avatars'; } @@ -241,7 +241,7 @@ public static function providerAvatars() * * @return string */ - public static function rememberSession() + public static function rememberSession(): string { return 'remember-session'; } diff --git a/src/FilamentCompanies.php b/src/FilamentCompanies.php index 60eaecf..0e6cdfd 100644 --- a/src/FilamentCompanies.php +++ b/src/FilamentCompanies.php @@ -19,63 +19,63 @@ class FilamentCompanies * * @var bool */ - public static $registersRoutes = true; + public static bool $registersRoutes = true; /** * The roles that are available to assign to users. * * @var array */ - public static $roles = []; + public static array $roles = []; /** * The permissions that exist within the application. * * @var array */ - public static $permissions = []; + public static array $permissions = []; /** * The default permissions that should be available to new entities. * * @var array */ - public static $defaultPermissions = []; + public static array $defaultPermissions = []; /** * The user model that should be used by Company. * * @var string */ - public static $userModel = 'App\\Models\\User'; + public static string $userModel = 'App\\Models\\User'; /** * The company model that should be used by Company. * * @var string */ - public static $companyModel = 'App\\Models\\Company'; + public static string $companyModel = 'App\\Models\\Company'; /** * The employeeship model that should be used by Company. * * @var string */ - public static $employeeshipModel = 'App\\Models\\Employeeship'; + public static string $employeeshipModel = 'App\\Models\\Employeeship'; /** * The company invitation model that should be used by Company. * * @var string */ - public static $companyInvitationModel = 'App\\Models\\CompanyInvitation'; + public static string $companyInvitationModel = 'App\\Models\\CompanyInvitation'; /** * Determine if Company has registered roles. * * @return bool */ - public static function hasRoles() + public static function hasRoles(): bool { return count(static::$roles) > 0; } @@ -83,10 +83,10 @@ public static function hasRoles() /** * Find the role with the given key. * - * @param string $key - * @return \Wallo\FilamentCompanies\Role + * @param string $key + * @return Role|null */ - public static function findRole(string $key) + public static function findRole(string $key): ?Role { return static::$roles[$key] ?? null; } @@ -97,9 +97,9 @@ public static function findRole(string $key) * @param string $key * @param string $name * @param array $permissions - * @return \Wallo\FilamentCompanies\Role + * @return Role */ - public static function role(string $key, string $name, array $permissions) + public static function role(string $key, string $name, array $permissions): Role { static::$permissions = collect(array_merge(static::$permissions, $permissions)) ->unique() @@ -117,7 +117,7 @@ public static function role(string $key, string $name, array $permissions) * * @return bool */ - public static function hasPermissions() + public static function hasPermissions(): bool { return count(static::$permissions) > 0; } @@ -128,7 +128,7 @@ public static function hasPermissions() * @param array $permissions * @return static */ - public static function permissions(array $permissions) + public static function permissions(array $permissions): static { static::$permissions = $permissions; @@ -141,7 +141,7 @@ public static function permissions(array $permissions) * @param array $permissions * @return static */ - public static function defaultApiTokenPermissions(array $permissions) + public static function defaultApiTokenPermissions(array $permissions): static { static::$defaultPermissions = $permissions; @@ -154,7 +154,7 @@ public static function defaultApiTokenPermissions(array $permissions) * @param array $permissions * @return array */ - public static function validPermissions(array $permissions) + public static function validPermissions(array $permissions): array { return array_values(array_intersect($permissions, static::$permissions)); } @@ -164,7 +164,7 @@ public static function validPermissions(array $permissions) * * @return bool */ - public static function managesProfilePhotos() + public static function managesProfilePhotos(): bool { return Features::managesProfilePhotos(); } @@ -174,7 +174,7 @@ public static function managesProfilePhotos() * * @return bool */ - public static function hasApiFeatures() + public static function hasApiFeatures(): bool { return Features::hasApiFeatures(); } @@ -184,7 +184,7 @@ public static function hasApiFeatures() * * @return bool */ - public static function hasCompanyFeatures() + public static function hasCompanyFeatures(): bool { return Features::hasCompanyFeatures(); } @@ -192,10 +192,10 @@ public static function hasCompanyFeatures() /** * Determine if a given user model utilizes the "HasCompanies" trait. * - * @param \Illuminate\Database\Eloquent\Model + * @param Model $user * @return bool */ - public static function userHasCompanyFeatures($user) + public static function userHasCompanyFeatures(Model $user): bool { return (array_key_exists(HasCompanies::class, class_uses_recursive($user)) || method_exists($user, 'currentCompany')) && @@ -207,7 +207,7 @@ public static function userHasCompanyFeatures($user) * * @return bool */ - public static function hasTermsAndPrivacyPolicyFeature() + public static function hasTermsAndPrivacyPolicyFeature(): bool { return Features::hasTermsAndPrivacyPolicyFeature(); } @@ -217,7 +217,7 @@ public static function hasTermsAndPrivacyPolicyFeature() * * @return bool */ - public static function hasAccountDeletionFeatures() + public static function hasAccountDeletionFeatures(): bool { return Features::hasAccountDeletionFeatures(); } @@ -225,10 +225,10 @@ public static function hasAccountDeletionFeatures() /** * Find a user instance by the given ID. * - * @param int $id + * @param int $id * @return mixed */ - public static function findUserByIdOrFail($id) + public static function findUserByIdOrFail(int $id): mixed { return static::newUserModel()->where('id', $id)->firstOrFail(); } @@ -239,7 +239,7 @@ public static function findUserByIdOrFail($id) * @param string $email * @return mixed */ - public static function findUserByEmailOrFail(string $email) + public static function findUserByEmailOrFail(string $email): mixed { return static::newUserModel()->where('email', $email)->firstOrFail(); } @@ -249,7 +249,7 @@ public static function findUserByEmailOrFail(string $email) * * @return string */ - public static function userModel() + public static function userModel(): string { return static::$userModel; } @@ -259,7 +259,7 @@ public static function userModel() * * @return mixed */ - public static function newUserModel() + public static function newUserModel(): mixed { $model = static::userModel(); @@ -272,7 +272,7 @@ public static function newUserModel() * @param string $model * @return static */ - public static function useUserModel(string $model) + public static function useUserModel(string $model): static { static::$userModel = $model; @@ -284,7 +284,7 @@ public static function useUserModel(string $model) * * @return string */ - public static function companyModel() + public static function companyModel(): string { return static::$companyModel; } @@ -294,7 +294,7 @@ public static function companyModel() * * @return mixed */ - public static function newCompanyModel() + public static function newCompanyModel(): mixed { $model = static::companyModel(); @@ -307,7 +307,7 @@ public static function newCompanyModel() * @param string $model * @return static */ - public static function useCompanyModel(string $model) + public static function useCompanyModel(string $model): static { static::$companyModel = $model; @@ -319,7 +319,7 @@ public static function useCompanyModel(string $model) * * @return string */ - public static function employeeshipModel() + public static function employeeshipModel(): string { return static::$employeeshipModel; } @@ -330,7 +330,7 @@ public static function employeeshipModel() * @param string $model * @return static */ - public static function useEmployeeshipModel(string $model) + public static function useEmployeeshipModel(string $model): static { static::$employeeshipModel = $model; @@ -342,7 +342,7 @@ public static function useEmployeeshipModel(string $model) * * @return string */ - public static function companyInvitationModel() + public static function companyInvitationModel(): string { return static::$companyInvitationModel; } @@ -353,7 +353,7 @@ public static function companyInvitationModel() * @param string $model * @return static */ - public static function useCompanyInvitationModel(string $model) + public static function useCompanyInvitationModel(string $model): static { static::$companyInvitationModel = $model; @@ -366,9 +366,9 @@ public static function useCompanyInvitationModel(string $model) * @param string $class * @return void */ - public static function createCompaniesUsing(string $class) + public static function createCompaniesUsing(string $class): void { - return app()->singleton(CreatesCompanies::class, $class); + app()->singleton(CreatesCompanies::class, $class); } /** @@ -377,9 +377,9 @@ public static function createCompaniesUsing(string $class) * @param string $class * @return void */ - public static function updateCompanyNamesUsing(string $class) + public static function updateCompanyNamesUsing(string $class): void { - return app()->singleton(UpdatesCompanyNames::class, $class); + app()->singleton(UpdatesCompanyNames::class, $class); } /** @@ -388,9 +388,9 @@ public static function updateCompanyNamesUsing(string $class) * @param string $class * @return void */ - public static function addCompanyEmployeesUsing(string $class) + public static function addCompanyEmployeesUsing(string $class): void { - return app()->singleton(AddsCompanyEmployees::class, $class); + app()->singleton(AddsCompanyEmployees::class, $class); } /** @@ -399,9 +399,9 @@ public static function addCompanyEmployeesUsing(string $class) * @param string $class * @return void */ - public static function inviteCompanyEmployeesUsing(string $class) + public static function inviteCompanyEmployeesUsing(string $class): void { - return app()->singleton(InvitesCompanyEmployees::class, $class); + app()->singleton(InvitesCompanyEmployees::class, $class); } /** @@ -410,9 +410,9 @@ public static function inviteCompanyEmployeesUsing(string $class) * @param string $class * @return void */ - public static function removeCompanyEmployeesUsing(string $class) + public static function removeCompanyEmployeesUsing(string $class): void { - return app()->singleton(RemovesCompanyEmployees::class, $class); + app()->singleton(RemovesCompanyEmployees::class, $class); } /** @@ -421,9 +421,9 @@ public static function removeCompanyEmployeesUsing(string $class) * @param string $class * @return void */ - public static function deleteCompaniesUsing(string $class) + public static function deleteCompaniesUsing(string $class): void { - return app()->singleton(DeletesCompanies::class, $class); + app()->singleton(DeletesCompanies::class, $class); } /** @@ -432,25 +432,25 @@ public static function deleteCompaniesUsing(string $class) * @param string $class * @return void */ - public static function deleteUsersUsing(string $class) + public static function deleteUsersUsing(string $class): void { - return app()->singleton(DeletesUsers::class, $class); + app()->singleton(DeletesUsers::class, $class); } /** * Find the path to a localized Markdown resource. * - * @param string $name + * @param string $name * @return string|null */ - public static function localizedMarkdownPath($name) + public static function localizedMarkdownPath(string $name): ?string { $localName = preg_replace('#(\.md)$#i', '.'.app()->getLocale().'$1', $name); return Arr::first([ resource_path('markdown/'.$localName), resource_path('markdown/'.$name), - ], function ($path) { + ], static function ($path) { return file_exists($path); }); } @@ -460,7 +460,7 @@ public static function localizedMarkdownPath($name) * * @return static */ - public static function ignoreRoutes() + public static function ignoreRoutes(): static { static::$registersRoutes = false; diff --git a/src/FilamentCompaniesServiceProvider.php b/src/FilamentCompaniesServiceProvider.php index f270477..7b61395 100644 --- a/src/FilamentCompaniesServiceProvider.php +++ b/src/FilamentCompaniesServiceProvider.php @@ -2,11 +2,11 @@ namespace Wallo\FilamentCompanies; +use Filament\Facades\Filament; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Illuminate\View\Compilers\BladeCompiler; use Laravel\Fortify\Fortify; -use Filament\Facades\Filament; use Livewire\Livewire; use Wallo\FilamentCompanies\Http\Livewire\ApiTokenManager; use Wallo\FilamentCompanies\Http\Livewire\CompanyEmployeeManager; @@ -39,13 +39,13 @@ class FilamentCompaniesServiceProvider extends ServiceProvider * * @return void */ - public function register() + public function register(): void { $this->mergeConfigFrom(__DIR__.'/../config/filament-companies.php', 'filament-companies'); $this->app->afterResolving(BladeCompiler::class, function () { - if (config('filament-companies.stack') === 'filament' && class_exists(Livewire::class)) { + if (class_exists(Livewire::class) && config('filament-companies.stack') === 'filament') { Livewire::component(UpdateProfileInformationForm::getName(), UpdateProfileInformationForm::class); Livewire::component(UpdatePasswordForm::getName(), UpdatePasswordForm::class); Livewire::component(TwoFactorAuthenticationForm::getName(), TwoFactorAuthenticationForm::class); @@ -77,7 +77,7 @@ public function register() * * @return void */ - public function boot() + public function boot(): void { $this->loadViewsFrom(__DIR__.'/../resources/views', 'filament-companies'); @@ -101,7 +101,7 @@ public function boot() * * @return void */ - protected function configurePublishing() + protected function configurePublishing(): void { if (! $this->app->runningInConsole()) { return; @@ -128,14 +128,13 @@ protected function configurePublishing() * * @return void */ - protected function configureRoutes() + protected function configureRoutes(): void { if (FilamentCompanies::$registersRoutes) { Route::group([ 'domain' => config('filament.domain'), 'middleware' => config('filament.middleware.base'), - 'name' => config('filament.'), - 'name' => config('filament-companies.terms_and_privacy_route_group_prefix'), + 'name' => config('filament.') ], function () { $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); }); @@ -147,7 +146,7 @@ protected function configureRoutes() * * @return void */ - protected function configureCommands() + protected function configureCommands(): void { if (! $this->app->runningInConsole()) { return; diff --git a/src/HasCompanies.php b/src/HasCompanies.php index fd8a549..5277dd4 100644 --- a/src/HasCompanies.php +++ b/src/HasCompanies.php @@ -2,6 +2,10 @@ namespace Wallo\FilamentCompanies; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Collection; use Illuminate\Support\Str; use Laravel\Sanctum\HasApiTokens; @@ -13,7 +17,7 @@ trait HasCompanies * @param mixed $company * @return bool */ - public function isCurrentCompany($company) + public function isCurrentCompany($company): bool { return $company->id === $this->currentCompany->id; } @@ -21,9 +25,9 @@ public function isCurrentCompany($company) /** * Get the current company of the user's filament-companies. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function currentCompany() + public function currentCompany(): BelongsTo { if (is_null($this->current_company_id) && $this->id) { $this->switchCompany($this->personalCompany()); @@ -38,7 +42,7 @@ public function currentCompany() * @param mixed $company * @return bool */ - public function switchCompany($company) + public function switchCompany($company): bool { if (! $this->belongsToCompany($company)) { return false; @@ -54,31 +58,31 @@ public function switchCompany($company) } /** - * Get all of the companies the user owns or belongs to. + * Get all the companies the user owns or belongs to. * - * @return \Illuminate\Support\Collection + * @return Collection */ - public function allCompanies() + public function allCompanies(): Collection { return $this->ownedCompanies->merge($this->companies)->sortBy('name'); } /** - * Get all of the companies the user owns. + * Get all the companies the user owns. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function ownedCompanies() + public function ownedCompanies(): HasMany { return $this->hasMany(FilamentCompanies::companyModel()); } /** - * Get all of the companies the user belongs to. + * Get all the companies the user belongs to. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function companies() + public function companies(): BelongsToMany { return $this->belongsToMany(FilamentCompanies::companyModel(), FilamentCompanies::employeeshipModel()) ->withPivot('role') @@ -91,7 +95,7 @@ public function companies() * * @return \App\Models\Company */ - public function personalCompany() + public function personalCompany(): \App\Models\Company { return $this->ownedCompanies->where('personal_company', true)->first(); } @@ -102,13 +106,13 @@ public function personalCompany() * @param mixed $company * @return bool */ - public function ownsCompany($company) + public function ownsCompany($company): bool { if (is_null($company)) { return false; } - return $this->id == $company->{$this->getForeignKey()}; + return $this->id === $company->{$this->getForeignKey()}; } /** @@ -117,7 +121,7 @@ public function ownsCompany($company) * @param mixed $company * @return bool */ - public function belongsToCompany($company) + public function belongsToCompany($company): bool { if (is_null($company)) { return false; @@ -132,16 +136,16 @@ public function belongsToCompany($company) * Get the role that the user has on the company. * * @param mixed $company - * @return \Wallo\FilamentCompanies\Role|null + * @return Role|null */ - public function companyRole($company) + public function companyRole($company): Role|null { if ($this->ownsCompany($company)) { return new OwnerRole; } if (! $this->belongsToCompany($company)) { - return; + return null; } $role = $company->users @@ -160,7 +164,7 @@ public function companyRole($company) * @param string $role * @return bool */ - public function hasCompanyRole($company, string $role) + public function hasCompanyRole($company, string $role): bool { if ($this->ownsCompany($company)) { return true; @@ -177,7 +181,7 @@ public function hasCompanyRole($company, string $role) * @param mixed $company * @return array */ - public function companyPermissions($company) + public function companyPermissions($company): array { if ($this->ownsCompany($company)) { return ['*']; @@ -197,7 +201,7 @@ public function companyPermissions($company) * @param string $permission * @return bool */ - public function hasCompanyPermission($company, string $permission) + public function hasCompanyPermission($company, string $permission): bool { if ($this->ownsCompany($company)) { return true; @@ -207,17 +211,21 @@ public function hasCompanyPermission($company, string $permission) return false; } - if (in_array(HasApiTokens::class, class_uses_recursive($this)) && - ! $this->tokenCan($permission) && - $this->currentAccessToken() !== null) { + $hasPermission = $this->tokenCan($permission); + $hasApiTokens = in_array(HasApiTokens::class, class_uses_recursive($this), true); + $hasAccessToken = $this->currentAccessToken() !== null; + + if (!$hasPermission && $hasApiTokens && $hasAccessToken) { return false; } $permissions = $this->companyPermissions($company); - return in_array($permission, $permissions) || - in_array('*', $permissions) || - (Str::endsWith($permission, ':create') && in_array('*:create', $permissions)) || - (Str::endsWith($permission, ':update') && in_array('*:update', $permissions)); + $hasDirectPermission = in_array($permission, $permissions, true); + $hasWildcardPermission = in_array('*', $permissions, true); + $hasCreatePermission = Str::endsWith($permission, ':create') && in_array('*:create', $permissions, true); + $hasUpdatePermission = Str::endsWith($permission, ':update') && in_array('*:update', $permissions, true); + + return $hasDirectPermission || $hasWildcardPermission || $hasCreatePermission || $hasUpdatePermission; } } diff --git a/src/HasConnectedAccounts.php b/src/HasConnectedAccounts.php index 81b8d1a..cbf27bd 100644 --- a/src/HasConnectedAccounts.php +++ b/src/HasConnectedAccounts.php @@ -2,6 +2,8 @@ namespace Wallo\FilamentCompanies; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Str; trait HasConnectedAccounts @@ -12,15 +14,17 @@ trait HasConnectedAccounts * @param mixed $connectedAccount * @return bool */ - public function isCurrentConnectedAccount($connectedAccount) + public function isCurrentConnectedAccount(mixed $connectedAccount): bool { return $connectedAccount->id === $this->currentConnectedAccount->id; } /** * Get the current connected account of the user's context. + * + * @return BelongsTo */ - public function currentConnectedAccount() + public function currentConnectedAccount(): BelongsTo { if (is_null($this->current_connected_account_id) && $this->id) { $this->switchConnectedAccount( @@ -37,7 +41,7 @@ public function currentConnectedAccount() * @param mixed $connectedAccount * @return bool */ - public function switchConnectedAccount($connectedAccount) + public function switchConnectedAccount(mixed $connectedAccount): bool { if (! $this->ownsConnectedAccount($connectedAccount)) { return false; @@ -58,18 +62,18 @@ public function switchConnectedAccount($connectedAccount) * @param mixed $connectedAccount * @return bool */ - public function ownsConnectedAccount($connectedAccount) + public function ownsConnectedAccount(mixed $connectedAccount): bool { - return $this->id == optional($connectedAccount)->user_id; + return $this->id === optional($connectedAccount)->user_id; } /** * Determine if the user has a specific account type. * - * @param string $accountType + * @param string $provider * @return bool */ - public function hasTokenFor(string $provider) + public function hasTokenFor(string $provider): bool { return $this->connectedAccounts->contains('provider', Str::lower($provider)); } @@ -77,10 +81,11 @@ public function hasTokenFor(string $provider) /** * Attempt to retrieve the token for a given provider. * - * @param string $provider + * @param string $provider + * @param null $default * @return mixed */ - public function getTokenFor(string $provider, $default = null) + public function getTokenFor(string $provider, $default = null): mixed { if ($this->hasTokenFor($provider)) { return $this->connectedAccounts @@ -98,9 +103,9 @@ public function getTokenFor(string $provider, $default = null) * * @param string $provider * @param string $id - * @return \Wallo\FilamentCompanies\ConnectedAccount + * @return ConnectedAccount */ - public function getConnectedAccountFor(string $provider, string $id) + public function getConnectedAccountFor(string $provider, string $id): ConnectedAccount { return $this->connectedAccounts ->where('provider', $provider) @@ -109,12 +114,12 @@ public function getConnectedAccountFor(string $provider, string $id) } /** - * Get all of the connected accounts belonging to the user. + * Get all the connected accounts belonging to the user. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function connectedAccounts() + public function connectedAccounts(): HasMany { - return $this->hasMany(Socialite::connectedAccountModel(), 'user_id'); + return $this->hasMany(Socialite::connectedAccountModel(), 'user_id', $this->getAuthIdentifierName()); } } diff --git a/src/HasProfilePhoto.php b/src/HasProfilePhoto.php index e7847d2..b6fa045 100644 --- a/src/HasProfilePhoto.php +++ b/src/HasProfilePhoto.php @@ -4,18 +4,17 @@ use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; -use Wallo\FilamentCompanies\Features; trait HasProfilePhoto { /** * Update the user's profile photo. * - * @param \Illuminate\Http\UploadedFile $photo + * @param UploadedFile $photo + * @param string $storagePath * @return void */ - public function updateProfilePhoto(UploadedFile $photo, $storagePath = 'profile-photos') + public function updateProfilePhoto(UploadedFile $photo, $storagePath = 'profile-photos'): void { tap($this->profile_photo_path, function ($previous) use ($photo, $storagePath) { $this->forceFill([ @@ -35,7 +34,7 @@ public function updateProfilePhoto(UploadedFile $photo, $storagePath = 'profile- * * @return void */ - public function deleteProfilePhoto() + public function deleteProfilePhoto(): void { if (! Features::managesProfilePhotos()) { return; @@ -57,8 +56,12 @@ public function deleteProfilePhoto() * * @return string */ - public function getProfilePhotoUrlAttribute() + public function getProfilePhotoUrlAttribute(): string { + if (filter_var($this->profile_photo_path, FILTER_VALIDATE_URL)) { + return $this->profile_photo_path; + } + return $this->profile_photo_path ? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path) : $this->defaultProfilePhotoUrl(); @@ -69,13 +72,13 @@ public function getProfilePhotoUrlAttribute() * * @return string */ - protected function defaultProfilePhotoUrl() + protected function defaultProfilePhotoUrl(): string { $name = trim(collect(explode(' ', $this->name))->map(function ($segment) { return mb_substr($segment, 0, 1); })->join(' ')); - return 'https://ui-avatars.com/api/?name='.urlencode($name).'&color=FFFFFF&background=111827'; + return sprintf("https://ui-avatars.com/api/?name=%s&color=FFFFFF&background=111827", urlencode($name)); } /** @@ -83,7 +86,7 @@ protected function defaultProfilePhotoUrl() * * @return string */ - protected function profilePhotoDisk() + protected function profilePhotoDisk(): string { return isset($_ENV['VAPOR_ARTIFACT_NAME']) ? 's3' : config('filament-companies.profile_photo_disk', 'public'); } diff --git a/src/Http/Controllers/CompanyInvitationController.php b/src/Http/Controllers/CompanyInvitationController.php index 860b232..4dd21a7 100644 --- a/src/Http/Controllers/CompanyInvitationController.php +++ b/src/Http/Controllers/CompanyInvitationController.php @@ -3,23 +3,31 @@ namespace Wallo\FilamentCompanies\Http\Controllers; use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Gate; use Wallo\FilamentCompanies\Contracts\AddsCompanyEmployees; -use Wallo\FilamentCompanies\CompanyInvitation; +use Wallo\FilamentCompanies\FilamentCompanies; +use Livewire\Redirector; +use Wallo\FilamentCompanies\InteractsWithBanner; class CompanyInvitationController extends Controller { + use InteractsWithBanner; /** * Accept a company invitation. * - * @param \Illuminate\Http\Request $request - * @param \Wallo\FilamentCompanies\CompanyInvitation $invitation - * @return \Illuminate\Http\RedirectResponse + * @param Request $request + * @param int $invitationId + * @return Redirector|RedirectResponse|null */ - public function accept(Request $request, CompanyInvitation $invitation) + public function accept(Request $request, int $invitationId): Redirector|RedirectResponse|null { + $model = FilamentCompanies::companyInvitationModel(); + + $invitation = $model::whereKey($invitationId)->firstOrFail(); + app(AddsCompanyEmployees::class)->add( $invitation->company->owner, $invitation->company, @@ -37,12 +45,17 @@ public function accept(Request $request, CompanyInvitation $invitation) /** * Cancel the given company invitation. * - * @param \Illuminate\Http\Request $request - * @param \Wallo\FilamentCompanies\CompanyInvitation $invitation - * @return \Illuminate\Http\RedirectResponse + * @param Request $request + * @param int $invitationId + * @return Redirector|RedirectResponse + * @throws AuthorizationException */ - public function destroy(Request $request, CompanyInvitation $invitation) + public function destroy(Request $request, int $invitationId): Redirector|RedirectResponse { + $model = FilamentCompanies::companyInvitationModel(); + + $invitation = $model::whereKey($invitationId)->firstOrFail(); + if (! Gate::forUser($request->user())->check('removeCompanyEmployee', $invitation->company)) { throw new AuthorizationException; } diff --git a/src/Http/Controllers/CurrentCompanyController.php b/src/Http/Controllers/CurrentCompanyController.php index e64030d..9412a03 100644 --- a/src/Http/Controllers/CurrentCompanyController.php +++ b/src/Http/Controllers/CurrentCompanyController.php @@ -2,21 +2,21 @@ namespace Wallo\FilamentCompanies\Http\Controllers; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Support\Facades\Auth; use Wallo\FilamentCompanies\FilamentCompanies; -use Wallo\FilamentCompanies\Pages\Companies\CompanySettings; +use Livewire\Redirector; class CurrentCompanyController extends Controller { /** * Update the authenticated user's current company. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse + * @param Request $request + * @return Redirector|RedirectResponse */ - public function update(Request $request) + public function update(Request $request): Redirector|RedirectResponse { $company = FilamentCompanies::newCompanyModel()->findOrFail($request->company_id); @@ -24,6 +24,6 @@ public function update(Request $request) abort(403); } - return back(); + return back(); } } diff --git a/src/Http/Controllers/Livewire/PrivacyPolicyController.php b/src/Http/Controllers/Livewire/PrivacyPolicyController.php index fd6b439..aa17aec 100644 --- a/src/Http/Controllers/Livewire/PrivacyPolicyController.php +++ b/src/Http/Controllers/Livewire/PrivacyPolicyController.php @@ -2,6 +2,9 @@ namespace Wallo\FilamentCompanies\Http\Controllers\Livewire; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Str; @@ -12,10 +15,10 @@ class PrivacyPolicyController extends Controller /** * Show the privacy policy for the application. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\View\View + * @param Request $request + * @return Application|Factory|View */ - public function show(Request $request) + public function show(Request $request): Application|Factory|View { $policyFile = FilamentCompanies::localizedMarkdownPath('policy.md'); diff --git a/src/Http/Controllers/Livewire/TermsOfServiceController.php b/src/Http/Controllers/Livewire/TermsOfServiceController.php index 1f6b0a1..b07a8b9 100644 --- a/src/Http/Controllers/Livewire/TermsOfServiceController.php +++ b/src/Http/Controllers/Livewire/TermsOfServiceController.php @@ -2,6 +2,9 @@ namespace Wallo\FilamentCompanies\Http\Controllers\Livewire; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Str; @@ -12,10 +15,10 @@ class TermsOfServiceController extends Controller /** * Show the terms of service for the application. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\View\View + * @param Request $request + * @return Application|Factory|View */ - public function show(Request $request) + public function show(Request $request): Application|Factory|View { $termsFile = FilamentCompanies::localizedMarkdownPath('terms.md'); diff --git a/src/Http/Livewire/ApiTokenManager.php b/src/Http/Livewire/ApiTokenManager.php index 14c7b6b..6ec9c5d 100644 --- a/src/Http/Livewire/ApiTokenManager.php +++ b/src/Http/Livewire/ApiTokenManager.php @@ -2,9 +2,12 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; use Filament\Notifications\Notification; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; +use Laravel\Sanctum\PersonalAccessToken; use Wallo\FilamentCompanies\FilamentCompanies; use Livewire\Component; @@ -44,7 +47,7 @@ class ApiTokenManager extends Component /** * The token that is currently having its permissions managed. * - * @var \Laravel\Sanctum\PersonalAccessToken|null + * @var PersonalAccessToken|null */ public $managingPermissionsFor; @@ -189,9 +192,9 @@ public function deleteApiToken() /** * Get the current user of the application. * - * @return mixed + * @return Authenticatable|User|null */ - public function getUserProperty() + public function getUserProperty(): Authenticatable|null|User { return Auth::user(); } diff --git a/src/Http/Livewire/CompanyEmployeeManager.php b/src/Http/Livewire/CompanyEmployeeManager.php index df75946..24c53ca 100644 --- a/src/Http/Livewire/CompanyEmployeeManager.php +++ b/src/Http/Livewire/CompanyEmployeeManager.php @@ -2,7 +2,12 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Actions\UpdateCompanyEmployeeRole; use Wallo\FilamentCompanies\Contracts\AddsCompanyEmployees; use Wallo\FilamentCompanies\Contracts\InvitesCompanyEmployees; @@ -11,7 +16,12 @@ use Wallo\FilamentCompanies\FilamentCompanies; use Wallo\FilamentCompanies\Role; use Livewire\Component; +use Livewire\Redirector; + +/** + * @property mixed $user + */ class CompanyEmployeeManager extends Component { /** @@ -79,7 +89,7 @@ class CompanyEmployeeManager extends Component * @param mixed $company * @return void */ - public function mount($company) + public function mount(mixed $company): void { $this->company = $company; } @@ -89,7 +99,7 @@ public function mount($company) * * @return void */ - public function addCompanyEmployee() + public function addCompanyEmployee(): void { $this->resetErrorBag(); @@ -122,10 +132,10 @@ public function addCompanyEmployee() /** * Cancel a pending company employee invitation. * - * @param int $invitationId + * @param int $invitationId * @return void */ - public function cancelCompanyInvitation($invitationId) + public function cancelCompanyInvitation(int $invitationId): void { if (! empty($invitationId)) { $model = FilamentCompanies::companyInvitationModel(); @@ -139,10 +149,10 @@ public function cancelCompanyInvitation($invitationId) /** * Allow the given user's role to be managed. * - * @param int $userId + * @param int $userId * @return void */ - public function manageRole($userId) + public function manageRole(int $userId): void { $this->currentlyManagingRole = true; $this->managingRoleFor = FilamentCompanies::findUserByIdOrFail($userId); @@ -152,10 +162,11 @@ public function manageRole($userId) /** * Save the role for the user being managed. * - * @param \Wallo\FilamentCompanies\Actions\UpdateCompanyEmployeeRole $updater + * @param UpdateCompanyEmployeeRole $updater * @return void + * @throws AuthorizationException */ - public function updateRole(UpdateCompanyEmployeeRole $updater) + public function updateRole(UpdateCompanyEmployeeRole $updater): void { $updater->update( $this->user, @@ -174,7 +185,7 @@ public function updateRole(UpdateCompanyEmployeeRole $updater) * * @return void */ - public function stopManagingRole() + public function stopManagingRole(): void { $this->currentlyManagingRole = false; } @@ -182,10 +193,10 @@ public function stopManagingRole() /** * Remove the currently authenticated user from the company. * - * @param \Wallo\FilamentCompanies\Contracts\RemovesCompanyEmployees $remover - * @return void + * @param RemovesCompanyEmployees $remover + * @return RedirectResponse|Redirector */ - public function leaveCompany(RemovesCompanyEmployees $remover) + public function leaveCompany(RemovesCompanyEmployees $remover): RedirectResponse|Redirector { $remover->remove( $this->user, @@ -203,10 +214,10 @@ public function leaveCompany(RemovesCompanyEmployees $remover) /** * Confirm that the given company employee should be removed. * - * @param int $userId + * @param int $userId * @return void */ - public function confirmCompanyEmployeeRemoval($userId) + public function confirmCompanyEmployeeRemoval(int $userId): void { $this->confirmingCompanyEmployeeRemoval = true; @@ -216,10 +227,10 @@ public function confirmCompanyEmployeeRemoval($userId) /** * Remove a company employee from the company. * - * @param \Wallo\FilamentCompanies\Contracts\RemovesCompanyEmployees $remover + * @param RemovesCompanyEmployees $remover * @return void */ - public function removeCompanyEmployee(RemovesCompanyEmployees $remover) + public function removeCompanyEmployee(RemovesCompanyEmployees $remover): void { $remover->remove( $this->user, @@ -237,9 +248,9 @@ public function removeCompanyEmployee(RemovesCompanyEmployees $remover) /** * Get the current user of the application. * - * @return mixed + * @return Authenticatable|User|null */ - public function getUserProperty() + public function getUserProperty(): Authenticatable|null|User { return Auth::user(); } @@ -249,7 +260,7 @@ public function getUserProperty() * * @return array */ - public function getRolesProperty() + public function getRolesProperty(): array { return collect(FilamentCompanies::$roles)->transform(function ($role) { return with($role->jsonSerialize(), function ($data) { @@ -265,9 +276,9 @@ public function getRolesProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::companies.company-employee-manager'); } diff --git a/src/Http/Livewire/ConnectedAccountsForm.php b/src/Http/Livewire/ConnectedAccountsForm.php index c2a8fe2..24b00ca 100644 --- a/src/Http/Livewire/ConnectedAccountsForm.php +++ b/src/Http/Livewire/ConnectedAccountsForm.php @@ -2,12 +2,20 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Wallo\FilamentCompanies\ConnectedAccount; use Wallo\FilamentCompanies\Socialite; use Wallo\FilamentCompanies\InteractsWithBanner; use Livewire\Component; +use Livewire\Redirector; use Wallo\FilamentCompanies\Pages\User\Profile; class ConnectedAccountsForm extends Component @@ -24,7 +32,7 @@ class ConnectedAccountsForm extends Component ]; /** - * Indicates whether or not removal of a provider is being confirmed. + * Indicates whether removal of a provider is being confirmed. * * @var bool */ @@ -36,12 +44,12 @@ class ConnectedAccountsForm extends Component public $selectedAccountId; /** - * Return all socialite providers and whether or not + * Return all socialite providers and whether * the application supports them. * * @return array */ - public function getProvidersProperty() + public function getProvidersProperty(): array { return Socialite::providers(); } @@ -49,9 +57,9 @@ public function getProvidersProperty() /** * Get the current user of the application. * - * @return mixed + * @return User|Authenticatable|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } @@ -62,7 +70,7 @@ public function getUserProperty() * @param mixed $accountId * @return void */ - public function confirmRemove($accountId) + public function confirmRemove(mixed $accountId): void { $this->selectedAccountId = $accountId; @@ -72,9 +80,10 @@ public function confirmRemove($accountId) /** * Set the providers avatar url as the users profile photo url. * - * @param mixed $accountId + * @param mixed $accountId + * @return RedirectResponse|Redirector */ - public function setAvatarAsProfilePhoto($accountId) + public function setAvatarAsProfilePhoto(mixed $accountId): RedirectResponse|Redirector { $account = Auth::user()->connectedAccounts ->where('user_id', ($user = Auth::user())->getAuthIdentifier()) @@ -94,7 +103,7 @@ public function setAvatarAsProfilePhoto($accountId) * @param mixed $accountId * @return void */ - public function removeConnectedAccount($accountId) + public function removeConnectedAccount(mixed $accountId): void { DB::table('connected_accounts') ->where('user_id', Auth::user()->getAuthIdentifier()) @@ -109,9 +118,9 @@ public function removeConnectedAccount($accountId) /** * Get the users connected accounts. * - * @return \Illuminate\Support\Collection + * @return Collection */ - public function getAccountsProperty() + public function getAccountsProperty(): Collection { return Auth::user()->connectedAccounts ->map(function (ConnectedAccount $account) { @@ -122,9 +131,9 @@ public function getAccountsProperty() /** * Render the component. * - * @return Illuminate\View\View + * @return Application|Factory|View */ - public function render() + public function render(): View|Factory|Application { return view('filament-companies::profile.connected-accounts-form'); } diff --git a/src/Http/Livewire/CreateCompanyForm.php b/src/Http/Livewire/CreateCompanyForm.php index f22bc52..56f276d 100644 --- a/src/Http/Livewire/CreateCompanyForm.php +++ b/src/Http/Livewire/CreateCompanyForm.php @@ -2,14 +2,17 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; +use Illuminate\Http\RedirectResponse; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Contracts\CreatesCompanies; -use Wallo\FilamentCompanies\RedirectsActions; use Livewire\Component; +use Livewire\Redirector; class CreateCompanyForm extends Component { - use RedirectsActions; /** * The component's state. @@ -21,24 +24,24 @@ class CreateCompanyForm extends Component /** * Create a new company. * - * @param \Wallo\FilamentCompanies\Contracts\CreatesCompanies $creator - * @return void + * @param CreatesCompanies $creator + * @return RedirectResponse|Redirector */ - public function createCompany(CreatesCompanies $creator) + public function createCompany(CreatesCompanies $creator): RedirectResponse|Redirector { $this->resetErrorBag(); $creator->create(Auth::user(), $this->state); - return $this->redirectPath($creator); + return redirect()->to(config('fortify.home')); } /** * Get the current user of the application. * - * @return mixed + * @return Authenticatable|User|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } @@ -46,9 +49,9 @@ public function getUserProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::companies.create-company-form'); } diff --git a/src/Http/Livewire/DeleteCompanyForm.php b/src/Http/Livewire/DeleteCompanyForm.php index 1c0cae0..4dad65e 100644 --- a/src/Http/Livewire/DeleteCompanyForm.php +++ b/src/Http/Livewire/DeleteCompanyForm.php @@ -2,16 +2,17 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Actions\ValidateCompanyDeletion; use Wallo\FilamentCompanies\Contracts\DeletesCompanies; -use Wallo\FilamentCompanies\RedirectsActions; use Livewire\Component; +use Livewire\Redirector; class DeleteCompanyForm extends Component { - use RedirectsActions; - /** * The company instance. * @@ -32,7 +33,7 @@ class DeleteCompanyForm extends Component * @param mixed $company * @return void */ - public function mount($company) + public function mount(mixed $company): void { $this->company = $company; } @@ -40,25 +41,26 @@ public function mount($company) /** * Delete the company. * - * @param \Wallo\FilamentCompanies\Actions\ValidateCompanyDeletion $validator - * @param \Wallo\FilamentCompanies\Contracts\DeletesCompanies $deleter - * @return void + * @param ValidateCompanyDeletion $validator + * @param DeletesCompanies $deleter + * @return RedirectResponse|Redirector + * @throws AuthorizationException */ - public function deleteCompany(ValidateCompanyDeletion $validator, DeletesCompanies $deleter) + public function deleteCompany(ValidateCompanyDeletion $validator, DeletesCompanies $deleter): RedirectResponse|Redirector { $validator->validate(Auth::user(), $this->company); $deleter->delete($this->company); - return $this->redirectPath($deleter); + return redirect()->to(config('fortify.home')); } /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::companies.delete-company-form'); } diff --git a/src/Http/Livewire/DeleteUserForm.php b/src/Http/Livewire/DeleteUserForm.php index b9a211b..a3f9b52 100644 --- a/src/Http/Livewire/DeleteUserForm.php +++ b/src/Http/Livewire/DeleteUserForm.php @@ -3,12 +3,15 @@ namespace Wallo\FilamentCompanies\Http\Livewire; use Illuminate\Contracts\Auth\StatefulGuard; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Contracts\DeletesUsers; use Livewire\Component; +use Livewire\Redirector; class DeleteUserForm extends Component { @@ -31,7 +34,7 @@ class DeleteUserForm extends Component * * @return void */ - public function confirmUserDeletion() + public function confirmUserDeletion(): void { $this->resetErrorBag(); @@ -45,12 +48,12 @@ public function confirmUserDeletion() /** * Delete the current user. * - * @param \Illuminate\Http\Request $request - * @param \Wallo\FilamentCompanies\Contracts\DeletesUsers $deleter - * @param \Illuminate\Contracts\Auth\StatefulGuard $auth - * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse + * @param Request $request + * @param DeletesUsers $deleter + * @param StatefulGuard $auth + * @return RedirectResponse|Redirector */ - public function deleteUser(Request $request, DeletesUsers $deleter, StatefulGuard $auth) + public function deleteUser(Request $request, DeletesUsers $deleter, StatefulGuard $auth): RedirectResponse|Redirector { $this->resetErrorBag(); @@ -69,15 +72,15 @@ public function deleteUser(Request $request, DeletesUsers $deleter, StatefulGuar $request->session()->regenerateToken(); } - return redirect(config('fortify.redirects.logout', '/')); + return redirect(config('fortify.redirects.logout') ?? '/'); } /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.delete-user-form'); } diff --git a/src/Http/Livewire/LogoutOtherBrowserSessionsForm.php b/src/Http/Livewire/LogoutOtherBrowserSessionsForm.php index 8d25c3d..1b63329 100644 --- a/src/Http/Livewire/LogoutOtherBrowserSessionsForm.php +++ b/src/Http/Livewire/LogoutOtherBrowserSessionsForm.php @@ -2,12 +2,15 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use Illuminate\Auth\AuthenticationException; use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Support\Carbon; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; +use Illuminate\Contracts\View\View; use Jenssegers\Agent\Agent; use Livewire\Component; @@ -32,7 +35,7 @@ class LogoutOtherBrowserSessionsForm extends Component * * @return void */ - public function confirmLogout() + public function confirmLogout(): void { $this->password = ''; @@ -44,10 +47,11 @@ public function confirmLogout() /** * Log out from other browser sessions. * - * @param \Illuminate\Contracts\Auth\StatefulGuard $guard + * @param StatefulGuard $guard * @return void + * @throws AuthenticationException */ - public function logoutOtherBrowserSessions(StatefulGuard $guard) + public function logoutOtherBrowserSessions(StatefulGuard $guard): void { if (config('session.driver') !== 'database') { return; @@ -79,7 +83,7 @@ public function logoutOtherBrowserSessions(StatefulGuard $guard) * * @return void */ - protected function deleteOtherSessionRecords() + protected function deleteOtherSessionRecords(): void { if (config('session.driver') !== 'database') { return; @@ -94,9 +98,9 @@ protected function deleteOtherSessionRecords() /** * Get the current sessions. * - * @return \Illuminate\Support\Collection + * @return Collection */ - public function getSessionsProperty() + public function getSessionsProperty(): Collection { if (config('session.driver') !== 'database') { return collect(); @@ -121,9 +125,9 @@ public function getSessionsProperty() * Create a new agent instance from the given session. * * @param mixed $session - * @return \Jenssegers\Agent\Agent + * @return Agent */ - protected function createAgent($session) + protected function createAgent(mixed $session): Agent { return tap(new Agent, function ($agent) use ($session) { $agent->setUserAgent($session->user_agent); @@ -133,9 +137,9 @@ protected function createAgent($session) /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.logout-other-browser-sessions-form'); } diff --git a/src/Http/Livewire/SetPasswordForm.php b/src/Http/Livewire/SetPasswordForm.php index c4825ca..53e9a71 100644 --- a/src/Http/Livewire/SetPasswordForm.php +++ b/src/Http/Livewire/SetPasswordForm.php @@ -2,7 +2,10 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Contracts\SetsUserPasswords; use Livewire\Component; @@ -21,10 +24,10 @@ class SetPasswordForm extends Component /** * Update the user's password. * - * @param \Wallo\FilamentCompanies\Contracts\SetsUserPasswords $setter + * @param SetsUserPasswords $setter * @return void */ - public function setPassword(SetsUserPasswords $setter) + public function setPassword(SetsUserPasswords $setter): void { $this->resetErrorBag(); @@ -41,9 +44,9 @@ public function setPassword(SetsUserPasswords $setter) /** * Get the current user of the application. * - * @return mixed + * @return Authenticatable|User|null */ - public function getUserProperty() + public function getUserProperty(): Authenticatable|null|User { return Auth::user(); } @@ -51,9 +54,9 @@ public function getUserProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.set-password-form'); } diff --git a/src/Http/Livewire/TwoFactorAuthenticationForm.php b/src/Http/Livewire/TwoFactorAuthenticationForm.php index 42f4ad5..3e854b4 100644 --- a/src/Http/Livewire/TwoFactorAuthenticationForm.php +++ b/src/Http/Livewire/TwoFactorAuthenticationForm.php @@ -2,7 +2,10 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication; use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; use Laravel\Fortify\Actions\EnableTwoFactorAuthentication; @@ -16,28 +19,28 @@ class TwoFactorAuthenticationForm extends Component use ConfirmsPasswords; /** - * Indicates if two factor authentication QR code is being displayed. + * Indicates if two-factor authentication QR code is being displayed. * * @var bool */ public $showingQrCode = false; /** - * Indicates if the two factor authentication confirmation input and button are being displayed. + * Indicates if the two-factor authentication confirmation input and button are being displayed. * * @var bool */ public $showingConfirmation = false; /** - * Indicates if two factor authentication recovery codes are being displayed. + * Indicates if two-factor authentication recovery codes are being displayed. * * @var bool */ public $showingRecoveryCodes = false; /** - * The OTP code for confirming two factor authentication. + * The OTP code for confirming two-factor authentication. * * @var string|null */ @@ -48,21 +51,21 @@ class TwoFactorAuthenticationForm extends Component * * @return void */ - public function mount() + public function mount(): void { - if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm') && - is_null(Auth::user()->two_factor_confirmed_at)) { + if (is_null(Auth::user()->two_factor_confirmed_at) && + Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm')) { app(DisableTwoFactorAuthentication::class)(Auth::user()); } } /** - * Enable two factor authentication for the user. + * Enable two-factor authentication for the user. * - * @param \Laravel\Fortify\Actions\EnableTwoFactorAuthentication $enable + * @param EnableTwoFactorAuthentication $enable * @return void */ - public function enableTwoFactorAuthentication(EnableTwoFactorAuthentication $enable) + public function enableTwoFactorAuthentication(EnableTwoFactorAuthentication $enable): void { if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')) { $this->ensurePasswordIsConfirmed(); @@ -80,12 +83,12 @@ public function enableTwoFactorAuthentication(EnableTwoFactorAuthentication $ena } /** - * Confirm two factor authentication for the user. + * Confirm two-factor authentication for the user. * - * @param \Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication $confirm + * @param ConfirmTwoFactorAuthentication $confirm * @return void */ - public function confirmTwoFactorAuthentication(ConfirmTwoFactorAuthentication $confirm) + public function confirmTwoFactorAuthentication(ConfirmTwoFactorAuthentication $confirm): void { if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')) { $this->ensurePasswordIsConfirmed(); @@ -103,7 +106,7 @@ public function confirmTwoFactorAuthentication(ConfirmTwoFactorAuthentication $c * * @return void */ - public function showRecoveryCodes() + public function showRecoveryCodes(): void { if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')) { $this->ensurePasswordIsConfirmed(); @@ -115,10 +118,10 @@ public function showRecoveryCodes() /** * Generate new recovery codes for the user. * - * @param \Laravel\Fortify\Actions\GenerateNewRecoveryCodes $generate + * @param GenerateNewRecoveryCodes $generate * @return void */ - public function regenerateRecoveryCodes(GenerateNewRecoveryCodes $generate) + public function regenerateRecoveryCodes(GenerateNewRecoveryCodes $generate): void { if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')) { $this->ensurePasswordIsConfirmed(); @@ -130,12 +133,12 @@ public function regenerateRecoveryCodes(GenerateNewRecoveryCodes $generate) } /** - * Disable two factor authentication for the user. + * Disable two-factor authentication for the user. * - * @param \Laravel\Fortify\Actions\DisableTwoFactorAuthentication $disable + * @param DisableTwoFactorAuthentication $disable * @return void */ - public function disableTwoFactorAuthentication(DisableTwoFactorAuthentication $disable) + public function disableTwoFactorAuthentication(DisableTwoFactorAuthentication $disable): void { if (Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')) { $this->ensurePasswordIsConfirmed(); @@ -151,19 +154,19 @@ public function disableTwoFactorAuthentication(DisableTwoFactorAuthentication $d /** * Get the current user of the application. * - * @return mixed + * @return User|Authenticatable|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } /** - * Determine if two factor authentication is enabled. + * Determine if two-factor authentication is enabled. * * @return bool */ - public function getEnabledProperty() + public function getEnabledProperty(): bool { return ! empty($this->user->two_factor_secret); } @@ -171,9 +174,9 @@ public function getEnabledProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.two-factor-authentication-form'); } diff --git a/src/Http/Livewire/UpdateCompanyNameForm.php b/src/Http/Livewire/UpdateCompanyNameForm.php index f243960..1c22c48 100644 --- a/src/Http/Livewire/UpdateCompanyNameForm.php +++ b/src/Http/Livewire/UpdateCompanyNameForm.php @@ -2,11 +2,17 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; use Filament\Notifications\Notification; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Wallo\FilamentCompanies\Contracts\UpdatesCompanyNames; use Livewire\Component; +/** + * @property mixed $user + */ class UpdateCompanyNameForm extends Component { /** @@ -29,7 +35,7 @@ class UpdateCompanyNameForm extends Component * @param mixed $company * @return void */ - public function mount($company) + public function mount(mixed $company): void { $this->company = $company; @@ -39,10 +45,10 @@ public function mount($company) /** * Update the company's name. * - * @param \Wallo\FilamentCompanies\Contracts\UpdatesCompanyNames $updater + * @param UpdatesCompanyNames $updater * @return void */ - public function updateCompanyName(UpdatesCompanyNames $updater) + public function updateCompanyName(UpdatesCompanyNames $updater): void { $this->resetErrorBag(); @@ -60,9 +66,9 @@ public function updateCompanyName(UpdatesCompanyNames $updater) /** * Get the current user of the application. * - * @return mixed + * @return User|Authenticatable|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } @@ -70,9 +76,9 @@ public function getUserProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::companies.update-company-name-form'); } diff --git a/src/Http/Livewire/UpdatePasswordForm.php b/src/Http/Livewire/UpdatePasswordForm.php index 5267b8a..fd8b98f 100644 --- a/src/Http/Livewire/UpdatePasswordForm.php +++ b/src/Http/Livewire/UpdatePasswordForm.php @@ -2,8 +2,11 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; use Filament\Notifications\Notification; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Laravel\Fortify\Contracts\UpdatesUserPasswords; use Livewire\Component; @@ -23,10 +26,10 @@ class UpdatePasswordForm extends Component /** * Update the user's password. * - * @param \Laravel\Fortify\Contracts\UpdatesUserPasswords $updater + * @param UpdatesUserPasswords $updater * @return void */ - public function updatePassword(UpdatesUserPasswords $updater) + public function updatePassword(UpdatesUserPasswords $updater): void { $this->resetErrorBag(); @@ -54,9 +57,9 @@ public function updatePassword(UpdatesUserPasswords $updater) /** * Get the current user of the application. * - * @return mixed + * @return User|Authenticatable|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } @@ -64,9 +67,9 @@ public function getUserProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.update-password-form'); } diff --git a/src/Http/Livewire/UpdateProfileInformationForm.php b/src/Http/Livewire/UpdateProfileInformationForm.php index 9b86f3d..52f2893 100644 --- a/src/Http/Livewire/UpdateProfileInformationForm.php +++ b/src/Http/Livewire/UpdateProfileInformationForm.php @@ -2,10 +2,15 @@ namespace Wallo\FilamentCompanies\Http\Livewire; +use App\Models\User; use Filament\Notifications\Notification; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; +use Illuminate\Contracts\View\View; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; use Livewire\Component; +use Livewire\Redirector; use Livewire\WithFileUploads; use Wallo\FilamentCompanies\Pages\User\Profile; @@ -39,7 +44,7 @@ class UpdateProfileInformationForm extends Component * * @return void */ - public function mount() + public function mount(): void { $this->state = Auth::user()->withoutRelations()->toArray(); } @@ -47,10 +52,10 @@ public function mount() /** * Update the user's profile information. * - * @param \Laravel\Fortify\Contracts\UpdatesUserProfileInformation $updater - * @return void + * @param UpdatesUserProfileInformation $updater + * @return Redirector|RedirectResponse */ - public function updateProfileInformation(UpdatesUserProfileInformation $updater) + public function updateProfileInformation(UpdatesUserProfileInformation $updater): Redirector|RedirectResponse { $this->resetErrorBag(); @@ -79,7 +84,7 @@ public function updateProfileInformation(UpdatesUserProfileInformation $updater) * * @return void */ - public function deleteProfilePhoto() + public function deleteProfilePhoto(): void { Auth::user()->deleteProfilePhoto(); @@ -91,7 +96,7 @@ public function deleteProfilePhoto() * * @return void */ - public function sendEmailVerification() + public function sendEmailVerification(): void { Auth::user()->sendEmailVerificationNotification(); @@ -101,9 +106,9 @@ public function sendEmailVerification() /** * Get the current user of the application. * - * @return mixed + * @return User|Authenticatable|null */ - public function getUserProperty() + public function getUserProperty(): User|Authenticatable|null { return Auth::user(); } @@ -111,9 +116,9 @@ public function getUserProperty() /** * Render the component. * - * @return \Illuminate\View\View + * @return View */ - public function render() + public function render(): View { return view('filament-companies::profile.update-profile-information-form'); } diff --git a/src/Http/Middleware/AuthenticateSession.php b/src/Http/Middleware/AuthenticateSession.php index f0009e6..1113157 100644 --- a/src/Http/Middleware/AuthenticateSession.php +++ b/src/Http/Middleware/AuthenticateSession.php @@ -2,6 +2,8 @@ namespace Wallo\FilamentCompanies\Http\Middleware; +use Illuminate\Contracts\Auth\Factory; +use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Session\Middleware\AuthenticateSession as BaseAuthenticateSession; @@ -10,9 +12,9 @@ class AuthenticateSession extends BaseAuthenticateSession /** * Get the guard instance that should be used by the middleware. * - * @return \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\Guard + * @return Factory|Guard */ - protected function guard() + protected function guard(): Guard|Factory { return app(StatefulGuard::class); } diff --git a/src/InteractsWithBanner.php b/src/InteractsWithBanner.php index c153832..84d0099 100644 --- a/src/InteractsWithBanner.php +++ b/src/InteractsWithBanner.php @@ -7,10 +7,10 @@ trait InteractsWithBanner /** * Update the banner message. * - * @param string $message + * @param string $message * @return void */ - protected function banner($message) + protected function banner(string $message): void { $this->dispatchBrowserEvent('banner-message', [ 'style' => 'success', @@ -19,12 +19,12 @@ protected function banner($message) } /** - * Update the banner message with an danger / error message. + * Update the banner message with a danger / error message. * - * @param string $message + * @param string $message * @return void */ - protected function dangerBanner($message) + protected function dangerBanner(string $message): void { $this->dispatchBrowserEvent('banner-message', [ 'style' => 'danger', diff --git a/src/Mail/CompanyInvitation.php b/src/Mail/CompanyInvitation.php index abe8f48..e8ec0dd 100644 --- a/src/Mail/CompanyInvitation.php +++ b/src/Mail/CompanyInvitation.php @@ -6,7 +6,7 @@ use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\URL; -use Wallo\FilamentCompanies\CompanyInvitation as CompanyInvitationModel; +use App\Models\CompanyInvitation as CompanyInvitationModel; class CompanyInvitation extends Mailable { @@ -15,14 +15,14 @@ class CompanyInvitation extends Mailable /** * The company invitation instance. * - * @var \Wallo\FilamentCompanies\CompanyInvitation + * @var CompanyInvitationModel */ - public $invitation; + public CompanyInvitationModel $invitation; /** * Create a new message instance. * - * @param \Wallo\FilamentCompanies\CompanyInvitation $invitation + * @param CompanyInvitationModel $invitation * @return void */ public function __construct(CompanyInvitationModel $invitation) @@ -35,7 +35,7 @@ public function __construct(CompanyInvitationModel $invitation) * * @return $this */ - public function build() + public function build(): static { return $this->markdown('filament-companies::mail.company-invitation', ['acceptUrl' => URL::signedRoute('company-invitations.accept', [ 'invitation' => $this->invitation, diff --git a/src/Pages/Companies/CompanySettings.php b/src/Pages/Companies/CompanySettings.php index 8368604..ed1419d 100644 --- a/src/Pages/Companies/CompanySettings.php +++ b/src/Pages/Companies/CompanySettings.php @@ -2,15 +2,15 @@ namespace Wallo\FilamentCompanies\Pages\Companies; -use App\Models\Company; use Filament\Pages\Page; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; +use App\Models\Company; use Wallo\FilamentCompanies\FilamentCompanies; class CompanySettings extends Page { - public $company; + public Company $company; protected static string $view = "filament-companies::filament.pages.companies.company_settings"; @@ -26,7 +26,6 @@ public function mount(Company $company): void abort_unless(FilamentCompanies::hasCompanyFeatures(), 403); abort_if(Gate::denies('view', $company), 403); $this->company = Auth::user()->currentCompany; - $this->company = $company; } public static function getSlug(): string diff --git a/src/Pages/Companies/CreateCompany.php b/src/Pages/Companies/CreateCompany.php index 35effe9..277ccb3 100644 --- a/src/Pages/Companies/CreateCompany.php +++ b/src/Pages/Companies/CreateCompany.php @@ -10,7 +10,7 @@ class CreateCompany extends Page { - public $company; + public Company $company; protected static string $view = "filament-companies::filament.pages.companies.create_company"; @@ -26,7 +26,6 @@ public function mount(Company $company): void abort_unless(FilamentCompanies::hasCompanyFeatures(), 403); Gate::authorize('create', FilamentCompanies::newCompanyModel()); $this->company = Auth::user()->currentCompany; - $this->company = $company; } public static function getSlug(): string diff --git a/src/Pages/User/APITokens.php b/src/Pages/User/APITokens.php index b588946..1646594 100644 --- a/src/Pages/User/APITokens.php +++ b/src/Pages/User/APITokens.php @@ -3,14 +3,17 @@ namespace Wallo\FilamentCompanies\Pages\User; use App\Models\User; +use Exception; +use Filament\Notifications\Notification; use Filament\Pages\Page; -use Filament\Forms; use Filament\Pages\Actions\Action; use Filament\Tables; use Filament\Tables\Actions\BulkAction; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; +use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\CheckboxList; use Laravel\Sanctum\Sanctum; use Wallo\FilamentCompanies\FilamentCompanies; @@ -18,17 +21,35 @@ class APITokens extends Page implements Tables\Contracts\HasTable { use Tables\Concerns\InteractsWithTable; - public $user; - public $plainTextToken; - public $name; - public $permissions = []; + public User $user; + + /** + * The plain text token value. + * + * @var string|null + */ + public ?string $plainTextToken; + + /** + * The token name. + * + * @var string + */ + public string $name = ''; + + /** + * The token permissions. + * + * @var array + */ + public array $permissions = []; /** * Indicates if the plain text token is being displayed to the user. * * @var bool */ - public $displayingToken = false; + public bool $displayingToken = false; protected static string $view = "filament-companies::filament.pages.user.api-tokens"; @@ -59,8 +80,8 @@ public function mount(): void protected function getTableQuery(): Builder { return app(Sanctum::$personalAccessTokenModel)->where([ - ["tokenable_id", '=', Auth::user()->id], - ["tokenable_type", '=', User::class], + ["tokenable_id", '=', $this->user->id], + ["tokenable_type", '=', FilamentCompanies::$userModel], ]); } @@ -91,15 +112,23 @@ protected function getTableColumns(): array ->label(trans('Created at')) ->dateTime() ->sortable(), + Tables\Columns\TextColumn::make('updated_at') + ->label(trans('Updated at')) + ->dateTime() + ->sortable(), ]; } + /** + * @throws Exception + */ protected function getActions(): array { return [ Action::make('create') ->label(trans('Create Token')) ->action(function (array $data) { + $name = $data['name']; $indexes = $data['abilities']; $abilities = FilamentCompanies::$permissions; $selected = collect($abilities)->filter(function ($item, $key) use ( @@ -107,15 +136,15 @@ protected function getActions(): array ) { return in_array($key, $indexes); })->toArray(); - $this->displayTokenValue($this->user->createToken($data['name'], array_values($selected))); - $this->notify("success", __('Token Created')); + $this->displayTokenValue($this->user->createToken($name, array_values($selected))); + $this->tokenCreatedNotification(name: $name); $this->reset(['name']); }) ->form([ - Forms\Components\TextInput::make('name') + TextInput::make('name') ->label(__('filament-companies::default.labels.token_name')) ->required(), - Forms\Components\CheckboxList::make('abilities') + CheckboxList::make('abilities') ->label(__('filament-companies::default.labels.permissions')) ->required() ->options(FilamentCompanies::$permissions) @@ -131,6 +160,17 @@ protected function displayTokenValue($token) $this->dispatchBrowserEvent('showing-token-modal'); } + protected function tokenCreatedNotification($name) + { + Notification::make() + ->title(trans("{$name} token created")) + ->success() + ->send(); + } + + /** + * @throws Exception + */ protected function getTableActions(): array { return [ @@ -142,6 +182,7 @@ protected function getTableActions(): array fn ($form, $record) => $form->fill($record->toArray()) ) ->action(function ($record, array $data) { + $name = $data['name']; $indexes = $data['abilities']; $abilities = FilamentCompanies::$permissions; $selected = collect($abilities)->filter(function ($item, $key) use ( @@ -150,12 +191,16 @@ protected function getTableActions(): array return in_array($key, $indexes); })->toArray(); $record->update([ + 'name' => $name, 'abilities' => array_values($selected), ]); - $this->notify("success", __('Token Permissions Updated')); + $this->tokenUpdatedNotification(); }) ->form([ - Forms\Components\CheckboxList::make('abilities') + TextInput::make('name') + ->label(__('filament-companies::default.labels.token_name')) + ->required(), + CheckboxList::make('abilities') ->label(__('filament-companies::default.labels.permissions')) ->required() ->options(FilamentCompanies::$permissions) @@ -174,6 +219,17 @@ protected function getTableActions(): array ]; } + protected function tokenUpdatedNotification() + { + Notification::make() + ->title(trans("Token Updated")) + ->success() + ->send(); + } + + /** + * @throws Exception + */ protected function getTableBulkActions(): array { return [ diff --git a/src/Providers.php b/src/Providers.php index 12dd07f..b3c12ea 100644 --- a/src/Providers.php +++ b/src/Providers.php @@ -8,14 +8,14 @@ class Providers { /** - * Determine if the given privider is enabled. + * Determine if the given provider is enabled. * * @param string $provider * @return bool */ - public static function enabled(string $provider) + public static function enabled(string $provider): bool { - return in_array($provider, config('filament-companies.providers', [])); + return in_array($provider, config('filament-companies.providers', []), true); } /** @@ -23,7 +23,7 @@ public static function enabled(string $provider) * * @return bool */ - public static function hasBitbucketSupport() + public static function hasBitbucketSupport(): bool { return static::enabled(static::bitbucket()); } @@ -33,7 +33,7 @@ public static function hasBitbucketSupport() * * @return bool */ - public static function hasFacebookSupport() + public static function hasFacebookSupport(): bool { return static::enabled(static::facebook()); } @@ -43,7 +43,7 @@ public static function hasFacebookSupport() * * @return bool */ - public static function hasGitlabSupport() + public static function hasGitlabSupport(): bool { return static::enabled(static::gitlab()); } @@ -53,7 +53,7 @@ public static function hasGitlabSupport() * * @return bool */ - public static function hasGithubSupport() + public static function hasGithubSupport(): bool { return static::enabled(static::github()); } @@ -63,7 +63,7 @@ public static function hasGithubSupport() * * @return bool */ - public static function hasGoogleSupport() + public static function hasGoogleSupport(): bool { return static::enabled(static::google()); } @@ -73,7 +73,7 @@ public static function hasGoogleSupport() * * @return bool */ - public static function hasLinkedInSupport() + public static function hasLinkedInSupport(): bool { return static::enabled(static::linkedin()); } @@ -83,7 +83,7 @@ public static function hasLinkedInSupport() * * @return bool */ - public static function hasTwitterSupport() + public static function hasTwitterSupport(): bool { return static::enabled(static::twitterOAuth1()) || static::enabled(static::twitterOAuth2()); @@ -94,7 +94,7 @@ public static function hasTwitterSupport() * * @return bool */ - public static function hasTwitterOAuth1Support() + public static function hasTwitterOAuth1Support(): bool { return static::enabled(static::twitterOAuth1()); } @@ -104,7 +104,7 @@ public static function hasTwitterOAuth1Support() * * @return bool */ - public static function hasTwitterOAuth2Support() + public static function hasTwitterOAuth2Support(): bool { return static::enabled(static::twitterOAuth2()); } @@ -114,7 +114,7 @@ public static function hasTwitterOAuth2Support() * * @return string */ - public static function bitbucket() + public static function bitbucket(): string { return 'bitbucket'; } @@ -124,7 +124,7 @@ public static function bitbucket() * * @return string */ - public static function facebook() + public static function facebook(): string { return 'facebook'; } @@ -134,7 +134,7 @@ public static function facebook() * * @return string */ - public static function github() + public static function github(): string { return 'github'; } @@ -144,7 +144,7 @@ public static function github() * * @return string */ - public static function gitlab() + public static function gitlab(): string { return 'gitlab'; } @@ -154,7 +154,7 @@ public static function gitlab() * * @return string */ - public static function google() + public static function google(): string { return 'google'; } @@ -164,7 +164,7 @@ public static function google() * * @return string */ - public static function linkedin() + public static function linkedin(): string { return 'linkedin'; } @@ -174,7 +174,7 @@ public static function linkedin() * * @return string */ - public static function twitter() + public static function twitter(): string { return 'twitter'; } @@ -184,7 +184,7 @@ public static function twitter() * * @return string */ - public static function twitterOAuth1() + public static function twitterOAuth1(): string { return 'twitter'; } @@ -194,7 +194,7 @@ public static function twitterOAuth1() * * @return string */ - public static function twitterOAuth2() + public static function twitterOAuth2(): string { return 'twitter-oauth-2'; } @@ -227,12 +227,12 @@ public static function __callStatic($name, $arguments) /** * Throw a bad method call exception for the given method. * - * @param string $method + * @param string $method * @return void * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ - protected static function throwBadMethodCallException($method) + protected static function throwBadMethodCallException(string $method): void { throw new BadMethodCallException(sprintf( 'Call to undefined method %s::%s()', static::class, $method diff --git a/src/RedirectsActions.php b/src/RedirectsActions.php index 9d70c95..bc53f9d 100644 --- a/src/RedirectsActions.php +++ b/src/RedirectsActions.php @@ -10,16 +10,15 @@ trait RedirectsActions * Get the redirect response for the given action. * * @param mixed $action - * @return \Illuminate\Http\Response + * @return Response */ - public function redirectPath($action) + public function redirectPath(mixed $action): Response { if (method_exists($action, 'redirectTo')) { $response = $action->redirectTo(); } else { - $response = property_exists($action, 'redirectTo') - ? $action->redirectTo - : config('fortify.home'); + $property = property_exists($action, 'redirectTo'); + $response = $property ? $action->redirectTo : config('fortify.home'); } return $response instanceof Response ? $response : redirect($response); diff --git a/src/Role.php b/src/Role.php index adcb0f3..0925780 100644 --- a/src/Role.php +++ b/src/Role.php @@ -11,28 +11,28 @@ class Role implements JsonSerializable * * @var string */ - public $key; + public string $key; /** * The name of the role. * * @var string */ - public $name; + public string $name; /** * The role's permissions. * * @var array */ - public $permissions; + public array $permissions; /** * The role's description. * * @var string */ - public $description; + public string $description; /** * Create a new role instance. @@ -55,7 +55,7 @@ public function __construct(string $key, string $name, array $permissions) * @param string $description * @return $this */ - public function description(string $description) + public function description(string $description): static { $this->description = $description; @@ -68,7 +68,7 @@ public function description(string $description) * @return array */ #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { return [ 'key' => $this->key, diff --git a/src/Rules/Role.php b/src/Rules/Role.php index 1023e9c..8c4d9ff 100644 --- a/src/Rules/Role.php +++ b/src/Rules/Role.php @@ -14,9 +14,9 @@ class Role implements Rule * @param mixed $value * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { - return in_array($value, array_keys(FilamentCompanies::$roles)); + return array_key_exists($value, FilamentCompanies::$roles); } /** @@ -24,7 +24,7 @@ public function passes($attribute, $value) * * @return string */ - public function message() + public function message(): string { return __('The :attribute must be a valid role.'); } diff --git a/src/SetsProfilePhotoFromUrl.php b/src/SetsProfilePhotoFromUrl.php index 98506b6..3b0eaa1 100644 --- a/src/SetsProfilePhotoFromUrl.php +++ b/src/SetsProfilePhotoFromUrl.php @@ -14,7 +14,7 @@ trait SetsProfilePhotoFromUrl * @param string $url * @return void */ - public function setProfilePhotoFromUrl(string $url) + public function setProfilePhotoFromUrl(string $url): void { $name = pathinfo($url)['basename']; $response = Http::get($url); @@ -25,7 +25,7 @@ public function setProfilePhotoFromUrl(string $url) $this->updateProfilePhoto(new UploadedFile($file, $name)); } else { - session()->flash('flash.banner', 'Unable to retrive image'); + session()->flash('flash.banner', 'Unable to retrieve image'); session()->flash('flash.bannerStyle', 'danger'); } } diff --git a/src/Socialite.php b/src/Socialite.php index 1afc4b7..52bacc0 100644 --- a/src/Socialite.php +++ b/src/Socialite.php @@ -17,29 +17,29 @@ class Socialite * * @var bool */ - public static $enabled = true; + public static bool $enabled = true; /** * Indicates if Socialite routes will be registered. * * @var bool */ - public static $registersRoutes = true; + public static bool $registersRoutes = true; /** * The user model that should be used by FilamentCompanies. * * @var string */ - public static $connectedAccountModel = 'App\\Models\\ConnectedAccount'; + public static string $connectedAccountModel = 'App\\Models\\ConnectedAccount'; /** - * Determine whether or not Socialite is enabled in the application. + * Determine whether Socialite is enabled in the application. * - * @param callable|bool $callback + * @param callable|bool|null $callback * @return bool */ - public static function enabled($callback = null) + public static function enabled(callable|bool $callback = null): bool { if (is_callable($callback)) { static::$enabled = $callback(); @@ -53,11 +53,11 @@ public static function enabled($callback = null) } /** - * Determine whether or not to show Socialite components on login or registration. + * Determine whether to show Socialite components on login or registration. * * @return bool */ - public static function show() + public static function show(): bool { return static::$enabled; } @@ -67,7 +67,7 @@ public static function show() * * @return array */ - public static function providers() + public static function providers(): array { return config('filament-companies.providers'); } @@ -75,9 +75,10 @@ public static function providers() /** * Determine if FilamentCompanies supports a specific Socialite provider. * + * @param string $provider * @return bool */ - public static function hasSupportFor(string $provider) + public static function hasSupportFor(string $provider): bool { return Providers::enabled($provider); } @@ -87,7 +88,7 @@ public static function hasSupportFor(string $provider) * * @return bool */ - public static function hasBitbucketSupport() + public static function hasBitbucketSupport(): bool { return Providers::hasBitbucketSupport(); } @@ -97,7 +98,7 @@ public static function hasBitbucketSupport() * * @return bool */ - public static function hasFacebookSupport() + public static function hasFacebookSupport(): bool { return Providers::hasFacebookSupport(); } @@ -107,17 +108,17 @@ public static function hasFacebookSupport() * * @return bool */ - public static function hasGitlabSupport() + public static function hasGitlabSupport(): bool { return Providers::hasGitlabSupport(); } /** - * Determine if the application has support for the Github provider.. + * Determine if the application has support for the GitHub provider.. * * @return bool */ - public static function hasGithubSupport() + public static function hasGithubSupport(): bool { return Providers::hasGithubSupport(); } @@ -127,7 +128,7 @@ public static function hasGithubSupport() * * @return bool */ - public static function hasGoogleSupport() + public static function hasGoogleSupport(): bool { return Providers::hasGoogleSupport(); } @@ -137,7 +138,7 @@ public static function hasGoogleSupport() * * @return bool */ - public static function hasLinkedInSupport() + public static function hasLinkedInSupport(): bool { return Providers::hasLinkedInSupport(); } @@ -147,7 +148,7 @@ public static function hasLinkedInSupport() * * @return bool */ - public static function hasTwitterSupport() + public static function hasTwitterSupport(): bool { return Providers::hasTwitterSupport(); } @@ -157,7 +158,7 @@ public static function hasTwitterSupport() * * @return bool */ - public static function hasTwitterOAuth1Support() + public static function hasTwitterOAuth1Support(): bool { return Providers::hasTwitterOAuth1Support(); } @@ -167,7 +168,7 @@ public static function hasTwitterOAuth1Support() * * @return bool */ - public static function hasTwitterOAuth2Support() + public static function hasTwitterOAuth2Support(): bool { return Providers::hasTwitterOAuth2Support(); } @@ -177,7 +178,7 @@ public static function hasTwitterOAuth2Support() * * @return bool */ - public static function generatesMissingEmails() + public static function generatesMissingEmails(): bool { return Features::generatesMissingEmails(); } @@ -187,7 +188,7 @@ public static function generatesMissingEmails() * * @return bool */ - public static function hasCreateAccountOnFirstLoginFeatures() + public static function hasCreateAccountOnFirstLoginFeatures(): bool { return Features::hasCreateAccountOnFirstLoginFeatures(); } @@ -197,29 +198,29 @@ public static function hasCreateAccountOnFirstLoginFeatures() * * @return bool */ - public static function hasProviderAvatarsFeature() + public static function hasProviderAvatarsFeature(): bool { return Features::hasProviderAvatarsFeature(); } /** - * Determine if the application should remember the users session om login. + * Determine if the application should remember the users session on login. * * @return bool */ - public static function hasRememberSessionFeatures() + public static function hasRememberSessionFeatures(): bool { return Features::hasRememberSessionFeatures(); } /** - * Find a connected account instance fot a given provider and provider ID. + * Find a connected account instance for a given provider and provider ID. * * @param string $provider * @param string $providerId * @return mixed */ - public static function findConnectedAccountForProviderAndId(string $provider, string $providerId) + public static function findConnectedAccountForProviderAndId(string $provider, string $providerId): mixed { return static::newConnectedAccountModel() ->where('provider', $provider) @@ -232,7 +233,7 @@ public static function findConnectedAccountForProviderAndId(string $provider, st * * @return string */ - public static function connectedAccountModel() + public static function connectedAccountModel(): string { return static::$connectedAccountModel; } @@ -242,7 +243,7 @@ public static function connectedAccountModel() * * @return mixed */ - public static function newConnectedAccountModel() + public static function newConnectedAccountModel(): mixed { $model = static::connectedAccountModel(); @@ -255,7 +256,7 @@ public static function newConnectedAccountModel() * @param string $model * @return static */ - public static function useConnectedAccountModel(string $model) + public static function useConnectedAccountModel(string $model): static { static::$connectedAccountModel = $model; @@ -265,12 +266,12 @@ public static function useConnectedAccountModel(string $model) /** * Register a class / callback that should be used to resolve the user for a Socialite Provider. * - * @param string $class + * @param string $class * @return void */ - public static function resolvesSocialiteUsersUsing($class) + public static function resolvesSocialiteUsersUsing(string $class): void { - return app()->singleton(ResolvesSocialiteUsers::class, $class); + app()->singleton(ResolvesSocialiteUsers::class, $class); } /** @@ -279,9 +280,9 @@ public static function resolvesSocialiteUsersUsing($class) * @param string $class * @return void */ - public static function createUsersFromProviderUsing(string $class) + public static function createUsersFromProviderUsing(string $class): void { - return app()->singleton(CreatesUserFromProvider::class, $class); + app()->singleton(CreatesUserFromProvider::class, $class); } /** @@ -290,9 +291,9 @@ public static function createUsersFromProviderUsing(string $class) * @param string $class * @return void */ - public static function createConnectedAccountsUsing(string $class) + public static function createConnectedAccountsUsing(string $class): void { - return app()->singleton(CreatesConnectedAccounts::class, $class); + app()->singleton(CreatesConnectedAccounts::class, $class); } /** @@ -301,9 +302,9 @@ public static function createConnectedAccountsUsing(string $class) * @param string $class * @return void */ - public static function updateConnectedAccountsUsing(string $class) + public static function updateConnectedAccountsUsing(string $class): void { - return app()->singleton(UpdatesConnectedAccounts::class, $class); + app()->singleton(UpdatesConnectedAccounts::class, $class); } /** @@ -312,9 +313,9 @@ public static function updateConnectedAccountsUsing(string $class) * @param string $callback * @return void */ - public static function setUserPasswordsUsing(string $callback) + public static function setUserPasswordsUsing(string $callback): void { - return app()->singleton(SetsUserPasswords::class, $callback); + app()->singleton(SetsUserPasswords::class, $callback); } /** @@ -323,9 +324,9 @@ public static function setUserPasswordsUsing(string $callback) * @param string $callback * @return void */ - public static function handlesInvalidStateUsing(string $callback) + public static function handlesInvalidStateUsing(string $callback): void { - return app()->singleton(HandlesInvalidState::class, $callback); + app()->singleton(HandlesInvalidState::class, $callback); } /** @@ -334,8 +335,8 @@ public static function handlesInvalidStateUsing(string $callback) * @param string $callback * @return void */ - public static function generatesProvidersRedirectsUsing(string $callback) + public static function generatesProvidersRedirectsUsing(string $callback): void { - return app()->singleton(GeneratesProviderRedirect::class, $callback); + app()->singleton(GeneratesProviderRedirect::class, $callback); } } diff --git a/stubs/app/Actions/FilamentCompanies/AddCompanyEmployee.php b/stubs/app/Actions/FilamentCompanies/AddCompanyEmployee.php index 1944176..9b9e446 100644 --- a/stubs/app/Actions/FilamentCompanies/AddCompanyEmployee.php +++ b/stubs/app/Actions/FilamentCompanies/AddCompanyEmployee.php @@ -5,6 +5,8 @@ use App\Models\Company; use App\Models\User; use Closure; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Contracts\Validation\Rule; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Wallo\FilamentCompanies\Contracts\AddsCompanyEmployees; @@ -18,6 +20,7 @@ class AddCompanyEmployee implements AddsCompanyEmployees /** * Add a new company employee to the given company. * + * @throws AuthorizationException */ public function add(User $user, Company $company, string $email, string $role = null): void { @@ -55,7 +58,7 @@ protected function validate(Company $company, string $email, ?string $role): voi /** * Get the validation rules for adding a company employee. * - * @return array + * @return array */ protected function rules(): array { @@ -73,7 +76,7 @@ protected function rules(): array */ protected function ensureUserIsNotAlreadyOnCompany(Company $company, string $email): Closure { - return function ($validator) use ($company, $email) { + return static function ($validator) use ($company, $email) { $validator->errors()->addIf( $company->hasUserWithEmail($email), 'email', diff --git a/stubs/app/Actions/FilamentCompanies/CreateCompany.php b/stubs/app/Actions/FilamentCompanies/CreateCompany.php index 966fa77..6c5f5e8 100644 --- a/stubs/app/Actions/FilamentCompanies/CreateCompany.php +++ b/stubs/app/Actions/FilamentCompanies/CreateCompany.php @@ -4,6 +4,7 @@ use App\Models\Company; use App\Models\User; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Wallo\FilamentCompanies\Contracts\CreatesCompanies; @@ -16,6 +17,7 @@ class CreateCompany implements CreatesCompanies * Validate and create a new company for the given user. * * @param array $input + * @throws AuthorizationException */ public function create(User $user, array $input): Company { diff --git a/stubs/app/Actions/FilamentCompanies/CreateConnectedAccount.php b/stubs/app/Actions/FilamentCompanies/CreateConnectedAccount.php index 2de96f9..e990a45 100644 --- a/stubs/app/Actions/FilamentCompanies/CreateConnectedAccount.php +++ b/stubs/app/Actions/FilamentCompanies/CreateConnectedAccount.php @@ -2,6 +2,7 @@ namespace App\Actions\FilamentCompanies; +use Wallo\FilamentCompanies\ConnectedAccount; use Wallo\FilamentCompanies\Contracts\CreatesConnectedAccounts; use Wallo\FilamentCompanies\Socialite; use Laravel\Socialite\Contracts\User as ProviderUser; @@ -13,10 +14,10 @@ class CreateConnectedAccount implements CreatesConnectedAccounts * * @param mixed $user * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \Wallo\FilamentCompanies\ConnectedAccount + * @param ProviderUser $providerUser + * @return ConnectedAccount */ - public function create($user, string $provider, ProviderUser $providerUser) + public function create($user, string $provider, ProviderUser $providerUser): ConnectedAccount { return Socialite::connectedAccountModel()::forceCreate([ 'user_id' => $user->id, diff --git a/stubs/app/Actions/FilamentCompanies/CreateUserFromProvider.php b/stubs/app/Actions/FilamentCompanies/CreateUserFromProvider.php index 612989e..596b879 100644 --- a/stubs/app/Actions/FilamentCompanies/CreateUserFromProvider.php +++ b/stubs/app/Actions/FilamentCompanies/CreateUserFromProvider.php @@ -17,14 +17,14 @@ class CreateUserFromProvider implements CreatesUserFromProvider /** * The creates connected accounts instance. * - * @var \Wallo\FilamentCompanies\Contracts\CreatesConnectedAccounts + * @var CreatesConnectedAccounts */ - public $createsConnectedAccounts; + public CreatesConnectedAccounts $createsConnectedAccounts; /** * Create a new action instance. * - * @param \Wallo\FilamentCompanies\Contracts\CreatesConnectedAccounts $createsConnectedAccounts + * @param CreatesConnectedAccounts $createsConnectedAccounts */ public function __construct(CreatesConnectedAccounts $createsConnectedAccounts) { @@ -35,10 +35,10 @@ public function __construct(CreatesConnectedAccounts $createsConnectedAccounts) * Create a new user from a social provider user. * * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \App\Models\User + * @param ProviderUserContract $providerUser + * @return User */ - public function create(string $provider, ProviderUserContract $providerUser) + public function create(string $provider, ProviderUserContract $providerUser): User { return DB::transaction(function () use ($provider, $providerUser) { return tap(User::create([ @@ -47,10 +47,8 @@ public function create(string $provider, ProviderUserContract $providerUser) ]), function (User $user) use ($provider, $providerUser) { $user->markEmailAsVerified(); - if (Features::profilePhotos()) { - if (Socialite::hasProviderAvatarsFeature() && FilamentCompanies::managesProfilePhotos() && $providerUser->getAvatar()) { - $user->setProfilePhotoFromUrl($providerUser->getAvatar()); - } + if (Features::profilePhotos() && Socialite::hasProviderAvatarsFeature() && FilamentCompanies::managesProfilePhotos() && $providerUser->getAvatar()) { + $user->setProfilePhotoFromUrl($providerUser->getAvatar()); } $user->switchConnectedAccount( @@ -65,10 +63,10 @@ public function create(string $provider, ProviderUserContract $providerUser) /** * Create a personal company for the user. * - * @param \App\Models\User $user + * @param User $user * @return void */ - protected function createCompany(User $user) + protected function createCompany(User $user): void { $user->ownedCompanies()->save(Company::forceCreate([ 'user_id' => $user->id, diff --git a/stubs/app/Actions/FilamentCompanies/DeleteUser.php b/stubs/app/Actions/FilamentCompanies/DeleteUser.php index 0e6ef2d..9cce613 100644 --- a/stubs/app/Actions/FilamentCompanies/DeleteUser.php +++ b/stubs/app/Actions/FilamentCompanies/DeleteUser.php @@ -13,9 +13,9 @@ class DeleteUser implements DeletesUsers /** * The company deleter implementation. * - * @var \Wallo\FilamentCompanies\Contracts\DeletesCompanies + * @var DeletesCompanies */ - protected $deletesCompanies; + protected DeletesCompanies $deletesCompanies; /** * Create a new action instance. diff --git a/stubs/app/Actions/FilamentCompanies/HandleInvalidState.php b/stubs/app/Actions/FilamentCompanies/HandleInvalidState.php index 7c96356..645f777 100644 --- a/stubs/app/Actions/FilamentCompanies/HandleInvalidState.php +++ b/stubs/app/Actions/FilamentCompanies/HandleInvalidState.php @@ -10,11 +10,11 @@ class HandleInvalidState implements HandlesInvalidState /** * Handle an invalid state exception from a Socialite provider. * - * @param \Laravel\Socialite\Two\InvalidStateException $exception - * @param callable $callback + * @param InvalidStateException $exception + * @param callable|null $callback * @return mixed */ - public function handle(InvalidStateException $exception, callable $callback = null) + public function handle(InvalidStateException $exception, callable $callback = null): mixed { if ($callback) { return $callback($exception); diff --git a/stubs/app/Actions/FilamentCompanies/InviteCompanyEmployee.php b/stubs/app/Actions/FilamentCompanies/InviteCompanyEmployee.php index 5a3b055..77bdebb 100644 --- a/stubs/app/Actions/FilamentCompanies/InviteCompanyEmployee.php +++ b/stubs/app/Actions/FilamentCompanies/InviteCompanyEmployee.php @@ -5,6 +5,7 @@ use App\Models\Company; use App\Models\User; use Closure; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Mail; @@ -20,6 +21,7 @@ class InviteCompanyEmployee implements InvitesCompanyEmployees { /** * Invite a new company employee to the given company. + * @throws AuthorizationException */ public function invite(User $user, Company $company, string $email, string $role = null): void { @@ -77,7 +79,7 @@ protected function rules(Company $company): array */ protected function ensureUserIsNotAlreadyOnCompany(Company $company, string $email): Closure { - return function ($validator) use ($company, $email) { + return static function ($validator) use ($company, $email) { $validator->errors()->addIf( $company->hasUserWithEmail($email), 'email', diff --git a/stubs/app/Actions/FilamentCompanies/RemoveCompanyEmployee.php b/stubs/app/Actions/FilamentCompanies/RemoveCompanyEmployee.php index 9861326..768627f 100644 --- a/stubs/app/Actions/FilamentCompanies/RemoveCompanyEmployee.php +++ b/stubs/app/Actions/FilamentCompanies/RemoveCompanyEmployee.php @@ -15,6 +15,7 @@ class RemoveCompanyEmployee implements RemovesCompanyEmployees /** * Remove the company employee from the given company. * + * @throws AuthorizationException */ public function remove(User $user, Company $company, User $companyEmployee): void { @@ -30,11 +31,15 @@ public function remove(User $user, Company $company, User $companyEmployee): voi /** * Authorize that the user can remove the company employee. * + * @throws AuthorizationException */ protected function authorize(User $user, Company $company, User $companyEmployee): void { - if (! Gate::forUser($user)->check('removeCompanyEmployee', $company) && - $user->id !== $companyEmployee->id) { + if (!Gate::forUser($user)->check('removeCompanyEmployee', $company)) { + throw new AuthorizationException; + } + + if ($user->id !== $companyEmployee->id) { throw new AuthorizationException; } } diff --git a/stubs/app/Actions/FilamentCompanies/ResolveSocialiteUser.php b/stubs/app/Actions/FilamentCompanies/ResolveSocialiteUser.php index 196db96..18ed9a4 100644 --- a/stubs/app/Actions/FilamentCompanies/ResolveSocialiteUser.php +++ b/stubs/app/Actions/FilamentCompanies/ResolveSocialiteUser.php @@ -2,6 +2,7 @@ namespace App\Actions\FilamentCompanies; +use Laravel\Socialite\Contracts\User; use Wallo\FilamentCompanies\Contracts\ResolvesSocialiteUsers; use Wallo\FilamentCompanies\Socialite as SocialiteUser; use Laravel\Socialite\Facades\Socialite; @@ -11,10 +12,10 @@ class ResolveSocialiteUser implements ResolvesSocialiteUsers /** * Resolve the user for a given provider. * - * @param string $provider - * @return \Laravel\Socialite\Contracts\User + * @param string $provider + * @return User */ - public function resolve($provider) + public function resolve(string $provider): User { $user = Socialite::driver($provider)->user(); diff --git a/stubs/app/Actions/FilamentCompanies/SetUserPassword.php b/stubs/app/Actions/FilamentCompanies/SetUserPassword.php index 9d62633..2d1958f 100644 --- a/stubs/app/Actions/FilamentCompanies/SetUserPassword.php +++ b/stubs/app/Actions/FilamentCompanies/SetUserPassword.php @@ -2,6 +2,7 @@ namespace App\Actions\FilamentCompanies; +use App\Models\User; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Wallo\FilamentCompanies\Contracts\SetsUserPasswords; @@ -12,11 +13,9 @@ class SetUserPassword implements SetsUserPasswords /** * Validate and update the user's password. * - * @param mixed $user - * @param array $input - * @return void + * @param array $input */ - public function set($user, array $input) + public function set(User $user, array $input): void { Validator::make($input, [ 'password' => ['required', 'string', new Password, 'confirmed'], diff --git a/stubs/app/Actions/FilamentCompanies/UpdateCompanyName.php b/stubs/app/Actions/FilamentCompanies/UpdateCompanyName.php index 7ff2e06..1aa0883 100644 --- a/stubs/app/Actions/FilamentCompanies/UpdateCompanyName.php +++ b/stubs/app/Actions/FilamentCompanies/UpdateCompanyName.php @@ -4,6 +4,7 @@ use App\Models\Company; use App\Models\User; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Wallo\FilamentCompanies\Contracts\UpdatesCompanyNames; @@ -14,6 +15,7 @@ class UpdateCompanyName implements UpdatesCompanyNames * Validate and update the given company's name. * * @param array $input + * @throws AuthorizationException */ public function update(User $user, Company $company, array $input): void { diff --git a/stubs/app/Actions/FilamentCompanies/UpdateConnectedAccount.php b/stubs/app/Actions/FilamentCompanies/UpdateConnectedAccount.php index 7ea4ff8..246e24c 100644 --- a/stubs/app/Actions/FilamentCompanies/UpdateConnectedAccount.php +++ b/stubs/app/Actions/FilamentCompanies/UpdateConnectedAccount.php @@ -2,6 +2,7 @@ namespace App\Actions\FilamentCompanies; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Facades\Gate; use Wallo\FilamentCompanies\ConnectedAccount; use Wallo\FilamentCompanies\Contracts\UpdatesConnectedAccounts; @@ -12,13 +13,14 @@ class UpdateConnectedAccount implements UpdatesConnectedAccounts /** * Update a given connected account. * - * @param mixed $user - * @param \Wallo\FilamentCompanies\ConnectedAccount $connectedAccount - * @param string $provider - * @param \Laravel\Socialite\Contracts\User $providerUser - * @return \Wallo\FilamentCompanies\ConnectedAccount + * @param mixed $user + * @param ConnectedAccount $connectedAccount + * @param string $provider + * @param User $providerUser + * @return ConnectedAccount + * @throws AuthorizationException */ - public function update($user, ConnectedAccount $connectedAccount, string $provider, User $providerUser) + public function update(mixed $user, ConnectedAccount $connectedAccount, string $provider, User $providerUser): ConnectedAccount { Gate::forUser($user)->authorize('update', $connectedAccount); diff --git a/stubs/app/Models/Company.php b/stubs/app/Models/Company.php index 60d8f0c..97c4c70 100644 --- a/stubs/app/Models/Company.php +++ b/stubs/app/Models/Company.php @@ -24,7 +24,7 @@ class Company extends FilamentCompaniesCompany /** * The attributes that are mass assignable. * - * @var string + * @var array */ protected $fillable = [ 'name', diff --git a/stubs/app/Models/CompanyInvitation.php b/stubs/app/Models/CompanyInvitation.php index f88529b..87a9010 100644 --- a/stubs/app/Models/CompanyInvitation.php +++ b/stubs/app/Models/CompanyInvitation.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Wallo\FilamentCompanies\FilamentCompanies; -use Wallo\FilamentCompanies\CompanyInvitation as FilamentCompaniesCompanyInvitation; -class CompanyInvitation extends FilamentCompaniesCompanyInvitation +class CompanyInvitation extends Model { /** * The attributes that are mass assignable. * - * @var string + * @var array */ protected $fillable = [ 'email', @@ -21,6 +21,7 @@ class CompanyInvitation extends FilamentCompaniesCompanyInvitation /** * Get the company that the invitation belongs to. * + * @return BelongsTo */ public function company(): BelongsTo { diff --git a/stubs/app/Models/ConnectedAccount.php b/stubs/app/Models/ConnectedAccount.php index 5c82470..f4e8d0d 100644 --- a/stubs/app/Models/ConnectedAccount.php +++ b/stubs/app/Models/ConnectedAccount.php @@ -3,7 +3,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Wallo\FilamentCompanies\ConnectedAccount as SocialiteConnectedAccount; use Wallo\FilamentCompanies\Events\ConnectedAccountCreated; use Wallo\FilamentCompanies\Events\ConnectedAccountDeleted; @@ -11,13 +10,12 @@ class ConnectedAccount extends SocialiteConnectedAccount { - use HasFactory; use HasTimestamps; /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'provider', @@ -34,7 +32,7 @@ class ConnectedAccount extends SocialiteConnectedAccount /** * The event map for the model. * - * @var array + * @var array */ protected $dispatchesEvents = [ 'created' => ConnectedAccountCreated::class, diff --git a/stubs/app/Models/User.php b/stubs/app/Models/User.php index c5070be..518e40f 100644 --- a/stubs/app/Models/User.php +++ b/stubs/app/Models/User.php @@ -12,7 +12,6 @@ use Wallo\FilamentCompanies\HasProfilePhoto; use Wallo\FilamentCompanies\HasCompanies; use Laravel\Sanctum\HasApiTokens; -use Wallo\FilamentCompanies\FilamentCompanies; use Wallo\FilamentCompanies\HasConnectedAccounts; use Wallo\FilamentCompanies\SetsProfilePhotoFromUrl; @@ -20,9 +19,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar { use HasApiTokens; use HasFactory; - use HasProfilePhoto { - getProfilePhotoUrlAttribute as getPhotoUrl; - } + use HasProfilePhoto; use HasCompanies; use HasConnectedAccounts; use Notifiable; @@ -36,15 +33,13 @@ public function canAccessFilament(): bool public function getFilamentAvatarUrl(): ?string { - if (FilamentCompanies::managesProfilePhotos()) { - return $this->profile_photo_url; - } + return $this->profile_photo_url; } /** * The attributes that are mass assignable. * - * @var string + * @var array */ protected $fillable = [ 'name', 'email', 'password', @@ -79,18 +74,4 @@ public function getFilamentAvatarUrl(): ?string protected $appends = [ 'profile_photo_url', ]; - - /** - * Get the URL to the user's profile photo. - * - * @return string - */ - public function getProfilePhotoUrlAttribute() - { - if (filter_var($this->profile_photo_path, FILTER_VALIDATE_URL)) { - return $this->profile_photo_path; - } - - return $this->getPhotoUrl(); - } } diff --git a/stubs/app/Policies/ConnectedAccountPolicy.php b/stubs/app/Policies/ConnectedAccountPolicy.php index 85776fb..3d50f2f 100644 --- a/stubs/app/Policies/ConnectedAccountPolicy.php +++ b/stubs/app/Policies/ConnectedAccountPolicy.php @@ -13,10 +13,10 @@ class ConnectedAccountPolicy /** * Determine whether the user can view any models. * - * @param \App\Models\User $user - * @return mixed + * @param User $user + * @return true */ - public function viewAny(User $user) + public function viewAny(User $user): bool { return true; } @@ -24,11 +24,11 @@ public function viewAny(User $user) /** * Determine whether the user can view the model. * - * @param \App\Models\User $user - * @param \App\Models\ConnectedAccount $connectedAccount - * @return mixed + * @param User $user + * @param ConnectedAccount $connectedAccount + * @return bool */ - public function view(User $user, ConnectedAccount $connectedAccount) + public function view(User $user, ConnectedAccount $connectedAccount): bool { return $user->ownsConnectedAccount($connectedAccount); } @@ -36,10 +36,10 @@ public function view(User $user, ConnectedAccount $connectedAccount) /** * Determine whether the user can create models. * - * @param \App\Models\User $user - * @return mixed + * @param User $user + * @return true */ - public function create(User $user) + public function create(User $user): bool { return true; } @@ -47,11 +47,11 @@ public function create(User $user) /** * Determine whether the user can update the model. * - * @param \App\Models\User $user - * @param \App\Models\ConnectedAccount $connectedAccount - * @return mixed + * @param User $user + * @param ConnectedAccount $connectedAccount + * @return bool */ - public function update(User $user, ConnectedAccount $connectedAccount) + public function update(User $user, ConnectedAccount $connectedAccount): bool { return $user->ownsConnectedAccount($connectedAccount); } @@ -59,11 +59,11 @@ public function update(User $user, ConnectedAccount $connectedAccount) /** * Determine whether the user can delete the model. * - * @param \App\Models\User $user - * @param \App\Models\ConnectedAccount $connectedAccount - * @return mixed + * @param User $user + * @param ConnectedAccount $connectedAccount + * @return bool */ - public function delete(User $user, ConnectedAccount $connectedAccount) + public function delete(User $user, ConnectedAccount $connectedAccount): bool { return $user->ownsConnectedAccount($connectedAccount); } diff --git a/stubs/app/Providers/FilamentCompaniesServiceProvider.php b/stubs/app/Providers/FilamentCompaniesServiceProvider.php index a7fb9c7..3a5429c 100644 --- a/stubs/app/Providers/FilamentCompaniesServiceProvider.php +++ b/stubs/app/Providers/FilamentCompaniesServiceProvider.php @@ -48,11 +48,11 @@ public function boot(): void if (FilamentCompanies::hasCompanyFeatures()) { Filament::registerRenderHook( 'global-search.start', - fn (): View => view('filament-companies::components.dropdown.navigation-menu'), + static fn (): View => view('filament-companies::components.dropdown.navigation-menu'), ); } - Filament::serving(function () { + Filament::serving(static function () { Filament::registerUserMenuItems([ 'account' => UserMenuItem::make()->url(Profile::getUrl()), // ... @@ -60,7 +60,7 @@ public function boot(): void }); if (FilamentCompanies::hasApiFeatures()) { - Filament::serving(function () { + Filament::serving(static function () { Filament::registerUserMenuItems([ UserMenuItem::make() ->label('API Tokens') @@ -70,13 +70,13 @@ public function boot(): void }); } - Filament::serving(function() { + Filament::serving(static function() { Filament::registerUserMenuItems([ 'logout' => UserMenuItem::make()->url(route('logout')), ]); }); - // Missing in FilamentCompaniesServiceProvider.php + RedirectResponse::macro('banner', function ($message) { return $this->with('flash', [ 'bannerStyle' => 'success', @@ -93,7 +93,7 @@ public function boot(): void Filament::registerRenderHook( 'content.start', - fn (): string => Blade::render(''), + static fn (): string => Blade::render(''), ); $this->configurePermissions(); diff --git a/stubs/config/filament-companies.php b/stubs/config/filament-companies.php index 6f77036..ad585cc 100644 --- a/stubs/config/filament-companies.php +++ b/stubs/config/filament-companies.php @@ -53,7 +53,7 @@ |-------------------------------------------------------------------------- | | Here you may specify the providers your application supports for OAuth. - | Out of the box, FilamentCompanies provides support for all of the OAuth + | Out of the box, FilamentCompanies provides support for all the OAuth | providers that are supported by Laravel Socialite. | */ @@ -69,7 +69,7 @@ | | Some of Company's features are optional. You may disable the features | by removing them from this array. You're free to only remove some of - | these features or you can even remove all of these if you need to. + | these features, or you can even remove all of these if you need to. | */ @@ -91,8 +91,8 @@ |-------------------------------------------------------------------------- | | This configuration value determines the default disk that will be used - | when storing profile photos for your application's users. Typically - | this will be the "public" disk but you may adjust this if needed. + | when storing profile photos for your application's users. Typically, + | this will be the "public" disk, but you may adjust this if needed. | */