Browse Source

Merge pull request #1 from nafiesl/analysis-XpW69a

Apply fixes from StyleCI
pull/2/head
Nafies Luthfi 9 years ago
committed by GitHub
parent
commit
a51164c95d
  1. 10
      app/Cart/CartCollection.php
  2. 2
      app/Cart/CashDraft.php
  3. 2
      app/Cart/CreditDraft.php
  4. 2
      app/Cart/Item.php
  5. 9
      app/Cart/TransactionDraft.php
  6. 1
      app/Console/Kernel.php
  7. 3
      app/Exceptions/Handler.php
  8. 6
      app/Http/Controllers/Auth/RegisterController.php
  9. 16
      app/Http/Controllers/CartController.php
  10. 4
      app/Http/Controllers/Controller.php
  11. 2
      app/Http/Controllers/HomeController.php
  12. 1
      app/Http/Middleware/RedirectIfAuthenticated.php
  13. 3
      app/Product.php
  14. 1
      app/Providers/AuthServiceProvider.php
  15. 2
      app/Providers/BroadcastServiceProvider.php
  16. 2
      app/Providers/EventServiceProvider.php
  17. 2
      app/Providers/RouteServiceProvider.php
  18. 2
      app/User.php
  19. 4
      database/factories/ModelFactory.php
  20. 4
      database/migrations/2014_10_12_000000_create_users_table.php
  21. 4
      database/migrations/2017_04_09_013901_create_products_table.php
  22. 3
      public/index.php
  23. 4
      server.php
  24. 32
      tests/Feature/Cart/CartControllerTest.php
  25. 12
      tests/Feature/TransactionEntryTest.php
  26. 53
      tests/Unit/CartCollectionTest.php
  27. 2
      tests/Unit/Integration/ProductTest.php

10
app/Cart/CartCollection.php

@ -2,11 +2,10 @@
namespace App\Cart;
use App\Product;
use Illuminate\Support\Collection;
/**
* Cart Collection Class
* Cart Collection Class.
*/
class CartCollection
{
@ -47,10 +46,9 @@ class CartCollection
public function get($draftKey)
{
$content = $this->getContent();
if (isset($content[$draftKey]))
if (isset($content[$draftKey])) {
return $content[$draftKey];
return null;
}
}
public function updateDraftAttributes($draftKey, $draftAttributes)
@ -112,6 +110,7 @@ class CartCollection
$content[$draftKey]->addItem($item);
$this->session->put($this->instance, $content);
return $item->product;
}
@ -145,5 +144,4 @@ class CartCollection
{
return !$this->isEmpty();
}
}

2
app/Cart/CashDraft.php

