Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add larastan #290

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c046b73
build: add larastan as dev dependency
fabiorodriguesroque Nov 9, 2024
398b4e8
fix: stan errors caused by View/Components/App.php
fabiorodriguesroque Nov 9, 2024
83e0541
fix: stan errors caused by view/Components/App
fabiorodriguesroque Nov 9, 2024
0497d41
refactor: add return types to trait Sluggable
fabiorodriguesroque Nov 9, 2024
f034348
refactor: trait HasUpvote to avoid stan errors
fabiorodriguesroque Nov 9, 2024
de6fd08
refactor: update ogImageGenerator to handle empty titles, since all m…
fabiorodriguesroque Nov 9, 2024
d1452a4
chore: update phpstan.neon
fabiorodriguesroque Nov 9, 2024
d99f68b
refactor: WebhookClient service
fabiorodriguesroque Nov 9, 2024
67ed9f1
refactor: update services to avoid the stan errors
fabiorodriguesroque Nov 9, 2024
4a64967
refactor: add return types to policies methods
fabiorodriguesroque Nov 9, 2024
48c4fff
fix: refactor Comment, User, UserSocial and Vote models
fabiorodriguesroque Nov 9, 2024
1affb67
refactor: refactor Board, Changelog, Comment, Item, Project, Tag and …
fabiorodriguesroque Nov 10, 2024
730271d
refactor: add return types to console/commands
fabiorodriguesroque Nov 10, 2024
c5740a6
refactor: enums
fabiorodriguesroque Nov 10, 2024
32d7207
refactor: add return types to observers
fabiorodriguesroque Nov 10, 2024
d7e899d
refactor: fix phpstan errors in the providers & CommentObserver
fabiorodriguesroque Nov 10, 2024
7399fa2
refactor: add return types to sso exception
fabiorodriguesroque Nov 11, 2024
be82e92
refactor: Colors page
fabiorodriguesroque Nov 11, 2024
9a8080e
refactor: Filament settings page
fabiorodriguesroque Nov 11, 2024
b4c7b9b
refactor: Filament Pages & ChangelogResource
fabiorodriguesroque Nov 11, 2024
f8d1a9e
fix: edit comment & inbox resource
fabiorodriguesroque Nov 13, 2024
227626c
fix: ItemObserver.php
fabiorodriguesroque Nov 13, 2024
f2f6ebe
refactor: MentionNotification
fabiorodriguesroque Nov 13, 2024
2d0e047
refactor: MentionNotification
fabiorodriguesroque Nov 13, 2024
93bd155
refactor: update ItemUpdatedNotification
fabiorodriguesroque Nov 13, 2024
73e7a32
refactor: update ItemHasNewCommentNotification
fabiorodriguesroque Nov 13, 2024
30f1a58
refactor: CommentHasReplyNotification
fabiorodriguesroque Nov 13, 2024
c44683a
refactor: update RecentMentions, RecentComments and RecentItems
fabiorodriguesroque Nov 13, 2024
b9f412b
refactor: add return types and type some properties
fabiorodriguesroque Nov 13, 2024
27aec10
refactor: add return types to ItemCard
fabiorodriguesroque Nov 13, 2024
9376b9a
refactor: refactor Profile component
fabiorodriguesroque Nov 13, 2024
46e0540
refactor: mails & notifications with typed arrays
fabiorodriguesroque Nov 15, 2024
f8b58cc
refactor: livewire components with return types
fabiorodriguesroque Nov 15, 2024
3085d83
refactor Livewire components
fabiorodriguesroque Nov 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Commands/ConvertNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConvertNotifications extends Command

protected $description = 'Convert notifications to new format';

public function handle()
public function handle(): int
{
$array = [];

Expand Down
3 changes: 3 additions & 0 deletions app/Console/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ protected function askForStar(): void
}
}

