VariantResource::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 21
rs 9.7
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Ronmrcdo\Inventory\Resources;
4
5
use Illuminate\Http\Resources\Json\JsonResource;
6
7
class VariantResource extends JsonResource
8
{
9
	public function toArray($request)
10
	{
11
		return [
12
			'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
13
			'parent_product_id' => $this->product_id,
0 ignored issues
show
Bug Best Practice introduced by
The property product_id does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
14
			'sku' => $this->code,
0 ignored issues
show
Bug Best Practice introduced by
The property code does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
15
			'name' => $this->product->name,
0 ignored issues
show
Bug Best Practice introduced by
The property product does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
16
			'short_description' => $this->product->short_description,
17
			'description' => $this->product->description,
18
			'price' => number_format($this->price, 2, '.', ''),
0 ignored issues
show
Bug Best Practice introduced by
The property price does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
			'cost' => number_format($this->cost, 2, '.', ''),
0 ignored issues
show
Bug Best Practice introduced by
The property cost does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
20
			'category' => [
21
				'id' => $this->product->category_id,
22
				'name' => $this->product->category->name
23
			],
24
			'attributes' => collect($this->variant)->map(function ($item) {
0 ignored issues
show
Bug Best Practice introduced by
The property variant does not exist on Ronmrcdo\Inventory\Resources\VariantResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
				return [
26
					'name' => $item->attribute->name,
27
					'option' => $item->option->value
28
				];
29
			})->values()->toArray()
30
		];
31
	}
32
}