Conditions | 3 |
Paths | 3 |
Total Lines | 53 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
61 | private function generateICS() |
||
62 | { |
||
63 | $date = Carbon::createFromFormat('Y-m-d', $this->date); |
||
64 | |||
65 | $reportAddress = Setting::where('name', 'report_address')->first(); |
||
66 | |||
67 | $rrule = ''; |
||
68 | if ($this->duty->cycle == 'weekly') { |
||
69 | $rrule = 'RRULE:FREQ=DAILY;COUNT=5;INTERVAL=1;'; |
||
70 | } elseif ($this->duty->cycle == 'daily') { |
||
71 | $rrule = 'RRULE:FREQ=DAILY;COUNT=1;INTERVAL=1;'; |
||
72 | } |
||
73 | |||
74 | $filename = 'schedule.ics'; |
||
75 | $meetingDuration = (1800); // 30 minutes |
||
76 | $time = 'T15:30:00.00'; |
||
77 | $meetingstamp = strtotime($date->toFormattedDateString().$time); |
||
78 | $dtstart = gmdate('Ymd\THis\Z', $meetingstamp); |
||
79 | $dtend = gmdate('Ymd\THis\Z', $meetingstamp + $meetingDuration); |
||
80 | $todaystamp = gmdate('Ymd\THis\Z'); |
||
81 | $title = "You have $this->duty->name security check"; |
||
82 | $organizer = 'MAILTO:'.$reportAddress->secondary; |
||
83 | |||
84 | // ICS |
||
85 | $mail = []; |
||
86 | $mail[0] = 'BEGIN:VCALENDAR'; |
||
87 | $mail[1] = 'PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN'; |
||
88 | $mail[2] = 'VERSION:2.0'; |
||
89 | $mail[3] = 'CALSCALE:GREGORIAN'; |
||
90 | $mail[4] = 'METHOD:REQUEST'; |
||
91 | $mail[5] = 'BEGIN:VEVENT'; |
||
92 | $mail[6] = 'DTSTART;TZID=America/Chicago:'.$dtstart; |
||
93 | $mail[7] = 'DTEND;TZID=America/Chicago:'.$dtend; |
||
94 | $mail[8] = 'DTSTAMP;TZID=America/Chicago:'.$todaystamp; |
||
95 | $mail[9] = 'UID:'.date('Ymd').'T'.date('His').'-'.rand().'@teamscci.com'; |
||
96 | $mail[10] = 'ORGANIZER;'.$organizer; |
||
97 | $mail[11] = 'CREATED:'.$todaystamp; |
||
98 | $mail[12] = 'LAST-MODIFIED:'.$todaystamp; |
||
99 | $mail[14] = 'SEQUENCE:0'; |
||
100 | $mail[15] = 'STATUS:CONFIRMED'; |
||
101 | $mail[16] = 'SUMMARY:'.$title; |
||
102 | $mail[17] = 'TRANSP:OPAQUE'; |
||
103 | $mail[18] = 'X-MICROSOFT-CDO-IMPORTANTCE:1'; |
||
104 | $mail[19] = $rrule; |
||
105 | $mail[20] = 'END:VEVENT'; |
||
106 | $mail[21] = 'END:VCALENDAR'; |
||
107 | |||
108 | $mail = implode("\r\n", $mail); |
||
109 | header('text/calendar'); |
||
110 | file_put_contents($filename, $mail); |
||
111 | |||
112 | return $filename; |
||
113 | } |
||
114 | } |
||
115 |