mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22:34 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -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