Test Setup Failed
Push — development ( 057645...ac5058 )
by Ashutosh
15:58
created

CronController::getUsers()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
nc 32
nop 0
dl 21
loc 21
rs 8.9617
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Common;
4
5
use App\Model\Common\Template;
6
use App\Model\Order\Invoice;
7
use App\Model\Order\Order;
8
use App\Model\Product\Subscription;
9
use App\User;
10
use Carbon\Carbon;
11
12
class CronController extends BaseCronController
13
{
14
    protected $subscription;
15
    protected $order;
16
    protected $user;
17
    protected $template;
18
    protected $invoice;
19
20
    public function __construct()
21
    {
22
        $subscription = new Subscription();
23
        $this->sub = $subscription;
0 ignored issues
show
Bug introduced by
The property sub does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
25
        $order = new Order();
26
        $this->order = $order;
27
28
        $user = new User();
29
        $this->user = $user;
30
31
        $template = new Template();
32
        $this->template = $template;
33
34
        $invoice = new Invoice();
35
        $this->invoice = $invoice;
36
    }
37
38
    public function getExpiredInfoByOrderId($orderid)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
39
    {
40
        $yesterday = new Carbon('today');
41
        $sub = $this->sub
42
                ->where('order_id', $orderid)
43
                ->where('ends_at', '!=', '0000-00-00 00:00:00')
44
                ->whereNotNull('ends_at')
45
                ->where('ends_at', '<', $yesterday)
46
                ->first();
47
48
        return $sub;
49
    }
50
51 View Code Duplication
    public function get30DaysExpiryUsers()
52
    {
53
        $sub = $this->get30DaysExpiryInfo();
54
        //dd($sub->get());
55
        $users = [];
56
        if ($sub->get()->count() > 0) {
57
            foreach ($sub->get() as $key => $value) {
58
                $users[$key]['users'] = $this->sub->find($value->id)->user()->get();
59
                $users[$key]['orders'] = $this->sub->find($value->id)->order()->get();
60
                $users[$key]['subscription'] = $value;
61
            }
62
        }
63
64
        return $users;
65
    }
66
67 View Code Duplication
    public function get15DaysExpiryUsers()
68
    {
69
        $sub = $this->get15DaysExpiryInfo();
70
        $users = [];
71
        if ($sub->get()->count() > 0) {
72
            foreach ($sub->get() as $key => $value) {
73
                $users[$key]['users'] = $this->sub->find($value->id)->user()->get();
74
                $users[$key]['orders'] = $this->sub->find($value->id)->order()->get();
75
                $users[$key]['subscription'] = $value;
76
            }
77
        }
78
79
        return $users;
80
    }
81
82 View Code Duplication
    public function getOneDayExpiryUsers()
83
    {
84
        $sub = $this->getOneDayExpiryInfo();
85
        $users = [];
86
        if ($sub->get()->count() > 0) {
87
            foreach ($sub->get() as $key => $value) {
88
                $users[$key]['users'] = $this->sub->find($value->id)->user()->get();
89
                $users[$key]['orders'] = $this->sub->find($value->id)->order()->get();
90
                $users[$key]['subscription'] = $value;
91
            }
92
        }
93
94
        return $users;
95
    }
96
97 View Code Duplication
    public function getOnDayExpiryUsers()
98
    {
99
        $sub = $this->getOnDayExpiryInfo();
100
        $users = [];
101
        if ($sub->get()->count() > 0) {
102
            foreach ($sub->get() as $key => $value) {
103
                $users[$key]['users'] = $this->sub->find($value->id)->user()->get();
104
                $users[$key]['orders'] = $this->sub->find($value->id)->order()->get();
105
                $users[$key]['subscription'] = $value;
106
            }
107
        }
108
109
        return $users;
110
    }
111
112 View Code Duplication
    public function getExpiredUsers()
113
    {
114
        $sub = $this->getExpiredInfo();
115
        $users = [];
116
        if ($sub->get()->count() > 0) {
117
            foreach ($sub->get() as $key => $value) {
118
                $users[$key]['users'] = $this->sub->find($value->id)->user()->get();
119
                $users[$key]['orders'] = $this->sub->find($value->id)->order()->get();
120
                $users[$key]['subscription'] = $value;
121
            }
122
        }
123
124
        return $users;
125
    }
126
127
    public function get30DaysOrders()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
128
    {
129
        $users = [];
130
        $users = $this->get30DaysExpiryUsers();
131
        if (count($users) > 0) {
132
            return $users[0]['orders'];
133
        }
134
135
        return $users;
136
    }
137
138 View Code Duplication
    public function get15DaysOrders()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
139
    {
140
        $users = [];
141
        $users = $this->get15DaysExpiryUsers();
142
        if (count($users) > 0) {
143
            return $users[0]['orders'];
144
        }
145
146
        return $users;
147
    }
148
149 View Code Duplication
    public function get1DaysOrders()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
150
    {
151
        $users = [];
152
        $users = $this->getOneDayExpiryUsers();
153
        if (count($users) > 0) {
154
            return $users[0]['orders'];
155
        }
156
157
        return $users;
158
    }
159
160 View Code Duplication
    public function get0DaysOrders()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
161
    {
162
        $users = [];
163
        $users = $this->getOnDayExpiryUsers();
164
        if (count($users) > 0) {
165
            return $users[0]['orders'];
166
        }
167
168
        return $users;
169
    }
170
171 View Code Duplication
    public function getPlus1Orders()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
172
    {
173
        $users = [];
174
        $users = $this->getExpiredUsers();
175
        if (count($users) > 0) {
176
            return $users[0]['orders'];
177
        }
178
179
        return $users;
180
    }
181
182 View Code Duplication
    public function get15DaysSubscription()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
183
    {
184
        $users = [];
185
        $users = $this->get15DaysExpiryUsers();
186
        if (count($users) > 0) {
187
            return $users[0]['subscription'];
188
        }
189
190
        return $users;
191
    }
192
193 View Code Duplication
    public function get1DaysSubscription()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
194
    {
195
        $users = [];
196
        $users = $this->getOneDayExpiryUsers();
197
        if (count($users) > 0) {
198
            return $users[0]['subscription'];
199
        }
200
201
        return $users;
202
    }
203
204 View Code Duplication
    public function get0DaysSubscription()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
205
    {
206
        $users = [];
207
        $users = $this->getOnDayExpiryUsers();
208
        if (count($users) > 0) {
209
            return $users[0]['subscription'];
210
        }
211
212
        return $users;
213
    }
214
215 View Code Duplication
    public function getPlus1Subscription()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
216
    {
217
        $users = [];
218
        $users = $this->getExpiredUsers();
219
        if (count($users) > 0) {
220
            return $users[0]['subscription'];
221
        }
222
223
        return $users;
224
    }
225
226 View Code Duplication
    public function getUsers()
227
    {
228
        $users = [];
229
        if (count($this->get30DaysUsers())) {
230
            array_push($users, $this->get30DaysUsers());
231
        }
232
        if (count($this->get15DaysUsers())) {
233
            array_push($users, $this->get15DaysUsers());
234
        }
235
        if (count($this->get1DaysUsers())) {
236
            array_push($users, $this->get1DaysUsers());
237
        }
238
        if (count($this->get0DaysUsers())) {
239
            array_push($users, $this->get0DaysUsers());
240
        }
241
        if (count($this->getPlus1Users())) {
242
            array_push($users, $this->getPlus1Users());
243
        }
244
245
        return $users;
246
    }
247
248
    public function eachSubscription()
249
    {
250
        $sub = $this->getSubscriptions();
251
252
        foreach ($sub as $value) {
253
            $userid = $value->user_id;
254
            $user = $this->getUserById($userid);
255
            $end = $value->ends_at;
256
            $order = $this->getOrderById($value->order_id);
257
            $invoice = $this->getInvoiceByOrderId($value->order_id);
258
            $item = $this->getInvoiceItemByInvoiceId($invoice->id);
259
            $product = $item->product_name;
260
            $this->mail($user, $end, $product, $order, $value->id);
261
        }
262
    }
263
}
264