mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -29,7 +29,10 @@ public static function getNavigationItemActiveRoutePattern(): string
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('viewAny', Project::class) ?? false;
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('viewAny', Project::class);
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
@ -47,15 +50,13 @@ protected function getHeaderActions(): array
|
||||
->icon('heroicon-o-plus')
|
||||
->authorize('create', Project::class)
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->form(function (Form $form) {
|
||||
return $form->schema([
|
||||
TextInput::make('name')
|
||||
->name('name')
|
||||
->rules(CreateProject::rules()['name']),
|
||||
])->columns(1);
|
||||
})
|
||||
->action(function (array $data) {
|
||||
app(CreateProject::class)->create(auth()->user(), $data);
|
||||
->form(fn (Form $form): \Filament\Forms\Form => $form->schema([
|
||||
TextInput::make('name')
|
||||
->name('name')
|
||||
->rules(CreateProject::rules()['name']),
|
||||
])->columns(1))
|
||||
->action(function (array $data): void {
|
||||
app(CreateProject::class)->create($this->getUser(), $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
|
@ -62,9 +62,9 @@ protected function getHeaderActions(): array
|
||||
->modalHeading('Delete Project')
|
||||
->modalDescription('Are you sure you want to delete this project? This action will delete all associated data and cannot be undone.')
|
||||
->requiresConfirmation()
|
||||
->action(function (Project $record) {
|
||||
->action(function (Project $record): void {
|
||||
try {
|
||||
app(DeleteProject::class)->delete(auth()->user(), $record);
|
||||
app(DeleteProject::class)->delete($this->getUser(), $record);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
|
@ -21,7 +21,7 @@ class AddUser extends Widget implements HasForms
|
||||
|
||||
public Project $project;
|
||||
|
||||
public ?int $user;
|
||||
public ?int $user = null;
|
||||
|
||||
public function mount(Project $project): void
|
||||
{
|
||||
@ -38,7 +38,7 @@ public function form(Form $form): Form
|
||||
Select::make('user')
|
||||
->name('user')
|
||||
->options(fn () => User::query()
|
||||
->whereNotExists(function ($query) {
|
||||
->whereNotExists(function ($query): void {
|
||||
$query->select('user_id')
|
||||
->from('user_project')
|
||||
->whereColumn('users.id', 'user_project.user_id')
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
class ProjectUsersList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $listeners = ['userAdded' => '$refresh'];
|
||||
|
||||
public Project $project;
|
||||
@ -20,9 +23,12 @@ public function mount(Project $project): void
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<User>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return User::query()->whereHas('projects', function (Builder $query) {
|
||||
return User::query()->whereHas('projects', function (Builder $query): void {
|
||||
$query->where('project_id', $this->project->id);
|
||||
});
|
||||
}
|
||||
@ -46,10 +52,8 @@ public function table(Table $table): Table
|
||||
Tables\Actions\DeleteAction::make()
|
||||
->label('Remove')
|
||||
->modalHeading('Remove user from project')
|
||||
->visible(function ($record) {
|
||||
return $this->authorize('update', $this->project)->allowed() && $record->id !== auth()->id();
|
||||
})
|
||||
->using(function ($record) {
|
||||
->visible(fn ($record): bool => $this->authorize('update', $this->project)->allowed() && $record->id !== auth()->id())
|
||||
->using(function ($record): void {
|
||||
$this->project->users()->detach($record);
|
||||
}),
|
||||
])
|
||||
|
@ -12,8 +12,14 @@
|
||||
|
||||
class ProjectsList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Project>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Project::query();
|
||||
@ -35,17 +41,20 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
->columns($this->getTableColumns())
|
||||
->recordUrl(fn (Project $record) => Settings::getUrl(['project' => $record]))
|
||||
->recordUrl(fn (Project $record): string => Settings::getUrl(['project' => $record]))
|
||||
->actions([
|
||||
Action::make('settings')
|
||||
->label('Settings')
|
||||
->icon('heroicon-o-cog-6-tooth')
|
||||
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||
->url(fn (Project $record) => Settings::getUrl(['project' => $record])),
|
||||
->authorize(fn ($record) => $user->can('update', $record))
|
||||
->url(fn (Project $record): string => Settings::getUrl(['project' => $record])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,31 @@ class SelectProject extends Widget
|
||||
{
|
||||
protected static string $view = 'widgets.select-project';
|
||||
|
||||
public ?Project $currentProject;
|
||||
public ?Project $currentProject = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Project>
|
||||
*/
|
||||
public Collection $projects;
|
||||
|
||||
public int|string|null $project;
|
||||
public int|string|null $project = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->currentProject = auth()->user()->currentProject;
|
||||
$this->projects = auth()->user()->allProjects()->get();
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$this->currentProject = $user->currentProject;
|
||||
$this->projects = $user->allProjects()->get();
|
||||
}
|
||||
|
||||
public function updateProject(Project $project): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$this->authorize('view', $project);
|
||||
auth()->user()->update(['current_project_id' => $project->id]);
|
||||
$user->update(['current_project_id' => $project->id]);
|
||||
|
||||
$this->redirect('/');
|
||||
}
|
||||
|
Reference in New Issue
Block a user