ProductResource::toArray()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 19
rs 9.4222
cc 5
nc 8
nop 1
1
<?php
2
3
namespace Ronmrcdo\Inventory\Resources;
4
5
use Ronmrcdo\Inventory\Resources\AttributeResource;
6
use Ronmrcdo\Inventory\Resources\VariantResource;
7
use Illuminate\Http\Resources\Json\JsonResource;
8
9
class ProductResource extends JsonResource
10
{
11
    /**
12
     * Transform the resource into an array.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @return array
16
     */
17
    public function toArray($request)
18
    {
19
        return [
20
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
21
			'name' => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
            'slug' => $this->slug,
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
            'sku' => $this->hasSku() ? $this->skus()->first()->code : null,
0 ignored issues
show
Bug introduced by
The method hasSku() does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            'sku' => $this->/** @scrutinizer ignore-call */ hasSku() ? $this->skus()->first()->code : null,
Loading history...
Bug introduced by
The method skus() does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            'sku' => $this->hasSku() ? $this->/** @scrutinizer ignore-call */ skus()->first()->code : null,
Loading history...
24
			'short_description' => $this->short_description,
0 ignored issues
show
Bug Best Practice introduced by
The property short_description does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
            'description' => $this->description,
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
26
            'price' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00,
27
            'cost' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00,
28
            'is_active' => $this->is_active,
0 ignored issues
show
Bug Best Practice introduced by
The property is_active does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'category' => [
30
                'id' => $this->category->id,
0 ignored issues
show
Bug Best Practice introduced by
The property category does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
                'name' => $this->category->name
32
            ],
33
            'attributes' => AttributeResource::collection($this->attributes)->toArray(app('request')),
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'variations' => $this->when($this->hasAttributes() && $this->hasSku(), 
0 ignored issues
show
Bug introduced by
The method hasAttributes() does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            'variations' => $this->when($this->/** @scrutinizer ignore-call */ hasAttributes() && $this->hasSku(), 
Loading history...
35
                VariantResource::collection($this->skus)->toArray(app('request'))
0 ignored issues
show
Bug Best Practice introduced by
The property skus does not exist on Ronmrcdo\Inventory\Resources\ProductResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            )
37
        ];
38
    }
39
}