From cff1a9b1f340d234fcfabed485bc556213b02ff4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 19 Apr 2017 12:51:40 +0000 Subject: [PATCH] Apply fixes from StyleCI --- app/Cart/CartCollection.php | 2 +- app/Cart/Item.php | 10 +++++----- app/Cart/TransactionDraft.php | 1 + app/Helpers/helpers.php | 11 +++++++---- app/Http/Controllers/CartController.php | 2 +- app/Providers/AppServiceProvider.php | 2 +- resources/lang/id/cart.php | 4 ++-- resources/lang/id/transaction.php | 10 +++++----- tests/Feature/TransactionEntryTest.php | 14 +++++++------- 9 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/Cart/CartCollection.php b/app/Cart/CartCollection.php index 2723606..304367f 100644 --- a/app/Cart/CartCollection.php +++ b/app/Cart/CartCollection.php @@ -122,7 +122,7 @@ class CartCollection { $item = $draft->search($product); - return ! is_null($item); + return !is_null($item); } public function updateDraftItem($draftKey, $itemKey, $newItemData) diff --git a/app/Cart/Item.php b/app/Cart/Item.php index 8481563..fdfb5d7 100644 --- a/app/Cart/Item.php +++ b/app/Cart/Item.php @@ -20,11 +20,11 @@ class Item public function __construct(Product $product, $qty) { - $this->id = $product->id; - $this->name = $product->name; - $this->product = $product; - $this->qty = $qty; - $this->price = $product->getPrice(); + $this->id = $product->id; + $this->name = $product->name; + $this->product = $product; + $this->qty = $qty; + $this->price = $product->getPrice(); $this->subtotal = $product->getPrice() * $qty; } diff --git a/app/Cart/TransactionDraft.php b/app/Cart/TransactionDraft.php index 582676c..0f8d055 100644 --- a/app/Cart/TransactionDraft.php +++ b/app/Cart/TransactionDraft.php @@ -79,6 +79,7 @@ abstract class TransactionDraft public function search(Product $product) { $productItem = $this->items()->where('id', $product->id)->first(); + return $productItem; } } diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 7c1abc3..b2e0dd5 100755 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -2,11 +2,14 @@ function formatNo($number) { - return number_format($number, 0,',','.'); + return number_format($number, 0, ',', '.'); } function formatRp($number) { - if ($number == 0) { return '-'; } - return 'Rp. ' . formatNo($number); -} \ No newline at end of file + if ($number == 0) { + return '-'; + } + + return 'Rp. '.formatNo($number); +} diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index b363235..4ff1d00 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -23,7 +23,7 @@ class CartController extends Controller $queriedProducts = []; $draft = $this->cart->content()->first(); - return view('cart.index', compact('draft','queriedProducts')); + return view('cart.index', compact('draft', 'queriedProducts')); } public function show(Request $request, $draftKey) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ddaae42..9d001f6 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - require_once app_path() . '/Helpers/helpers.php'; + require_once app_path().'/Helpers/helpers.php'; } /** diff --git a/resources/lang/id/cart.php b/resources/lang/id/cart.php index e1162ea..b253138 100644 --- a/resources/lang/id/cart.php +++ b/resources/lang/id/cart.php @@ -2,5 +2,5 @@ return [ // Labels - 'product_search' => 'Cari Produk' -]; \ No newline at end of file + 'product_search' => 'Cari Produk', +]; diff --git a/resources/lang/id/transaction.php b/resources/lang/id/transaction.php index dce4d33..9ba666b 100644 --- a/resources/lang/id/transaction.php +++ b/resources/lang/id/transaction.php @@ -2,9 +2,9 @@ return [ // Labels - 'create' => 'Buat Transaksi', - 'create_cash' => 'Buat Transaksi Tunai', + 'create' => 'Buat Transaksi', + 'create_cash' => 'Buat Transaksi Tunai', 'create_credit' => 'Buat Transaksi Kredit', - 'cash' => 'Tunai', - 'credit' => 'Kredit', -]; \ No newline at end of file + 'cash' => 'Tunai', + 'credit' => 'Kredit', +]; diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index ee8178e..23aa487 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -68,15 +68,15 @@ class TransactionEntryTest extends BrowserKitTestCase $this->see($product->name); $this->see($product->credit_price); $this->seeElement('form', ['action' => route('cart.add-draft-item', [$draft->draftKey, $product->id])]); - $this->seeElement('input', ['id' => 'qty-' . $product->id, 'name' => 'qty']); - $this->seeElement('input', ['id' => 'add-product-' . $product->id]); + $this->seeElement('input', ['id' => 'qty-'.$product->id, 'name' => 'qty']); + $this->seeElement('input', ['id' => 'add-product-'.$product->id]); $this->dontSee($product->cash_price); } /** @test */ public function user_can_add_item_to_draft() { - $product = factory(Product::class)->create(['name' => 'Testing Produk 1','cash_price' => 400,'credit_price' => 500]); + $product = factory(Product::class)->create(['name' => 'Testing Produk 1', 'cash_price' => 400, 'credit_price' => 500]); $this->loginAsUser(); $cart = new CartCollection(); @@ -87,14 +87,14 @@ class TransactionEntryTest extends BrowserKitTestCase $this->visit(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->type(2, 'qty'); - $this->press('add-product-' . $product->id); + $this->press('add-product-'.$product->id); $this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->assertTrue($cart->draftHasItem($draft, $product)); $this->assertEquals(800, $draft->getTotal()); $this->see(formatRp(800)); - $this->seeElement('input', ['id' => 'qty-' . 0]); - $this->seeElement('input', ['id' => 'item_discount-' . 0]); - $this->seeElement('button', ['id' => 'remove-item-' . 0]); + $this->seeElement('input', ['id' => 'qty-'. 0]); + $this->seeElement('input', ['id' => 'item_discount-'. 0]); + $this->seeElement('button', ['id' => 'remove-item-'. 0]); } }