AsCheckoutProduct::toCheckoutProduct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace QuickCheckout\Eloquent;
4
5
use QuickCheckout\CartProduct;
6
use QuickCheckout\Contracts\ProductInterface;
7
use QuickCheckout\Product;
8
9
trait AsCheckoutProduct
10
{
11 5
    public function checkoutProductTitle(): string
12
    {
13 5
        return (string) $this->title;
14
    }
15
16 5
    public function checkoutProductPrice(): int
17
    {
18 5
        return (int) $this->price;
19
    }
20
21 5
    public function checkoutProductMeta(): array
22
    {
23 5
        return array_merge(CartProduct::getModelDataAsEntity($this), $this->checkoutProductGeneralMeta());
0 ignored issues
show
Bug introduced by
$this of type QuickCheckout\Eloquent\AsCheckoutProduct is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of QuickCheckout\CartProduct::getModelDataAsEntity(). ( Ignorable by Annotation )

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

23
        return array_merge(CartProduct::getModelDataAsEntity(/** @scrutinizer ignore-type */ $this), $this->checkoutProductGeneralMeta());
Loading history...
24
    }
25
26 4
    public function checkoutProductGeneralMeta(): array
27
    {
28 4
        return [];
29
    }
30
31 5
    public function checkoutProductClass(): string
32
    {
33 5
        return Product::class;
34
    }
35
36 5
    public function toCheckoutProduct(array $meta = []): ProductInterface
37
    {
38 5
        $class = $this->checkoutProductClass();
39
40 5
        return new $class(
41 5
            $this->checkoutProductTitle(),
42 5
            $this->checkoutProductPrice(),
43 5
            array_merge($this->checkoutProductMeta(), $meta),
44
        );
45
    }
46
}
47