Completed
Push — master ( d6e5bd...91fdab )
by Sander
13:05
created

src/Kunstmaan/SeoBundle/Helper/Order.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\SeoBundle\Helper;
4
5
6
/**
7
 * Simple helper class to do E-Commerce Tracking.
8
 * Create one of these objects and pass it along to the google_analytics_ecommerce_tracking Twig function.
9
 * It'll create the correct calls to the GA script for you.
10
 *
11
 * API: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce?hl=nl
12
 *
13
 * Class Order
14
 *
15
 * @package Kunstmaan\SeoBundle\Helper
16
 */
17
class Order
18
{
19
20
    /**
21
     * @var string REQUIRED! The unique identifier for this Order/Transaction.
22
     */
23
    protected $transactionID;
24
25
    /**
26
     * @param $id number The ID.
27
     *
28
     * @return $this
29
     */
30
    public function setTransactionID($id)
31
    {
32
        $this->transactionID = $id;
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getTransactionID()
41
    {
42
        return $this->transactionID;
43
    }
44
45
    /**
46
     * @var string The name of the store that handled the Order/Transaction.
47
     */
48
    protected $storeName = '';
49
50
    /**
51
     * @param $name string The name of the store.
52
     *
53
     * @return $this
54
     */
55
    public function setStoreName($name)
56
    {
57
        $this->storeName = $name;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getStoreName()
66
    {
67
        return $this->storeName;
68
    }
69
70
    /**
71
     * REQUIREd!
72
     * @return string The total. Calculated automatically and returned as string.
0 ignored issues
show
Should the return type not be string|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
73
     */
74
    public function getTotal()
75
    {
76
        return $this->accumulatePropertyOnOrderItems('getValue');
77
    }
78
79
    /**
80
     *
81
     * @return int|string
82
     */
83
    public function getTaxesTotal()
84
    {
85
        return $this->accumulatePropertyOnOrderItems('getTaxes');
86
    }
87
88
    protected $shippingTotal = '';
89
90
    /**
91
     * @param $total string|number
92
     *
93
     * @return $this
94
     */
95
    public function setShippingTotal($total)
96
    {
97
        $this->shippingTotal = (Double)$total;
0 ignored issues
show
Documentation Bug introduced by
The property $shippingTotal was declared of type string, but (double) $total is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getShippingTotal()
106
    {
107
        return $this->shippingTotal;
108
    }
109
110
    /**
111
     * @var array(of OrderItem) An array of OrderItem objects.
112
     */
113
    public $orderItems = array();
114
115
    /**
116
     * @var string City the order was shipped to.
117
     */
118
    protected $city = '';
119
120
    /**
121
     * @param $city string
122
     *
123
     * @return $this
124
     */
125
    public function setCity($city)
126
    {
127
        $this->city = $city;
128
129
        return $this;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getCity()
136
    {
137
        return $this->city;
138
    }
139
140
    /**
141
     * @var string State or province the order was shipped to.
142
     */
143
    protected $stateOrProvince = '';
144
145
    /**
146
     * @param $stateOrProvince string
147
     *
148
     * @return $this
149
     */
150
    public function setStateOrProvince($stateOrProvince)
151
    {
152
        $this->stateOrProvince = $stateOrProvince;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return string
159
     */
160
   public function getStateOrProvince()
161
   {
162
        return $this->stateOrProvince;
163
   }
164
165
    /**
166
     * @var string Country the order was shipped to.
167
     */
168
    protected $country = '';
169
170
    /**
171
     * @param $country string
172
     *
173
     * @return $this
174
     */
175
    public function setCountry($country)
176
    {
177
        $this->country = $country;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getCountry()
186
    {
187
        return $this->country;
188
    }
189
190
191
    /**
192
     * Loops over the OrderItems and accumulates the value of the given property. Can also be a getter.
193
     *
194
     * @param $property
195
     * @return int|string
196
     */
197
    private function accumulatePropertyOnOrderItems($property)
198
    {
199
        if (count($this->orderItems) == 0) {
200
            return '';
201
        }
202
203
        $total = 0;
204
        foreach ($this->orderItems as $orderItem) {
205
            $total += $orderItem->$property();
206
        }
207
208
        return $total;
209
    }
210
}
211