@ -3,7 +3,7 @@
namespace App\Cart;
/**
* Cash Draft
* Cash Draft.
*/
class CashDraft extends TransactionDraft
{

2
app/Cart/CreditDraft.php

@ -3,7 +3,7 @@
namespace App\Cart;
/**
* Credit Draft
* Credit Draft.
*/
class CreditDraft extends TransactionDraft
{

2
app/Cart/Item.php

@ -5,7 +5,7 @@ namespace App\Cart;
use App\Product;
/**
* Draft Item class
* Draft Item class.
*/
class Item
{

9
app/Cart/TransactionDraft.php

@ -2,10 +2,8 @@
namespace App\Cart;
use App\Product;
/**
* Transaction Draft Interface
* Transaction Draft Interface.
*/
abstract class TransactionDraft
{
@ -65,8 +63,9 @@ abstract class TransactionDraft
public function updateItem($itemKey, $newItemData)
{
if (!isset($this->items[$itemKey]))
return null;
if (!isset($this->items[$itemKey])) {
return;
}
$item = $this->items[$itemKey];

1
app/Console/Kernel.php

@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule)

3
app/Exceptions/Handler.php

@ -28,6 +28,7 @@ class Handler extends ExceptionHandler
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
*
* @return void
*/
public function report(Exception $exception)
@ -40,6 +41,7 @@ class Handler extends ExceptionHandler
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
@ -52,6 +54,7 @@ class Handler extends ExceptionHandler
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
*
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)

6
app/Http/Controllers/Auth/RegisterController.php

@ -2,10 +2,10 @@
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
@ -43,6 +43,7 @@ class RegisterController extends Controller
* Get a validator for an incoming registration request.
*
* @param array $data
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
@ -58,6 +59,7 @@ class RegisterController extends Controller
* Create a new user instance after a valid registration.
*
* @param array $data
*
* @return User
*/
protected function create(array $data)

16
app/Http/Controllers/CartController.php

@ -15,7 +15,7 @@ class CartController extends Controller
public function __construct()
{
$this->cart = new CartCollection;
$this->cart = new CartCollection();
}
public function index(Request $request)
@ -38,10 +38,11 @@ class CartController extends Controller
public function add(Request $request)
{
if ($request->has('create-cash-draft'))
$this->cart->add(new CashDraft);
else
$this->cart->add(new CreditDraft);
if ($request->has('create-cash-draft')) {
$this->cart->add(new CashDraft());
} else {
$this->cart->add(new CreditDraft());
}
return redirect()->route('cart.show', $this->cart->content()->last()->draftKey);
}
@ -57,30 +58,35 @@ class CartController extends Controller
public function updateDraftItem(Request $request, $draftKey)
{
$this->cart->updateDraftItem($draftKey, $request->item_key, $request->only('qty', 'item_discount'));
return redirect()->route('cart.index', $draftKey);
}
public function removeDraftItem(Request $request, $draftKey)
{
$this->cart->removeItemFromDraft($draftKey, $request->item_index);
return redirect()->route('cart.index', $draftKey);
}
public function empty($draftKey)
{
$this->cart->emptyDraft($draftKey);
return redirect()->route('cart.index', $draftKey);
}
public function remove(Request $request)
{
$this->cart->removeDraft($request->draft_key);
return redirect()->route('cart.index');
}
public function destroy()
{
$this->cart->destroy();
return redirect()->route('cart.index');
}
}

4
app/Http/Controllers/Controller.php

@ -2,10 +2,10 @@
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{

2
app/Http/Controllers/HomeController.php

@ -2,8 +2,6 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**

1
app/Http/Middleware/RedirectIfAuthenticated.php

@ -13,6 +13,7 @@ class RedirectIfAuthenticated
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)

3
app/Product.php

@ -10,8 +10,9 @@ class Product extends Model
public function getPrice($type = 'cash')
{
if ($type == 'credit')
if ($type == 'credit') {
return $this->credit_price;
}
return $this->cash_price;
}

1
app/Providers/AuthServiceProvider.php

@ -2,7 +2,6 @@
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider

2
app/Providers/BroadcastServiceProvider.php

@ -2,8 +2,8 @@
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{

2
app/Providers/EventServiceProvider.php

@ -2,8 +2,8 @@
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{

2
app/Providers/RouteServiceProvider.php

@ -2,8 +2,8 @@
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{

2
app/User.php

@ -2,8 +2,8 @@
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{

4
database/factories/ModelFactory.php

@ -13,7 +13,6 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'username' => $faker->unique()->username,
@ -22,9 +21,8 @@ $factory->define(App\User::class, function (Faker\Generator $faker) {
];
});
/** @var \Illuminate\Database\Eloquent\Factory $factory */
/* @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\Product::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'cash_price' => 2000,

4
database/migrations/2014_10_12_000000_create_users_table.php

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{

4
database/migrations/2017_04_09_013901_create_products_table.php

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductsTable extends Migration
{

3
public/index.php

@ -1,9 +1,8 @@
<?php
/**
* Laravel - A PHP Framework For Web Artisans
* Laravel - A PHP Framework For Web Artisans.
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/

4
server.php

@ -1,12 +1,10 @@
<?php
/**
* Laravel - A PHP Framework For Web Artisans
* Laravel - A PHP Framework For Web Artisans.
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

32
tests/Feature/Cart/CartControllerTest.php

@ -19,7 +19,7 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cart = new CartCollection();
$response = $this->post(route('cart.add'), ['create-cash-draft'=> trans('transaction.create')]);
$response = $this->post(route('cart.add'), ['create-credit-draft'=> trans('transaction.create_credit')]);
@ -37,8 +37,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$draft = new CashDraft;
$cart = new CartCollection();
$draft = new CashDraft();
$cart->add($draft);
// Add Product to database
@ -47,7 +47,7 @@ class CartControllerTest extends TestCase
// Add Product as CashDraft item
$response = $this->post(route('cart.add-draft-item', [$draft->draftKey, $product->id]), [
'qty' => $itemQty
'qty' => $itemQty,
]);
$cashDraft = $cart->content()->first();
@ -60,8 +60,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cashDraft = new CashDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$product = factory(Product::class)->create(['cash_price' => 1100], ['credit_price' => 1000]);
$item = new Item($product, 2);
@ -73,7 +73,7 @@ class CartControllerTest extends TestCase
// Remove Item Product from CashDraft
$response = $this->delete(route('cart.remove-draft-item', [$cashDraft->draftKey]), [
'item_index' => 0
'item_index' => 0,
]);
$this->assertEquals(0, $cashDraft->getTotalQty());
@ -86,8 +86,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cashDraft = new CashDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$cart->add($cashDraft);
$this->assertFalse($cart->isEmpty());
@ -95,7 +95,7 @@ class CartControllerTest extends TestCase
// Remove a transaction draft
$response = $this->delete(route('cart.remove'), [
'draft_key' => $cashDraft->draftKey
'draft_key' => $cashDraft->draftKey,
]);
$this->assertTrue($cart->isEmpty());
@ -106,8 +106,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cashDraft = new CashDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$cart->add($cashDraft);
$cart->add($cashDraft);
@ -125,8 +125,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cashDraft = new CashDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$product = factory(Product::class)->create(['cash_price' => 1100], ['credit_price' => 1000]);
$item = new Item($product, 2);
@ -149,8 +149,8 @@ class CartControllerTest extends TestCase
{
$this->loginAsUser();
$cart = new CartCollection;
$cashDraft = new CashDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$product = factory(Product::class)->create(['cash_price' => 1100], ['credit_price' => 1000]);
$item = new Item($product, 2);

12
tests/Feature/TransactionEntryTest.php

@ -19,8 +19,8 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->loginAsUser();
// Add new draft to collection
$cart = new CartCollection;
$draft = $cart->add(new CashDraft);
$cart = new CartCollection();
$draft = $cart->add(new CashDraft());
$this->visit(route('cart.index'));
@ -35,12 +35,12 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->visit(route('home'));
$this->press(trans('transaction.create'));
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->content()->last();
$this->seePageIs(route('cart.show', $draft->draftKey));
$this->press(trans('transaction.create_credit'));
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->content()->last();
$this->seePageIs(route('cart.show', $draft->draftKey));
}
@ -51,8 +51,8 @@ class TransactionEntryTest extends BrowserKitTestCase
$product = factory(Product::class)->create(['name' => 'Testing Produk 1']);
$this->loginAsUser();
$cart = new CartCollection;
$draft = new CreditDraft;
$cart = new CartCollection();
$draft = new CreditDraft();
$cart->add($draft);
// Visit cart index page

53
tests/Unit/CartCollectionTest.php

@ -14,17 +14,17 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_has_a_default_instance()
{
$cart = new CartCollection;
$cart = new CartCollection();
$this->assertEquals('drafts', $cart->currentInstance());
}
/** @test */
public function it_can_have_multiple_instances()
{
$cart = new CartCollection;
$cart = new CartCollection();
$cashDraft = new CashDraft;
$creditDraft = new CreditDraft;
$cashDraft = new CashDraft();
$creditDraft = new CreditDraft();
$cart->add($cashDraft);
$cart->add($creditDraft);
@ -39,9 +39,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function cart_collection_consist_of_transacion_draft()
{
$cart = new CartCollection;
$cashDraft = new CashDraft;
$creditDraft = new CreditDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$creditDraft = new CreditDraft();
$cart->add($cashDraft);
$cart->add($creditDraft);
@ -53,8 +53,8 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_get_a_draft_by_key()
{
$draft = new CashDraft;
$cart = new CartCollection;
$draft = new CashDraft();
$cart = new CartCollection();
$cart->add($draft);
$gottenDraft = $cart->get($draft->draftKey);
@ -67,9 +67,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_remove_draft_from_draft_collection()
{
$cart = new CartCollection;
$cashDraft = new CashDraft;
$creditDraft = new CreditDraft;
$cart = new CartCollection();
$cashDraft = new CashDraft();
$creditDraft = new CreditDraft();
$cart->add($cashDraft);
$cart->add($creditDraft);
@ -82,10 +82,10 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_be_empty_out()
{
$cart = new CartCollection;
$cart = new CartCollection();
$cashDraft = new CashDraft;
$creditDraft = new CreditDraft;
$cashDraft = new CashDraft();
$creditDraft = new CreditDraft();
$cart->add($cashDraft);
$cart->add($cashDraft);
@ -103,10 +103,10 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_has_content_keys()
{
$cart = new CartCollection;
$cart = new CartCollection();
$cashDraft = new CashDraft;
$creditDraft = new CreditDraft;
$cashDraft = new CashDraft();
$creditDraft = new CreditDraft();
$cart->add($cashDraft);
$cart->add($creditDraft);
@ -119,9 +119,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_update_a_draft_attributes()
{
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->add(new CashDraft);
$draft = $cart->add(new CashDraft());
$this->assertCount(1, $cart->content());
$newDraftAttribute = [
@ -151,9 +151,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_add_product_to_draft()
{
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->add(new CashDraft);
$draft = $cart->add(new CashDraft());
$count = 2;
$item = new Item(new Product(['cash_price' => 1000]), $count);
@ -164,9 +164,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_remove_item_from_draft()
{
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->add(new CashDraft);
$draft = $cart->add(new CashDraft());
$item = new Item(new Product(['cash_price' => 1000]), 3);
$cart->addItemToDraft($draft->draftKey, $item);
@ -179,9 +179,9 @@ class CartCollectionTest extends TestCase
/** @test */
public function it_can_update_an_item_of_draft()
{
$cart = new CartCollection;
$cart = new CartCollection();
$draft = $cart->add(new CashDraft);
$draft = $cart->add(new CashDraft());
$item = new Item(new Product(['cash_price' => 1100]), 3);
$cart->addItemToDraft($draft->draftKey, $item);
@ -196,5 +196,4 @@ class CartCollectionTest extends TestCase
$cart->updateDraftItem($draft->draftKey, 0, $newItemData);
$this->assertEquals(2000, $draft->getTotal());
}
}

2
tests/Unit/Integration/ProductTest.php

@ -3,8 +3,6 @@
namespace Tests\Unit\Integration;
use App\Product;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ProductTest extends TestCase

Loading…
Cancel
Save