Refactor code for improved readability and consistency

- Removed unnecessary blank lines in various files to enhance code clarity.
- Updated comments for consistency and clarity across multiple classes and methods.
- Adjusted spacing in test files for better formatting and readability.
This commit is contained in:
Mekan1206
2026-02-08 02:24:43 +05:00
parent 2dfa3747b5
commit c46eccb24f
38 changed files with 257 additions and 257 deletions

View File

@@ -38,7 +38,7 @@ class OrderController extends Controller
*/
public function store(CheckoutOrderRequest $request, CreateOrderService $service): JsonResponse
{
$order = $service->execute(auth()->user(), $request->validated());
$order = $service->execute(auth()->user(), $request->all());
$url = null;
if ($request->payment_type_id == 3) {
@@ -81,7 +81,6 @@ class OrderController extends Controller
/**
* Remove the specified resource from storage.
*
* @param Order $order
* @return \Illuminate\Http\Response
*/
public function destroy(Order $order)

View File

@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Api\V1\Product\Resources;
use App\Http\Resources\MediaResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use App\Http\Controllers\Api\V1\Product\Resources\Variant\ProductVariantResource;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductIndexResource extends JsonResource

View File

@@ -2,7 +2,6 @@
namespace App\Http\Requests\Api\V1\Auth;
use App\Rules\VerificationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

View File

@@ -27,16 +27,16 @@ class Product extends Model implements HasMedia, Viewable
*/
use HasFactory;
/**
* Has Schemaless Attributes (spatie/laravel-schemaless-attributes)
*/
use HasSchemalessAttributes;
/**
* Has Properties Json
*/
use HasPropertiesJson;
/**
* Has Schemaless Attributes (spatie/laravel-schemaless-attributes)
*/
use HasSchemalessAttributes;
/**
* Has Slug (spatie/laravel-sluggable)
*/

View File

@@ -38,7 +38,6 @@ class Warning extends Resource
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
@@ -68,7 +67,6 @@ class Warning extends Resource
/**
* Get the cards available for the request.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(NovaRequest $request)
@@ -79,7 +77,6 @@ class Warning extends Resource
/**
* Get the filters available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function filters(NovaRequest $request)
@@ -90,7 +87,6 @@ class Warning extends Resource
/**
* Get the lenses available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function lenses(NovaRequest $request)
@@ -101,7 +97,6 @@ class Warning extends Resource
/**
* Get the actions available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request)

View File

@@ -2,11 +2,11 @@
namespace App\Providers;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\ServiceProvider;
use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityRequirement;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\ServiceProvider;
class DocumentationServiceProvider extends ServiceProvider
{

View File

@@ -13,15 +13,12 @@ class CreateOrderService
{
/**
* Create a new order for the user
*
* @param User $user
* @param array $data
* @return Order
*/
public function execute(User $user, array $data): Order
{
return DB::transaction(function () use ($user, $data) {
// 1. Create the order
info(['service' => $data]);
$order = Order::create($data);
// 2. Process Cart Items

View File

@@ -13,6 +13,9 @@ return new class extends Migration
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('source_app');
});
Schema::table('orders', function (Blueprint $table) {
$table->string('source')->nullable();
});
}
@@ -26,6 +29,9 @@ return new class extends Migration
if (Schema::hasColumn('source')) {
$table->dropColumn('source')->nullable();
}
});
Schema::table('orders', function (Blueprint $table) {
if (! Schema::hasColumn('source_app')) {
$table->string('source_app')->nullable();
}

View File

@@ -26,7 +26,6 @@ use App\Http\Controllers\Api\V1\Profile\ProfileController;
use App\Http\Controllers\Api\V1\Province\ProvinceController;
use App\Http\Controllers\Api\V1\ReviewController;
use App\Modules\GlobalOrder\Controllers\GlobalOrderController;
use Dedoc\Scramble\Attributes\HeaderParameter;
use Illuminate\Support\Facades\Route;
// Auth...

View File

@@ -1,8 +1,8 @@
<?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Cart\CartItem;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\User;
beforeEach(function () {
$this->user = User::factory()->create([
@@ -50,7 +50,7 @@ test('authenticated user can store item in cart', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [
'product_id' => $product->id,
'product_quantity' => 2
'product_quantity' => 2,
]);
$response->assertStatus(201);
@@ -58,7 +58,7 @@ test('authenticated user can store item in cart', function () {
$this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id,
'product_id' => $product->id,
'product_quantity' => 2
'product_quantity' => 2,
]);
});
@@ -69,7 +69,7 @@ test('storing item updates quantity if already in cart', function () {
CartItem::create([
'user_id' => $this->user->id,
'product_id' => $product->id,
'product_quantity' => 1
'product_quantity' => 1,
]);
// Update quantity
@@ -77,7 +77,7 @@ test('storing item updates quantity if already in cart', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [
'product_id' => $product->id,
'product_quantity' => 5
'product_quantity' => 5,
]);
$response->assertStatus(201);
@@ -85,7 +85,7 @@ test('storing item updates quantity if already in cart', function () {
$this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id,
'product_id' => $product->id,
'product_quantity' => 5 // Should update to new quantity, not add
'product_quantity' => 5, // Should update to new quantity, not add
]);
});
@@ -94,7 +94,7 @@ test('cart validation fails if product does not exist', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [
'product_id' => 99999,
'product_quantity' => 1
'product_quantity' => 1,
]);
// Expecting validation error.
@@ -111,7 +111,7 @@ test('cart validation fails if quantity is invalid', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [
'product_id' => $product->id,
'product_quantity' => 0 // Min is 1
'product_quantity' => 0, // Min is 1
]);
$response->assertStatus(422)
@@ -125,7 +125,7 @@ test('cart validation fails if stock is insufficient', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [
'product_id' => $product->id,
'product_quantity' => 10
'product_quantity' => 10,
]);
$response->assertStatus(422)
@@ -153,8 +153,8 @@ test('authenticated user can list cart items', function () {
'product_id',
'product_quantity',
'product',
]
]
],
],
]);
});
@@ -175,7 +175,7 @@ test('index adjusts quantity if stock decreased', function () {
$this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id,
'product_id' => $product->id,
'product_quantity' => 5
'product_quantity' => 5,
]);
});
@@ -207,14 +207,14 @@ test('authenticated user can remove specific item from cart', function () {
$response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->patchJson('/api/v1/carts', [
'product_id' => $product->id
'product_id' => $product->id,
]);
$response->assertStatus(200);
$this->assertDatabaseMissing('cart_items', [
'user_id' => $this->user->id,
'product_id' => $product->id
'product_id' => $product->id,
]);
});

