Skip to content

Commit

Permalink
Add and run rector and pint
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbrandB committed Jun 15, 2024
1 parent 13e7525 commit 25c1a98
Show file tree
Hide file tree
Showing 42 changed files with 264 additions and 269 deletions.
40 changes: 0 additions & 40 deletions app/Console/Commands/fixJsonItems.php

This file was deleted.

6 changes: 5 additions & 1 deletion app/Http/Controllers/AttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function create()
public function store(Request $request)
{
$id = Attribute::create($request->all())->id;
return to_route('attributes.edit',$id);

return to_route('attributes.edit', $id);
}

public function show($id)
Expand All @@ -36,6 +37,7 @@ public function show($id)
public function edit($id)
{
$attribute = Attribute::findOrFail($id);

return Inertia::render('Attributes/Edit', [
'attributeTypes' => AttributeType::all(),
'attribute' => $attribute,
Expand All @@ -46,6 +48,7 @@ public function update(Request $request, $id)
{
$attribute = Attribute::findOrFail($id);
$attribute->update($request->all());

return to_route('attributes.index');
}

Expand All @@ -54,6 +57,7 @@ public function destroy($id)
$attribute = Attribute::findOrFail($id);
$attribute->items()->detach();
$attribute->delete();

return to_route('attributes.index');
}
}
8 changes: 6 additions & 2 deletions app/Http/Controllers/AttributeTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Models\AttributeType;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class AttributeTypeController extends Controller
{
Expand All @@ -24,7 +23,8 @@ public function create()
public function store(Request $request)
{
$id = AttributeType::create($request->all())->id;
return to_route('attribute_types.edit',$id);

return to_route('attribute_types.edit', $id);
}

public function show($id)
Expand All @@ -34,6 +34,7 @@ public function show($id)
public function edit($id)
{
$attributeType = AttributeType::findOrFail($id);

return Inertia::render('AttributeTypes/Edit',
['colors' => AttributeType::$colors, 'attributeType' => $attributeType]);
}
Expand All @@ -42,6 +43,7 @@ public function update(Request $request, $id)
{
$attributeType = AttributeType::findOrFail($id);
$attributeType->update($request->all());

return to_route('attribute_types.index');
}

Expand All @@ -52,7 +54,9 @@ public function destroy($id)
$attribute->items()->detach();
$attribute->delete();
}

$attributeType->delete();

return to_route('attribute_types.index');
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function create(): Response
/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
public function store(LoginRequest $loginRequest): RedirectResponse
{
$request->authenticate();
$loginRequest->authenticate();

$request->session()->regenerate();
$loginRequest->session()->regenerate();

return redirect()->intended(route('dashboard', absolute: false));
}
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/NewPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ public function store(Request $request): RedirectResponse
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function ($user) use ($request) {
static function ($user) use ($request): void {
$user->forceFill([
'password' => Hash::make($request->password),
'remember_token' => Str::random(60),
])->save();

event(new PasswordReset($user));
}
);
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class VerifyEmailController extends Controller
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
public function __invoke(EmailVerificationRequest $emailVerificationRequest): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
if ($emailVerificationRequest->user()->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}

if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
if ($emailVerificationRequest->user()->markEmailAsVerified()) {
event(new Verified($emailVerificationRequest->user()));
}

return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public function index(Request $request)
->whereIn('id', $items->pluck('json_items')->flatten()->unique())
->whereNotIn('id', $items->pluck('id')->toArray())
->get();

return Inertia::render('Test', [
'items' => $items,
'python' => $pythonItem,
'nodes' => $nodes,
]);
}

