VariantResource   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 18
c 2
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 21 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
}