View File

@@ -31,6 +31,7 @@ function createCategory(array $attributes = []): Category
function createProduct(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -61,8 +62,8 @@ test('can list categories', function () {
'id',
'name',
'slug',
]
]
],
],
]);
$this->assertCount(3, $response->json('data'));
@@ -152,7 +153,7 @@ test('can show a specific category', function () {
'data' => [
'id' => $category->id,
'name' => 'Test Category',
]
],
]);
});
@@ -199,7 +200,7 @@ test('can list products for a category', function () {
'*' => [
'id',
'name',
]
],
],
]);

View File

@@ -30,6 +30,7 @@ function createCollection(array $attributes = []): Collection
function createProductForCollection(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -60,8 +61,8 @@ test('can list collections', function () {
'id',
'name',
'slug',
]
]
],
],
]);
$this->assertCount(3, $response->json('data'));
@@ -119,7 +120,7 @@ test('can show a specific collection', function () {
'data' => [
'id' => $collection->id,
'name' => 'Test Collection',
]
],
]);
});
@@ -166,7 +167,7 @@ test('can list products for a collection', function () {
'*' => [
'id',
'name',
]
],
],
]);

View File

@@ -1,8 +1,7 @@
<?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Favorite\Favorite;
use App\Models\User;
beforeEach(function () {
$this->user = User::factory()->create([
@@ -43,17 +42,17 @@ test('authenticated user can add item to favorites', function () {
$response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [
'product_id' => $product->id
'product_id' => $product->id,
]);
$response->assertStatus(200)
->assertJson([
'message' => 'Added'
'message' => 'Added',
]);
$this->assertDatabaseHas('favorites', [
'user_id' => $this->user->id,
'product_id' => $product->id
'product_id' => $product->id,
]);
});
@@ -62,24 +61,24 @@ test('authenticated user can remove item from favorites (toggle)', function () {
// Add first
$this->user->favorites()->create([
'product_id' => $product->id
'product_id' => $product->id,
]);
// Request to toggle (remove)
$response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [
'product_id' => $product->id
'product_id' => $product->id,
]);
$response->assertStatus(200)
->assertJson([
'message' => 'Removed'
'message' => 'Removed',
]);
$this->assertDatabaseMissing('favorites', [
'user_id' => $this->user->id,
'product_id' => $product->id
'product_id' => $product->id,
]);
});
@@ -87,7 +86,7 @@ test('favorite toggle validation fails if product does not exist', function () {
$response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [
'product_id' => 99999
'product_id' => 99999,
]);
$response->assertStatus(422)
@@ -116,8 +115,8 @@ test('authenticated user can view favorites list with items', function () {
'name',
'slug',
// Add other product fields as expected by ProductResource
]
]
]
],
],
],
]);
});

View File

