Completed
Push — development ( 2fad51...a387f8 )
by Claudio
02:44
created

ShopInventory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 77
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setCountry() 0 4 1
A setPaymentCategories() 0 9 2
A setPricePoints() 0 4 1
1
<?php
2
3
namespace App\Models;
4
5
/**
6
 * Class ShopInventory
7
 * @package App\Models
8
 */
9
class ShopInventory
10
{
11
    /**
12
     * Payment Categories of the Country
13
     *
14
     * @var PaymentCategory[]
15
     */
16
    public $paymentCategories = [];
17
18
    /**
19
     * Inventory Items
20
     *
21
     * @var array
22
     */
23
    public $pricePoints = [];
24
25
    /**
26
     * If double Credits are Enabled
27
     *
28
     * @var bool
29
     */
30
    public $doubleCredits = false;
31
32
    /**
33
     * Country Meta Data
34
     *
35
     * @var Country
36
     */
37
    public $country = null;
38
39
    /**
40
     * Create a Shop Inventory
41
     *
42
     * @param Country $country
43
     */
44
    public function __construct(Country $country)
45
    {
46
        $this->setCountry($country);
47
        $this->setPaymentCategories($country->countryCode);
48
        $this->setPricePoints($country->countryCode);
49
    }
50
51
    /**
52
     * Set the Country Metadata
53
     *
54
     * @param Country $country
55
     */
56
    public function setCountry(Country $country)
57
    {
58
        $this->country = $country;
59
    }
60
61
    /**
62
     * Set the Payment Methods
63
     *
64
     * @param string $countryCode
65
     */
66
    public function setPaymentCategories(string $countryCode)
67
    {
68
        $paymentMethods = [];
69
70
        foreach (PaymentCategory::where('country_code', $countryCode)->get(['payment_type']) as $paymentMethod)
71
            $paymentMethods[] = $paymentMethod->payment_type;
72
73
        $this->paymentCategories = $paymentMethods;
74
    }
75
76
    /**
77
     * Get All Shop Items from this Country Code
78
     *
79
     * @param string $countryCode
80
     */
81
    public function setPricePoints(string $countryCode)
82
    {
83
        $this->pricePoints = ShopItem::where('countryCode', $countryCode)->get();
84
    }
85
}
86