Total Complexity | 44 |
Total Lines | 250 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like CronController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CronController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class CronController extends BaseCronController |
||
14 | { |
||
15 | protected $subscription; |
||
16 | protected $order; |
||
17 | protected $user; |
||
18 | protected $template; |
||
19 | protected $invoice; |
||
20 | |||
21 | public function __construct() |
||
37 | } |
||
38 | |||
39 | public function getExpiredInfoByOrderId($orderid) |
||
40 | { |
||
41 | $yesterday = new Carbon('today'); |
||
42 | $sub = $this->sub |
||
43 | ->where('order_id', $orderid) |
||
44 | ->where('update_ends_at', '!=', '0000-00-00 00:00:00') |
||
45 | ->whereNotNull('update_ends_at') |
||
46 | ->where('update_ends_at', '<', $yesterday) |
||
47 | ->first(); |
||
48 | |||
49 | return $sub; |
||
50 | } |
||
51 | |||
52 | public function getAllDaysExpiryUsers($day) |
||
53 | { |
||
54 | $sub = $this->getAllDaysExpiryInfo($day); |
||
55 | //dd($sub->get()); |
||
56 | $users = []; |
||
57 | if ($sub->get()->count() > 0) { |
||
58 | foreach ($sub->get() as $key => $value) { |
||
59 | $users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
||
60 | $users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
||
61 | $users[$key]['subscription'] = $value; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | return $users; |
||
66 | } |
||
67 | |||
68 | public function get15DaysExpiryUsers() |
||
69 | { |
||
70 | $sub = $this->get15DaysExpiryInfo(); |
||
71 | $users = []; |
||
72 | if ($sub->get()->count() > 0) { |
||
73 | foreach ($sub->get() as $key => $value) { |
||
74 | $users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
||
75 | $users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
||
76 | $users[$key]['subscription'] = $value; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | return $users; |
||
81 | } |
||
82 | |||
83 | public function getOneDayExpiryUsers() |
||
84 | { |
||
85 | $sub = $this->getOneDayExpiryInfo(); |
||
86 | $users = []; |
||
87 | if ($sub->get()->count() > 0) { |
||
88 | foreach ($sub->get() as $key => $value) { |
||
89 | $users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
||
90 | $users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
||
91 | $users[$key]['subscription'] = $value; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | return $users; |
||
96 | } |
||
97 | |||
98 | public function getOnDayExpiryUsers() |
||
99 | { |
||
100 | $sub = $this->getOnDayExpiryInfo(); |
||
101 | $users = []; |
||
102 | if ($sub->get()->count() > 0) { |
||
103 | foreach ($sub->get() as $key => $value) { |
||
104 | $users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
||
105 | $users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
||
106 | $users[$key]['subscription'] = $value; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | return $users; |
||
111 | } |
||
112 | |||
113 | public function getExpiredUsers() |
||
114 | { |
||
115 | $sub = $this->getExpiredInfo(); |
||
116 | $users = []; |
||
117 | if ($sub->get()->count() > 0) { |
||
118 | foreach ($sub->get() as $key => $value) { |
||
119 | $users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
||
120 | $users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
||
121 | $users[$key]['subscription'] = $value; |
||
122 | } |
||
123 | } |
||
124 | |||
125 | return $users; |
||
126 | } |
||
127 | |||
128 | public function get30DaysOrders() |
||
129 | { |
||
130 | $users = []; |
||
131 | $users = $this->get30DaysExpiryUsers(); |
||
132 | if (count($users) > 0) { |
||
133 | return $users[0]['orders']; |
||
134 | } |
||
135 | |||
136 | return $users; |
||
137 | } |
||
138 | |||
139 | public function get15DaysOrders() |
||
140 | { |
||
141 | $users = []; |
||
142 | $users = $this->get15DaysExpiryUsers(); |
||
143 | if (count($users) > 0) { |
||
144 | return $users[0]['orders']; |
||
145 | } |
||
146 | |||
147 | return $users; |
||
148 | } |
||
149 | |||
150 | public function get1DaysOrders() |
||
151 | { |
||
152 | $users = []; |
||
153 | $users = $this->getOneDayExpiryUsers(); |
||
154 | if (count($users) > 0) { |
||
155 | return $users[0]['orders']; |
||
156 | } |
||
157 | |||
158 | return $users; |
||
159 | } |
||
160 | |||
161 | public function get0DaysOrders() |
||
162 | { |
||
163 | $users = []; |
||
164 | $users = $this->getOnDayExpiryUsers(); |
||
165 | if (count($users) > 0) { |
||
166 | return $users[0]['orders']; |
||
167 | } |
||
168 | |||
169 | return $users; |
||
170 | } |
||
171 | |||
172 | public function getPlus1Orders() |
||
173 | { |
||
174 | $users = []; |
||
175 | $users = $this->getExpiredUsers(); |
||
176 | if (count($users) > 0) { |
||
177 | return $users[0]['orders']; |
||
178 | } |
||
179 | |||
180 | return $users; |
||
181 | } |
||
182 | |||
183 | public function get15DaysSubscription() |
||
184 | { |
||
185 | $users = []; |
||
186 | $users = $this->get15DaysExpiryUsers(); |
||
187 | if (count($users) > 0) { |
||
188 | return $users[0]['subscription']; |
||
189 | } |
||
190 | |||
191 | return $users; |
||
192 | } |
||
193 | |||
194 | public function get1DaysSubscription() |
||
195 | { |
||
196 | $users = []; |
||
197 | $users = $this->getOneDayExpiryUsers(); |
||
198 | if (count($users) > 0) { |
||
199 | return $users[0]['subscription']; |
||
200 | } |
||
201 | |||
202 | return $users; |
||
203 | } |
||
204 | |||
205 | public function get0DaysSubscription() |
||
206 | { |
||
207 | $users = []; |
||
208 | $users = $this->getOnDayExpiryUsers(); |
||
209 | if (count($users) > 0) { |
||
210 | return $users[0]['subscription']; |
||
211 | } |
||
212 | |||
213 | return $users; |
||
214 | } |
||
215 | |||
216 | public function getPlus1Subscription() |
||
225 | } |
||
226 | |||
227 | public function getUsers() |
||
228 | { |
||
229 | $users = []; |
||
230 | if (count($this->get30DaysUsers())) { |
||
247 | } |
||
248 | |||
249 | public function eachSubscription() |
||
250 | { |
||
251 | $allDays = ExpiryMailDay::pluck('days')->toArray(); |
||
252 | $sub = $this->getSubscriptions($allDays); |
||
253 | foreach ($sub as $value) { |
||
254 | $userid = $value->user_id; |
||
255 | $user = $this->getUserById($userid); |
||
256 | $end = $value->update_ends_at; |
||
267 |