@@ -32,6 +32,7 @@ function createFilterCategory(array $attributes = []): Category
function createFilterBrand(array $attributes = []): Brand
{
$name = $attributes['name'] ?? 'Test Brand '.Str::random(5);
return Brand::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -57,6 +58,7 @@ function createFilterCollection(array $attributes = []): Collection
function createFilterProduct(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -84,7 +86,7 @@ test('can get filters', function () {
'data' => [
'categories',
'brands',
]
],
]);
$this->assertCount(1, $response->json('data.categories'));

View File

@@ -1,7 +1,5 @@
<?php
use App\Models\CMS\Forms\ContactUS;
use App\Models\CMS\Marketing\NewsletterUser;
use App\Models\System\Settings\OS;
use App\Models\User;

View File

@@ -32,8 +32,8 @@ test('can list provinces', function () {
'id',
'name',
'region',
]
]
],
],
]);
$this->assertCount(2, $response->json('data'));
@@ -73,8 +73,8 @@ test('can list post branches', function () {
'name',
'address',
'description',
]
]
],
],
]);
$this->assertCount(2, $response->json('data'));

View File

@@ -42,8 +42,8 @@ test('can list order payment types', function () {
'*' => [
'id',
'name',
]
]
],
],
]);
$this->assertCount(2, $response->json('data'));

View File

@@ -31,7 +31,7 @@ beforeEach(function () {
// Mock default payment type for OrderPayment::default()
if (PaymentType::count() === 0) {
$paymentType = new PaymentType();
$paymentType = new PaymentType;
$paymentType->forceFill([
'id' => 1,
'code' => 'cash',
@@ -44,7 +44,7 @@ beforeEach(function () {
});
test('authenticated user can list their orders', function () {
$order = new Order();
$order = new Order;
$order->forceFill([
'user_id' => $this->user->id,
'number' => 'ORD-123',
@@ -71,8 +71,8 @@ test('authenticated user can list their orders', function () {
'id',
'number',
// Add other fields from OrderIndexResource
]
]
],
],
]);
});
@@ -186,7 +186,7 @@ test('order validation fails with invalid data', function () {
});
test('can show specific order', function () {
$order = new Order();
$order = new Order;
$order->forceFill([
'user_id' => $this->user->id,
'number' => 'ORD-SHOW',
@@ -215,7 +215,7 @@ test('can delete order (if allowed)', function () {
// Note: The controller destroy method is basically empty: return response()->rest();
// But the route exists. Let's test it returns 200 at least.
$order = new Order();
$order = new Order;
$order->forceFill([
'user_id' => $this->user->id,
'number' => 'ORD-DEL',

View File

@@ -16,6 +16,7 @@ beforeEach(function () {
function createProductForFilterTest(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -44,6 +45,7 @@ function createCategoryForFilterTest(array $attributes = []): Category
function createBrandForFilterTest(array $attributes = []): Brand
{
$name = $attributes['name'] ?? 'Test Brand '.Str::random(5);
return Brand::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),

View File

@@ -17,6 +17,7 @@ beforeEach(function () {
function createProductForReview(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -62,8 +63,8 @@ test('can list product reviews', function () {
'id',
'rating',
'content',
]
]
],
],
]);
$this->assertCount(2, $response->json('data'));

View File

@@ -14,6 +14,7 @@ beforeEach(function () {
function createProductForSearch(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -28,7 +29,7 @@ test('can search product by barcode', function () {
// Arrange
$product = createProductForSearch([
'name' => 'Barcode Product',
'barcode' => '1234567890123'
'barcode' => '1234567890123',
]);
// Act
@@ -44,7 +45,7 @@ test('can search product by barcode', function () {
'id' => $product->id,
'name' => 'Barcode Product',
'stock' => 10,
]
],
]);
});

View File

@@ -1,8 +1,8 @@
<?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\ProductView\ProductView;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
@@ -19,6 +19,7 @@ beforeEach(function () {
$this->createProduct = function (array $attributes = []) {
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -111,8 +112,8 @@ test('authenticated user can list viewed products', function () {
'name',
'slug',
'price_amount',
]
]
],
],
]);
$this->assertCount(2, $response->json('data'));

View File

@@ -15,6 +15,7 @@ beforeEach(function () {
function createProductForTest(array $attributes = []): Product
{
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([
'name' => $name,
'slug' => Str::slug($name),
@@ -61,8 +62,8 @@ test('can list products', function () {
'name',
'slug',
'price_amount',
]
]
],
],
]);
$this->assertCount(3, $response->json('data'));
@@ -150,7 +151,7 @@ test('can show a specific product', function () {
'data' => [
'id' => $product->id,
'name' => 'Test Product',
]
],
]);
});
@@ -190,7 +191,7 @@ test('can list related products', function () {
$category->products()->attach([
$mainProduct->id,
$relatedProduct1->id,
$relatedProduct2->id
$relatedProduct2->id,
]);
// Act
@@ -206,8 +207,8 @@ test('can list related products', function () {
'*' => [
'id',
'name',
]
]
],
],
]);
// Should contain related products but not the main product itself (usually)

View File

@@ -2,11 +2,10 @@
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Review\Review;
use App\Models\User;
use App\Models\System\Settings\OS;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
uses(RefreshDatabase::class);
@@ -53,9 +52,9 @@ test('authenticated user can view their reviews', function () {
'product' => [
'id',
'name',
]
]
]
],
],
],
]);
});