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

BaseCronController::getSubscriptions()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
nc 32
nop 0
dl 24
loc 24
rs 8.9137
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Common;
4
5
use App\Http\Controllers\Controller;
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 BaseCronController extends Controller
13
{
14
    public function getUserById($id)
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...
15
    {
16
        $user = User::find($id);
17
18
        return $user;
19
    }
20
21
    public function getOrderById($id)
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...
22
    {
23
        $order = Order::find($id);
24
25
        return $order;
26
    }
27
28
    public function getInvoiceByOrderId($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...
29
    {
30
        $order = Order::find($orderid);
31
        $invoice = $order->invoice()->first();
32
33
        return $invoice;
34
    }
35
36
    public function getInvoiceItemByInvoiceId($invoiceid)
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...
37
    {
38
        $invoice = Invoice::find($invoiceid);
39
        $item_id = $invoice->invoiceItem()->first();
0 ignored issues
show
Coding Style introduced by
$item_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
40
41
        return $item_id;
0 ignored issues
show
Coding Style introduced by
$item_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
42
    }
43
44 View Code Duplication
    public function getSubscriptions()
45
    {
46
        $sub = [];
47
        if (count($this->get30DaysSubscription())) {
48
            array_push($sub, $this->get30DaysSubscription());
49
        }
50
51
        if (count($this->get15DaysUsers())) {
52
            array_push($sub, $this->get15DaysSubscription());
0 ignored issues
show
Bug introduced by
The method get15DaysSubscription() does not exist on App\Http\Controllers\Common\BaseCronController. Did you maybe mean get30DaysSubscription()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
53
        }
54
55
        if (count($this->get1DaysUsers())) {
56
            array_push($sub, $this->get1DaysSubscription());
0 ignored issues
show
Bug introduced by
The method get1DaysSubscription() does not exist on App\Http\Controllers\Common\BaseCronController. Did you maybe mean get30DaysSubscription()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
57
        }
58
59
        if (count($this->get0DaysUsers())) {
60
            array_push($sub, $this->get0DaysSubscription());
0 ignored issues
show
Bug introduced by
The method get0DaysSubscription() does not exist on App\Http\Controllers\Common\BaseCronController. Did you maybe mean get30DaysSubscription()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
        }
62
        if (count($this->getPlus1Users())) {
63
            array_push($sub, $this->getPlus1Subscription());
64
        }
65
66
        return $sub;
67
    }
68
69
    public function get30DaysSubscription()
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...
70
    {
71
        $users = [];
72
        $users = $this->get30DaysExpiryUsers();
73
        if (count($users) > 0) {
74
            return $users[0]['subscription'];
75
        }
76
77
        return $users;
78
    }
79
80 View Code Duplication
    public function get15DaysUsers()
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...
81
    {
82
        $users = [];
83
        $users = $this->get15DaysExpiryUsers();
84
        if (count($users) > 0) {
85
            return $users[0]['users'];
86
        }
87
88
        return $users;
89
    }
90
91 View Code Duplication
    public function get1DaysUsers()
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...
92
    {
93
        $users = [];
94
        $users = $this->getOneDayExpiryUsers();
95
        if (count($users) > 0) {
96
            return $users[0]['users'];
97
        }
98
99
        return $users;
100
    }
101
102 View Code Duplication
    public function get0DaysUsers()
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...
103
    {
104
        $users = [];
105
        $users = $this->getOnDayExpiryUsers();
106
        if (count($users) > 0) {
107
            return $users[0]['users'];
108
        }
109
110
        return $users;
111
    }
112
113 View Code Duplication
    public function getPlus1Users()
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...
114
    {
115
        $users = [];
116
        $users = $this->getExpiredUsers();
117
        if (count($users) > 0) {
118
            return $users[0]['users'];
119
        }
120
121
        return $users;
122
    }
123
124
    public function get30DaysUsers()
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...
125
    {
126
        $users = $this->get30DaysExpiryUsers();
127
        //dd($users);
128
        if (count($users) > 0) {
129
            return $users[0]['users'];
130
        }
131
132
        return $users;
133
    }
134
135 View Code Duplication
    public function getExpiredInfo()
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...
136
    {
137
        $yesterday = new Carbon('today');
138
        $tomorrow = new Carbon('+2 days');
139
        $sub = Subscription:: where('ends_at', '!=', '0000-00-00 00:00:00')
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after double colon; 1 found

This check looks for references to static members where there are spaces between the name of the type and the actual member.

An example:

Certificate:: TRIPLEDES_CBC

will actually work, but is not very readable.

Loading history...
140
                ->whereNotNull('ends_at')
141
                ->whereBetween('ends_at', [$yesterday, $tomorrow]);
142
143
        return $sub;
144
    }
145
146 View Code Duplication
    public function getOnDayExpiryInfo()
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...
147
    {
148
        $yesterday = new Carbon('yesterday');
149
        $tomorrow = new Carbon('tomorrow');
150
        $sub = Subscription::where('ends_at', '!=', '0000-00-00 00:00:00')
151
            ->whereNotNull('ends_at')
152
            ->whereBetween('ends_at', [$yesterday, $tomorrow]);
153
154
        return $sub;
155
    }
156
157 View Code Duplication
    public function getOneDayExpiryInfo()
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...
158
    {
159
        $yesterday = new Carbon('-2 days');
160
        $today = new Carbon('today');
161
        $sub = Subscription::where('ends_at', '!=', '0000-00-00 00:00:00')
162
                ->whereNotNull('ends_at')
163
                ->whereBetween('ends_at', [$yesterday, $today]);
164
165
        return $sub;
166
    }
167
168 View Code Duplication
    public function get15DaysExpiryInfo()
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...
169
    {
170
        $plus14days = new Carbon('+14 days');
171
        $plus16days = new Carbon('+16 days');
172
        $sub = Subscription::where('ends_at', '!=', '0000-00-00 00:00:00')
173
            ->whereNotNull('ends_at')
174
            ->whereBetween('ends_at', [$plus14days, $plus16days]);
175
176
        return $sub;
177
    }
178
179 View Code Duplication
    public function get30DaysExpiryInfo()
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...
180
    {
181
        $plus29days = new Carbon('+29 days');
182
        $plus31days = new Carbon('+31 days');
183
184
        $sub = Subscription::where('ends_at', '!=', '0000-00-00 00:00:00')
185
            ->whereNotNull('ends_at')
186
            ->whereBetween('ends_at', [$plus29days, $plus31days]);
187
188
        return $sub;
189
    }
190
191
    public function mail($user, $end, $product, $order, $sub)
192
    {
193
        //check in the settings
194
        $settings = new \App\Model\Common\Setting();
195
        $setting = $settings->where('id', 1)->first();
196
        $url = url('my-orders');
197
        //template
198
        $templates = new \App\Model\Common\Template();
199
        $temp_id = $setting->subscription_going_to_end;
0 ignored issues
show
Coding Style introduced by
$temp_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
200
201
        if ($end < date('Y-m-d H:m:i')) {
202
            $temp_id = $setting->subscription_over;
0 ignored issues
show
Coding Style introduced by
$temp_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
203
        }
204
205
        $template = $templates->where('id', $temp_id)->first();
0 ignored issues
show
Coding Style introduced by
$temp_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
206
        $from = $setting->email;
207
        $to = $user->email;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $to. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
208
        $subject = $template->name;
209
        $data = $template->data;
210
        $date = date_create($end);
211
        $end = date_format($date, 'l, F j, Y H:m A');
212
        $replace = ['name' => ucfirst($user->first_name).' '.ucfirst($user->last_name),
213
            'expiry'       => $end,
214
            'product'      => $product,
215
            'number'       => $order->number,
216
            'url'          => $url,
217
        ];
218
        $type = '';
219 View Code Duplication
        if ($template) {
220
            $type_id = $template->type;
0 ignored issues
show
Coding Style introduced by
$type_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
221
            $temp_type = new \App\Model\Common\TemplateType();
0 ignored issues
show
Coding Style introduced by
$temp_type does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
222
            $type = $temp_type->where('id', $type_id)->first()->name;
0 ignored issues
show
Coding Style introduced by
$temp_type does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
223
        }
224
        $templateController = new \App\Http\Controllers\Common\TemplateController();
225
        $mail = $templateController->mailing($from, $to, $data, $subject, $replace, $type);
226
227
        return $mail;
228
    }
229
}
230