Skip to content

Commit

Permalink
Install Larastan
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho committed Jan 10, 2024
1 parent 7afcbe0 commit 73db6ae
Show file tree
Hide file tree
Showing 29 changed files with 303 additions and 112 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait PasswordValidationRules
/**
* Get the validation rules used to validate passwords.
*
* @return array<int, (Rule | array | string)>
* @return array<int, (Rule | array<int, string> | string)>
*/
protected function passwordRules(): array
{
Expand Down
10 changes: 7 additions & 3 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

use App\Models\User;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param array<string, string> $input
*
* @throws ValidationException
*/
public function update(User $user, array $input): void
{
Expand All @@ -24,7 +26,9 @@ public function update(User $user, array $input): void
])->validateWithBag('updateProfileInformation');

if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
/** @var UploadedFile $photo */
$photo = $input['photo'];
$user->updateProfilePhoto($photo);
}

if ($input['email'] !== $user->email &&
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Jetstream/AddTeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function validate(Team $team, string $email, ?string $role): void
/**
* Get the validation rules for adding a team member.
*
* @return array<string, (Rule | array | string)>
* @return array<string, (Rule | array<int, mixed> | string)>
*/
protected function rules(): array
{
Expand Down
7 changes: 5 additions & 2 deletions app/Actions/Jetstream/CreateTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public function create(User $user, array $input): Team

AddingTeam::dispatch($user);

$user->switchTeam($team = $user->ownedTeams()->create([
/** @var Team $team */
$team = $user->ownedTeams()->create([
'name' => $input['name'],
'personal_team' => false,
]));
]);

$user->switchTeam($team);

return $team;
}
Expand Down
4 changes: 1 addition & 3 deletions app/Actions/Jetstream/DeleteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ protected function deleteTeams(User $user): void
{
$user->teams()->detach();

$user->ownedTeams->each(function (Team $team) {
$this->deletesTeams->delete($team);
});
$user->ownedTeams->each(fn ($team) => $this->deletesTeams->delete($team));
}
}
3 changes: 2 additions & 1 deletion app/Actions/Jetstream/InviteTeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function invite(User $user, Team $team, string $email, ?string $role = nu

InvitingTeamMember::dispatch($team, $email, $role);

/** @var \App\Models\TeamInvitation $invitation */
$invitation = $team->teamInvitations()->create([
'email' => $email,
'role' => $role,
Expand All @@ -55,7 +56,7 @@ protected function validate(Team $team, string $email, ?string $role): void
/**
* Get the validation rules for inviting a team member.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
* @return array<string, \Illuminate\Contracts\Validation\Rule|array<int, mixed>|string>
*/
protected function rules(Team $team): array
{
Expand Down
10 changes: 7 additions & 3 deletions app/Actions/Photos/ExtractLocationFromPhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function run(UploadedFile $photo): array
return [];
}

$result = $this->convertArrayToLatLng((array) $exif);
$result = $this->convertExifToLatLng((array) $exif);

if ($result['latitude'] === 0.0 && $result['longitude'] === 0.0) {
return [];
Expand All @@ -27,7 +27,11 @@ public function run(UploadedFile $photo): array
return $result;
}

private function convertArrayToLatLng(array $exif): array
/**
* @param array<string, mixed> $exif
* @return float[]
*/
private function convertExifToLatLng(array $exif): array
{
$GPSLatitudeRef = $exif['GPSLatitudeRef'];
$GPSLatitude = $exif['GPSLatitude'];
Expand Down Expand Up @@ -59,7 +63,7 @@ private function gpsToNumeric(?string $coordinates): float

$parts = explode('/', $coordinates);

if ($parts === []) {
if ($parts == []) {
return 0.0;
}

Expand Down
3 changes: 3 additions & 0 deletions app/Actions/Photos/ExtractsLocationFromPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

interface ExtractsLocationFromPhoto
{
/**
* @return array<string, float>
*/
public function run(UploadedFile $photo): array;
}
1 change: 1 addition & 0 deletions app/Console/Commands/GenerateRandomPhotos.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GenerateRandomPhotos extends Command

public function handle(): void
{
/** @var User $user */
$user = User::query()
->where('email', '[email protected]')
->first();
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/CopyPhotoItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace App\Http\Controllers;

use App\Models\PhotoItem;
use Illuminate\Http\JsonResponse;

class CopyPhotoItemController extends Controller
{
public function __invoke(PhotoItem $photoItem): array
public function __invoke(PhotoItem $photoItem): JsonResponse
{
$newPhotoItem = $photoItem->replicate();
$newPhotoItem->save();

$newPhotoItem->tags()->sync($photoItem->tags);

return [];
return response()->json();
}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/PhotoItemTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use App\Models\PhotoItem;
use App\Models\Tag;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PhotoItemTagsController extends Controller
{
public function store(PhotoItem $photoItem, Request $request)
public function store(PhotoItem $photoItem, Request $request): JsonResponse
{
$photoItem->tags()->syncWithoutDetaching($request->input('tag_id'));

return [];
return response()->json();
}

public function destroy(PhotoItem $photoItem, Tag $tag)
public function destroy(PhotoItem $photoItem, Tag $tag): JsonResponse
{
$photoItem->tags()->detach($tag);

return [];
return response()->json();
}
}
13 changes: 7 additions & 6 deletions app/Http/Controllers/PhotoItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use App\Models\Photo;
use App\Models\PhotoItem;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PhotoItemsController extends Controller
{
public function store(Photo $photo, Request $request)
public function store(Photo $photo, Request $request): JsonResponse
{
/** @var User $user */
$user = auth()->user();
Expand All @@ -20,10 +21,10 @@ public function store(Photo $photo, Request $request)
'recycled' => $user->settings->recycled_by_default,
]);

return [];
return response()->json();
}

public function update(PhotoItem $photoItem, UpdatePhotoItemRequest $request): array
public function update(PhotoItem $photoItem, UpdatePhotoItemRequest $request): JsonResponse
{
if ($request->filled('quantity')) {
$photoItem->quantity = $request->quantity;
Expand All @@ -39,13 +40,13 @@ public function update(PhotoItem $photoItem, UpdatePhotoItemRequest $request): a

$photoItem->save();

return [];
return response()->json();
}

public function destroy(PhotoItem $photoItem)
public function destroy(PhotoItem $photoItem): JsonResponse
{
$photoItem->delete();

return [];
return response()->json();
}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/PhotoTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use App\Models\Photo;
use App\Models\Tag;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PhotoTagsController extends Controller
{
public function store(Photo $photo, Request $request)
public function store(Photo $photo, Request $request): JsonResponse
{
$photo->tags()->syncWithoutDetaching($request->tag_id);

return [];
return response()->json();
}

public function destroy(Photo $photo, Tag $tag)
public function destroy(Photo $photo, Tag $tag): JsonResponse
{
$photo->tags()->detach($tag);

return [];
return response()->json();
}
}
17 changes: 11 additions & 6 deletions app/Http/Controllers/PhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use App\Models\Tag;
use App\Models\TagType;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Storage;
use Inertia\Inertia;
use Inertia\Response;

class PhotosController extends Controller
{
public function index()
public function index(): Response
{
/** @var User $user */
$user = auth()->user();
Expand All @@ -35,15 +37,18 @@ public function index()
]);
}

public function show(Photo $photo)
public function show(Photo $photo): Response|JsonResponse
{
$tagTypes = TagType::query()->get();
$tags = Tag::query()
->orderBy('name')
->get()
->groupBy('tag_type_id')
->mapWithKeys(function ($values, $key) use ($tagTypes) {
return [$tagTypes->find($key)->slug => $values];
/** @var TagType $tagType */
$tagType = $tagTypes->find($key);

return [$tagType->slug => $values];
});

if (! request()->wantsJson()) {
Expand All @@ -60,14 +65,14 @@ public function show(Photo $photo)
->items()
->orderByDesc('photo_items.id')
->get()
->each(fn (Item $item) => $item->pivot->load('tags'));
->each(fn (Item $item) => $item->pivot?->load('tags'));

$photo->append('full_path');

return [
return response()->json([
'photo' => $photo,
'items' => $items,
];
]);
}

public function destroy(Photo $photo): RedirectResponse
Expand Down
66 changes: 0 additions & 66 deletions app/Http/Controllers/TagController.php

This file was deleted.

Loading

0 comments on commit 73db6ae

Please sign in to comment.