Skip to content

Commit a8f2a30

Browse files
authored
Merge pull request #3 from mohammadv184/analysis-L34AGP
Apply fixes from StyleCI
2 parents 30c1903 + fb8a9b5 commit a8f2a30

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

Database/Migrations/0000_00_00_000000_create_Cart_Items_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public function up()
1616
Schema::create('cart_items', function (Blueprint $table) {
1717
$table->id();
1818
$table->string('rowId');
19-
$table->unsignedBigInteger("user_id");
20-
$table->foreign("user_id")->references("id")->on("users")->onDelete("cascade")->onUpdate("cascade");
19+
$table->unsignedBigInteger('user_id');
20+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
2121
$table->unsignedBigInteger('price');
2222
$table->integer('quantity');
2323
$table->integer('cartable_id');

src/CartService.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ public function __construct($instanceName, $storage)
3535
$this->instanceName = $instanceName;
3636
$this->storage = $storage;
3737
$this->cart = $this->storage instanceof Model
38-
? $this->storage->all()->where("user_id", \Auth::user()->id)->mapWithKeys(function ($item) {
39-
38+
? $this->storage->all()->where('user_id', \Auth::user()->id)->mapWithKeys(function ($item) {
4039
return [$item['rowId'] => [
41-
'id' => $item['rowId'],
42-
'price' => $item['price'],
43-
'quantity' => $item['quantity'],
44-
'cartable_id' => $item['cartable_id'],
40+
'id' => $item['rowId'],
41+
'price' => $item['price'],
42+
'quantity' => $item['quantity'],
43+
'cartable_id' => $item['cartable_id'],
4544
'cartable_type' => $item['cartable_type'],
4645
]];
4746
})
@@ -125,7 +124,8 @@ public function has($key): bool
125124
}
126125

127126
/**
128-
* check if exists session
127+
* check if exists session.
128+
*
129129
* @return bool
130130
*/
131131
public function hasSession()
@@ -136,7 +136,8 @@ public function hasSession()
136136
}
137137

138138
/**
139-
* Move session to database
139+
* Move session to database.
140+
*
140141
* @return $this
141142
*/
142143
public function moveSessionToDatabase()
@@ -145,13 +146,13 @@ public function moveSessionToDatabase()
145146
$session = \Session::get($this->instanceName);
146147
\Session::forget($this->instanceName);
147148
$session->each(function ($item) {
148-
$cart=$this->cart->where("cartable_id", $item["cartable_id"])->where("cartable_type", $item["cartable_type"])->first();
149+
$cart = $this->cart->where('cartable_id', $item['cartable_id'])->where('cartable_type', $item['cartable_type'])->first();
149150
if (!is_null($cart)) {
150-
$item["id"]=$cart["id"];
151-
$item["quantity"]+=$cart["quantity"];
152-
$item["price"]=$cart["price"];
151+
$item['id'] = $cart['id'];
152+
$item['quantity'] += $cart['quantity'];
153+
$item['price'] = $cart['price'];
153154
}
154-
$this->cart->put($item["id"], $item);
155+
$this->cart->put($item['id'], $item);
155156
});
156157
$this->save();
157158
}
@@ -174,7 +175,7 @@ public function delete($key): CartService
174175
}
175176
$this->cart->forget($item['id']);
176177
if ($this->storage instanceof Model) {
177-
$this->storage->where("id", \Auth::user()->id)->firstWhere('rowId', $key)->delete();
178+
$this->storage->where('id', \Auth::user()->id)->firstWhere('rowId', $key)->delete();
178179
} else {
179180
$this->save();
180181
}
@@ -191,7 +192,7 @@ public function flush(): CartService
191192
{
192193
$this->cart = collect([]);
193194
if ($this->storage instanceof Model) {
194-
$this->storage->where("id", \Auth::user()->id)->delete();
195+
$this->storage->where('id', \Auth::user()->id)->delete();
195196
} else {
196197
$this->save();
197198
}

0 commit comments

Comments
 (0)