Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperTurtle committed Dec 20, 2023
1 parent 13038d1 commit b5ef23e
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContactController extends Controller
* @return JsonResponse Returns a JSON response indicating the success of the email operation.
* @throws ValidationException If the request data does not pass validation checks.
*/
public function sendEmail(Request $request)
public function sendEmail(Request $request): JsonResponse
{
// Validate the request data
$validatedData = $request->validate([
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function show(Product $product): Factory|View
* This method returns the view for creating a new product.
*
* @return Factory|View Returns a view for creating a new product.
* @throws AuthorizationException
*/
public function create(): Factory|View
{
Expand All @@ -101,6 +102,7 @@ public function create(): Factory|View
*
* @param StoreProductRequest $request The request object containing product data.
* @return RedirectResponse Returns JSON response with the status of product creation.
* @throws AuthorizationException
*/
public function store(StoreProductRequest $request): RedirectResponse
{
Expand Down Expand Up @@ -138,6 +140,7 @@ public function edit(Product $product): Factory|View
* @param UpdateProductRequest $request The request object containing updated product data.
* @param Product $product The product instance to update.
* @return RedirectResponse Returns a redirect response to the product's detail page.
* @throws AuthorizationException
*/
public function update(UpdateProductRequest $request, Product $product): RedirectResponse
{
Expand All @@ -163,6 +166,7 @@ public function update(UpdateProductRequest $request, Product $product): Redirec
*
* @param Product $product The product instance to delete.
* @return RedirectResponse
* @throws AuthorizationException
*/
public function destroy(Product $product): RedirectResponse
{
Expand Down
9 changes: 4 additions & 5 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
Expand All @@ -19,7 +18,7 @@
*/
class ProfileController extends Controller
{
protected $imageService;
protected ImageService $imageService;

public function __construct(ImageService $imageService)
{
Expand All @@ -29,7 +28,7 @@ public function __construct(ImageService $imageService)
/**
* Display the user's profile.
* This method returns the view for the user's profile with the user data.
*
*
* @param int $userID The ID of the user whose profile is being displayed.
* @return View Returns the view for the user's profile with the user data.
*/
Expand All @@ -43,7 +42,7 @@ public function show(int $userID): View
* Display the user's profile form for editing.
* This method returns the view for the user to edit their profile information.
*
* @param Request $request The current request instance.
* @param int $userID
* @return View Returns the view for editing the user's profile with the user data.
*/
public function edit(int $userID): View
Expand Down Expand Up @@ -102,7 +101,7 @@ public function update(ProfileUpdateRequest $request, int $userID): RedirectResp
*
* @param Request $request The current request instance.
* @param int $userID The ID of the user whose account is being deleted.
* @return RedirectResponse Returns a redirect response to the home page after account deletion.
* @return RedirectResponse Returns a redirect response to the home page after account deletion.
*/
public function destroy(Request $request, int $userID): RedirectResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ReviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function update(UpdateReviewRequest $request, Review $review): JsonRespon
* @param int $id The ID of the review to be deleted.
* @return JsonResponse Returns JSON response with a success message.
*/
public function destroy($id)
public function destroy(int $id): JsonResponse
{
$review = Review::find($id);
$review->delete();
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Middleware/EnsureUserIsArtisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
use Symfony\Component\HttpFoundation\Response;

/**
* Middleware to redirect the user if their cart is empty.
* Middleware to redirect the user if their cart is empty.
*/
class EnsureUserIsArtisan
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next): Response
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Middleware/RedirectIfNoTransactionDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Middleware to redirect the user if no transaction details are present in the session.
*
*
* This middleware checks if the session has 'transactionDetails' and if they are structured as an array.
* If the session does not have valid 'transactionDetails', the user is redirected to the products index route.
* This is typically used to ensure that a user can only access certain routes if they have completed a transaction.
Expand All @@ -18,11 +18,11 @@ class RedirectIfNoTransactionDetails
/**
* Handle an incoming request.
*
* Checks the session for 'transactionDetails'. If not present or not an array,
* Checks the session for 'transactionDetails'. If not present or not an array,
* it redirects to the products index page. Otherwise, it allows the request to proceed.
*
* @param \Illuminate\Http\Request $request The incoming request.
* @param \Closure $next The next middleware in the pipeline.
* @param Request $request The incoming request.
* @param Closure $next The next middleware in the pipeline.
* @return Response The response after handling.
*/
public function handle(Request $request, Closure $next): Response
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/CheckoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

/**
Expand All @@ -23,7 +24,7 @@ public function authorize(): bool
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
Expand Down
7 changes: 4 additions & 3 deletions app/Mail/ContactMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
Expand All @@ -19,15 +20,15 @@ class ContactMail extends Mailable
/**
* @var array The data received from the contact form.
*/
public $data;
public array $data;

/**
* Create a new message instance.
* Initializes the mail with data provided from the contact form.
*
* @param array $data Data passed to the email view.
*/
public function __construct($data)
public function __construct(array $data)
{
$this->data = $data;
}
Expand Down Expand Up @@ -64,7 +65,7 @@ public function content(): Content
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment> Returns an array of attachments.
* @return array<int, Attachment> Returns an array of attachments.
*/
public function attachments(): array
{
Expand Down
3 changes: 2 additions & 1 deletion app/Mail/SendOrderConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Mail;

use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
Expand Down Expand Up @@ -101,7 +102,7 @@ public function generatePdf(): string
$pdfFilePath = storage_path('pdfs/order-confirmation-' . time() . '.pdf');

$pdf->save($pdfFilePath);
} catch (\Exception $e) {
} catch (Exception $e) {
Log::error('Error during PDF generation and saving: ' . $e->getMessage(), [
'exception' => $e,
]);
Expand Down
2 changes: 0 additions & 2 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* @property Carbon $created_at Timestamp when the category was created.
* @property Carbon $updated_at Timestamp when the category was last updated.
*
* @method HasMany products() HasMany relationship with Product. Represents all products belonging to this category.
*
* @package App\Models
*/
class Category extends Model
Expand Down
10 changes: 0 additions & 10 deletions app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
* @property Carbon $created_at Timestamp when the product was created.
* @property Carbon $updated_at Timestamp when the product was last updated.
*
* @method BelongsTo artisan() BelongsTo relationship with User. Indicates the creator of the product.
* @method BelongsTo category() BelongsTo relationship with Category. Indicates the category of the product.
* @method HasMany images() HasMany relationship with ProductImage. Represents the images associated with the product.
* @method HasMany reviews() HasMany relationship with Review. Represents the reviews made for the product.
*
* @method bool hasUserReviewed(int $userId) Checks if a specific user has already reviewed the product.
* @method float|null averageRating() Calculates and returns the average rating of the product based on its reviews.
* @method int totalReviews() Returns the total number of reviews made for the product.
* @method bool isInUserCart() Checks if the product is in the current user's shopping cart.
*
* @package App\Models
*/
class Product extends Model
Expand Down
2 changes: 0 additions & 2 deletions app/Models/ProductImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* @property Carbon $created_at Timestamp when the image was created.
* @property Carbon $updated_at Timestamp when the image was last updated.
*
* @method BelongsTo product() BelongsTo relationship with Product. Indicates the product to which the image belongs.
*
* @package App\Models
*/
class ProductImage extends Model
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
* @property Carbon $created_at Timestamp when the review was created.
* @property Carbon $updated_at Timestamp when the review was last updated.
*
* @method BelongsTo product() BelongsTo relationship with Product. Indicates the product that is being reviewed.
* @method BelongsTo user() BelongsTo relationship with User. Indicates the user who made the review.
*
* @package App\Models
*/
class Review extends Model
Expand Down
6 changes: 0 additions & 6 deletions app/Models/ShoppingCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
* @property Carbon|null $updated_at Timestamp when the cart item was last updated. Can be null.
* @property-read float|int $total_price Accessor to calculate the total price of the cart item, based on the quantity and the product's price.
*
* @method BelongsTo user() BelongsTo relationship with User. Indicates the user who owns the shopping cart item.
* @method BelongsTo product() BelongsTo relationship with Product. Indicates the product that is in the shopping cart.
*
* @method float|int getTotalPriceAttribute() Accessor to calculate the total price of the cart item.
* @method bool isEmpty() Checks if the shopping cart is empty.
*
* @package App\Models
*/
class ShoppingCart extends Model
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
* @property Carbon $created_at Timestamp when the transaction was created.
* @property Carbon $updated_at Timestamp when the transaction was last updated.
*
* @method BelongsTo buyer() BelongsTo relationship with User. Represents the buyer in the transaction.
* @method BelongsTo product() BelongsTo relationship with Product. Represents the product involved in the transaction.
*
* @package App\Models
*/
class Transaction extends Model
Expand Down
8 changes: 1 addition & 7 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
* @property Carbon|null $updated_at Timestamp when the user account was last updated. Can be null.
* @property bool $isArtisan Flag indicating whether the user is an artisan.
*
* @method HasOne profile() HasOne relationship with UserProfile. Represents the user's profile.
* @method HasMany products() HasMany relationship with Product. Represents products created by the user (if the user is an artisan).
* @method HasMany reviews() HasMany relationship with Review. Represents reviews written by the user.
* @method HasOne cart() HasOne relationship with ShoppingCart. Represents the user's cart.
* @method HasMany transactions() HasMany relationship with Transaction. Represents transactions where the user is the buyer.
*
* @package App\Models
*/
class User extends Authenticatable implements MustVerifyEmail
Expand Down Expand Up @@ -99,7 +93,7 @@ public function reviews(): HasMany

/**
* Get the cart associated with the user.
*
*
* @return HasOne
*/
public function cart(): HasOne
Expand Down
2 changes: 0 additions & 2 deletions app/Models/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* @property Carbon $created_at Timestamp when the profile was created.
* @property Carbon $updated_at Timestamp when the profile was last updated.
*
* @method BelongsTo user() BelongsTo relationship with User. Represents the user to whom the profile belongs.
*
* @package App\Models
*/
class UserProfile extends Model
Expand Down
5 changes: 2 additions & 3 deletions app/Services/CheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class CheckoutService
* It begins a database transaction and attempts to create a Transaction record for each cart item.
* It sends an order confirmation email upon success or rolls back the transaction on failure.
*
* @param User $user The user performing the checkout.
* @param User|null $user The user performing the checkout.
* @param array $buyerData
* @return array Returns the status of the checkout process along with appropriate messages and transaction details.
* @throws ModelNotFoundException Throws if a product in the cart is not found.
* @throws Exception Throws on any other error encountered during the process.
*/
public function processCheckout(?User $user, array $buyerData): array
{
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
Route::prefix("dashboard")->group(function () {
Route::get('/', [DashboardController::class, 'index'])->name('dashboard')->middleware(EnsureUserIsArtisan::class);
Route::patch('/transactions/{transaction}/mark-as-sent', [DashboardController::class, 'markAsSent'])
->name('dashboard.markAsSent')->middleware(EnsureUserIsArtisan::class);;
->name('dashboard.markAsSent')->middleware(EnsureUserIsArtisan::class);
});

// Cart routes
Expand Down

0 comments on commit b5ef23e

Please sign in to comment.