public function syncSelected(Request $request)
public function syncSelected(Request $request): void
{
$selected = $request->input('selected');
// add the selected items to the selected items in this session
Expand Down
54 changes: 33 additions & 21 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ class ItemController extends Controller
* Display a listing of the resource.
*/
public function index(Request $request)
{ $items = Item::query();
{
$builder = Item::query();
$filters = $request->input('filters');
foreach($filters??[] as $attributeCategoryId => $attribiteIds) {
$items->whereHas('attributes', function ($query) use ($attributeCategoryId, $attribiteIds) {
$query->where('attribute_type_id', $attributeCategoryId)->whereIn('attributes.id', $attribiteIds);
foreach ($filters ?? [] as $attributeCategoryId => $attributeIds) {
$builder->whereHas('attributes', static function ($query) use ($attributeCategoryId, $attributeIds): void {
$query->where('attribute_type_id', $attributeCategoryId)->whereIn('attributes.id', $attributeIds);
});
}

return Inertia::render('Items/Index', [
'initialSelectedItems'=> Item::whereIn('id', $request->session()->get('selected'))->get(),
'items' => $items->get(),
'initialSelectedItems' => Item::whereIn('id', $request->session()->get('selected') ?? [])->get(),
'items' => $builder->get(),
'attributeTypes' => AttributeType::with('attributes')->orderBy('created_at', 'desc')->get(),
'initialFilters' => $filters,
]);
Expand All @@ -47,16 +49,18 @@ public function create()
public function store(Request $request)
{
$photo = $request->file('photo');
$photo?->storeAs('photos/' . $photo->hashName(), ['disk' => 'public']);
$photo?->storeAs('photos/'.$photo->hashName(), ['disk' => 'public']);
$wiringPhoto = $request->file('wiring_photo');
$wiringPhoto?->storeAs('photos/' . $photo->hashName(), ['disk' => 'public']);
$wiringPhoto?->storeAs('photos/'.$photo->hashName(), ['disk' => 'public']);
$item = new Item();
$item->fill($request->except('attributes', 'photo', 'wiring_photo', 'json_items'));

$item->json_items = $request->input('edges') ?? [];
$item->photo = $photo?->hashName();
$item->wiring_photo = $wiringPhoto?->hashName();
$item->save();
$item->attributes()->sync($request->input('attributes')??[]);
$item->attributes()->sync($request->input('attributes') ?? []);

return to_route('items.show', ['public_id' => $item->public_id]);
}

Expand All @@ -66,10 +70,12 @@ public function store(Request $request)
public function show(string $publicId)
{
$id = Hashids::decode($publicId);
if (!$id || !isset($id[0])) {
if (! $id || ! isset($id[0])) {
abort(404);
}

$item = Item::with('attributes', 'attributes.attributeType')->findOrFail($id[0]);

return Inertia::render('Items/Show', [
'item' => $item,
]);
Expand All @@ -80,19 +86,20 @@ public function show(string $publicId)
*/
public function edit(int $id)
{
$attributeTypes = AttributeType::whereHas('attributes', function ($attributes) use ($id) {
$attributes->whereHas('items', function ($query) use ($id) {
$attributeTypes = AttributeType::whereHas('attributes', static function ($attributes) use ($id): void {
$attributes->whereHas('items', static function ($query) use ($id): void {
$query->where('items.id', $id);
});
})->with(['attributes' => function ($attributes) use ($id) {
$attributes->whereHas('items', function ($query) use ($id) {
})->with(['attributes' => static function ($attributes) use ($id): void {
$attributes->whereHas('items', static function ($query) use ($id): void {
$query->where('items.id', $id);
})->select('attribute_type_id', 'id');
}])->select('id')->get();
$myAttributes = new \stdClass();
foreach ($attributeTypes as $attributeType) {
$myAttributes->{$attributeType->id} = $attributeType->attributes->pluck('id');
}

return Inertia::render('Items/Edit', [
'item' => Item::with('attributes')->findorFail($id),
'items' => Item::query()->select('id', 'title')->get(),
Expand All @@ -109,29 +116,32 @@ public function update(Request $request, int $id)
$item = Item::findOrFail($id);
$photo = $request->file('photo');
if ($photo) {
$photo->storeAs('photos/' . $photo->hashName(), ['disk' => 'public']);
$photo->storeAs('photos/'.$photo->hashName(), ['disk' => 'public']);
if ($item->photo) {
//delete the old photo
Storage::disk('public')->delete('photos/' . $item->photo);
Storage::disk('public')->delete('photos/'.$item->photo);
}

$item->photo = $photo->hashName();
}

$wiring_photo = $request->file('wiring_photo');
if ($wiring_photo) {
$wiring_photo->storeAs('photos/' . $wiring_photo->hashName(), ['disk' => 'public']);
$wiring_photo->storeAs('photos/'.$wiring_photo->hashName(), ['disk' => 'public']);

if ($item->wiring_photo) {
//delete the old photo
Storage::disk('public')->delete('photos/' . $item->wiring_photo);
Storage::disk('public')->delete('photos/'.$item->wiring_photo);
}

$item->wiring_photo = $wiring_photo->hashName();
}

$item->fill($request->except('attributes', 'photo', 'wiring_photo', 'json_items'));
$item->json_items = $request->input('edges') ?? [];
$item->save();
$item->attributes()->sync($request->input('attributes')??[]);
$item->attributes()->sync($request->input('attributes') ?? []);

return to_route('items.show', ['public_id' => $item->public_id]);
}

Expand All @@ -143,12 +153,14 @@ public function destroy(int $id)
$item = Item::findOrFail($id);
if ($item->photo) {
//delete the old photo
Storage::disk('public')->delete('photos/' . $item->photo);
Storage::disk('public')->delete('photos/'.$item->photo);
}

if ($item->wiring_photo) {
//delete the old photo
Storage::disk('public')->delete('photos/' . $item->wiring_photo);
Storage::disk('public')->delete('photos/'.$item->wiring_photo);
}

$item->attributes()->detach();
$item->edges()->delete();
$item->delete();
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function edit(Request $request): Response
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
public function update(ProfileUpdateRequest $profileUpdateRequest): RedirectResponse
{
$request->user()->fill($request->validated());
$profileUpdateRequest->user()->fill($profileUpdateRequest->validated());

if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
if ($profileUpdateRequest->user()->isDirty('email')) {
$profileUpdateRequest->user()->email_verified_at = null;
}

$request->user()->save();
$profileUpdateRequest->user()->save();

return Redirect::route('profile.edit');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HandleInertiaRequests extends Middleware
/**
* Determine the current asset version.
*/
public function version(Request $request): string|null
public function version(Request $request): ?string
{
return parent::version($request);
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Attribute extends Model
use HasFactory;

protected $fillable = ['title', 'description', 'attribute_type_id'];

public function items(): BelongsToMany
{
return $this->belongsToMany(Item::class);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Edge extends Model
protected $fillable = [
'from_item_id',
'to_item_id',
'belongsto_item_id'
'belongsto_item_id',
];

public function fromItem(): BelongsTo
Expand Down
Loading

0 comments on commit 25c1a98

Please sign in to comment.