/**
* @return array<string, mixed>
*/
protected function getUserData(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions app/Enums/InboxWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ enum InboxWorkflow: string
case WithoutBoardOrProject = 'without-board-or-project';
case WithoutBoard = 'without-board';

/**
* @return Collection<string, string>
*/
public static function getSelectOptions(): Collection
{
return collect(InboxWorkflow::cases())
Expand Down
3 changes: 2 additions & 1 deletion app/Exceptions/SsoException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Http\RedirectResponse;

class SsoException extends Exception
{
public function render($request)
public function render(): RedirectResponse
{
return redirect()->route('login')->withErrors([
$this->getMessage()
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Pages/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public function getHeading(): string|Htmlable

public static function shouldRegisterNavigation(): bool
{
return auth()->user()->hasRole(UserRole::Admin);
return auth()->user()?->hasRole(UserRole::Admin) ?? false;
}

public function mount(): void
{
parent::mount();

abort_unless(auth()->user()->hasRole(UserRole::Admin), 403);
abort_unless(auth()->user()?->hasRole(UserRole::Admin) ?? false, 403);
}

public function form(Form $form): Form
Expand Down
18 changes: 10 additions & 8 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Board;
use App\Enums\UserRole;
use App\Models\Project;
use App\Services\OgImage;
use Filament\Forms\Get;
use Filament\Forms\Form;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -53,18 +54,21 @@ public function getHeading(): string|Htmlable
return trans('settings.title');
}

/**
* @var Collection<int, string>
*/
public Collection $ogImages;

public static function shouldRegisterNavigation(): bool
{
return auth()->user()->hasRole(UserRole::Admin);
return auth()->user()?->hasRole(UserRole::Admin) ?? false;
}

public function mount(): void
{
parent::mount();

abort_unless(auth()->user()->hasRole(UserRole::Admin), 403);
abort_unless(auth()->user()?->hasRole(UserRole::Admin) ?? false, 403);

$this->ogImages = collect(Storage::disk('public')->allFiles())
->filter(
Expand Down Expand Up @@ -275,12 +279,10 @@ public function form(Form $form): Form
Select::make('column_span')
->label(trans('settings.dashboard-items.column-span'))
->helperText(trans('settings.dashboard-items.column-span-helper-text'))
->options(
[
1 => 1,
2 => 2,
]
)
->options(fn () => [
1 => 1,
2 => 2,
])
->default(1),

Toggle::make('must_have_project')
Expand Down
11 changes: 9 additions & 2 deletions app/Filament/Pages/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Pages;

use App\Enums\UserRole;
use App\Models\User;
use Filament\Pages\Page;
use Filament\Actions\Action;
use App\Services\SystemChecker;
Expand Down Expand Up @@ -36,12 +37,18 @@ public function getHeading(): string|Htmlable

public static function shouldRegisterNavigation(): bool
{
return auth()->user()->hasRole(UserRole::Admin);
/** @var User $user */
$user = auth()->user();

return $user->hasRole(UserRole::Admin);
}

public function mount(): void
{
abort_unless(auth()->user()->hasRole(UserRole::Admin), 403);
/** @var User $user */
$user = auth()->user();

abort_unless($user->hasRole(UserRole::Admin), 403);
}

protected function getHeaderWidgets(): array
Expand Down
5 changes: 4 additions & 1 deletion app/Filament/Pages/Widgets/System/SystemInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class SystemInfo extends Widget

protected int | string | array $columnSpan = 2;

/**
* @var array<string, mixed>
*/
public array $version = [
'remoteVersion' => 0,
'currentVersion' => 0
];
public bool $isOutOfDate = false;
public string $phpVersion = '8.1';

public function mount()
public function mount(): void
{
$systemChecker = (new SystemChecker);

Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/ChangelogResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function form(Form $form): Form
Select::make('user_id')
->label(trans('resources.changelog.author'))
->relationship('user', 'name')
->default(auth()->user()->id)
->default(auth()->user()?->id)
->preload()
->required()
->searchable(),
Expand Down
9 changes: 8 additions & 1 deletion app/Filament/Resources/CommentResource/Pages/EditComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources\CommentResource\Pages;

use App\Models\Comment;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
Expand All @@ -18,8 +19,14 @@ public function getHeaderActions(): array
->label(trans('resources.item.view-public'))
->color('gray')
->openUrlInNewTab()
->url(fn () => route('items.show', $this->record->item) . '#comment-' . $this->record->id),
->url(fn () => route('items.show', $this->getCurrentComment()->item) . '#comment-' . $this->getCurrentComment()->id),
DeleteAction::make(),
];
}

protected function getCurrentComment(): Comment
{
/** @var Comment */
return $this->record;
}
}
3 changes: 2 additions & 1 deletion app/Filament/Resources/InboxResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static function shouldRegisterNavigation(): bool

public static function getNavigationBadge(): ?string
{
return Item::query()->forInbox()->count();
return (string) Item::query()->forInbox()->count();

}

public static function form(Form $form): Form
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/Item/VoteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Livewire\Item;

use App\Models\User;
use App\Models\Vote;
use Livewire\Component;
use Illuminate\Support\Collection;
Expand All @@ -12,6 +13,10 @@ class VoteButton extends Component
{
public Model $model;
public Vote|null $vote;

/**
* @var Collection<User>
*/
public Collection $recentVoters;
public int $recentVotersToShow = 5;
public bool $showSubscribeOption;
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Modals/Item/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire\Modals\Item;

use App\Models\Item;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Filament\Tables\Table;
use Filament\Forms\Contracts\HasForms;
Expand All @@ -29,7 +30,7 @@ public function table(Table $table): Table
]);
}

public function render()
public function render(): View
{
return view('livewire.modals.item.search');
}
Expand Down
28 changes: 22 additions & 6 deletions app/Livewire/My.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Livewire;

use App\Models\Item;
use Closure;
use Filament\Tables;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Livewire\Component;
use Illuminate\Support\Carbon;
use Filament\Forms\Contracts\HasForms;
Expand All @@ -16,26 +19,39 @@ class My extends Component implements HasTable, HasForms
{
use InteractsWithTable, InteractsWithForms;

public $type = 'default';
public string $type = 'default';

protected function getTableQuery(): Builder
/**
* @return Builder<Item>|null
*/
protected function getTableQuery(): Builder|null
{
if ($this->type == 'default') {
return auth()->user()->items()->with('board.project')->getQuery();
return auth()->user()?->items()->with('board.project')->getQuery();
}

if ($this->type == 'commentedOn') {
return auth()->user()->commentedItems()->getQuery();
return auth()->user()?->commentedItems()->getQuery();
}

return auth()->user()->votedItems()->with('board.project')->latest('votes.created_at')->getQuery();
return auth()->user()?->votedItems()->with('board.project')->latest('votes.created_at')->getQuery();
}

/**
* Get per page select options.
*
* @return int[]
*/
protected function getTableRecordsPerPageSelectOptions(): array
{
return auth()->user()->per_page_setting ?? [5];
}

/**
* Get the table columns.
*
* @return Tables\Columns\TextColumn[]
*/
protected function getTableColumns(): array
{
return [
Expand Down Expand Up @@ -71,7 +87,7 @@ protected function getTableRecordUrlUsing(): ?Closure
};
}

public function render()
public function render(): View
{
return view('livewire.my');
}
Expand Down
Loading
Loading