Completed
Push — master ( a79d86...61314e )
by Nuno
01:56
created
src/Scheduler.php 3 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param string $startTime \Datetime start time string compatible with php Datetime class. example: '08:00'
31 31
      * @param string $endTime \Datetime end time string compatible with php Datetime class. example: '17:00'
32 32
      */
33
-    public function setTimeFrame( $startTime = null, $endTime = null )
33
+    public function setTimeFrame($startTime = null, $endTime = null)
34 34
     {
35 35
         if ($startTime != null && !empty($startTime)) {
36 36
             $this->startTime = new \DateTime($startTime);
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @param string $dateTimeStr \Datetime object valid date string
50 50
      */
51
-    public function add( $dateTimeStr )
51
+    public function add($dateTimeStr)
52 52
     {
53 53
         $this->oneTimeEvents[] = new \DateTime($dateTimeStr);
54 54
         return $this;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @param string $dateTimeStr \Datetime object valid date string
61 61
      */
62
-    public function addRecurring( $dateTimeStr )
62
+    public function addRecurring($dateTimeStr)
63 63
     {
64 64
         $this->schedules[] = $dateTimeStr;
65 65
         return $this;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param string $fromDateStr \Datetime object valid date string
73 73
      * @return \Datetime or null
74 74
      */
75
-    public function getNextSchedule( $fromDateStr = 'now' )
75
+    public function getNextSchedule($fromDateStr = 'now')
76 76
     {
77 77
         $dates = $this->getNextSchedules($fromDateStr, 1);
78 78
         return count($dates) ? $dates[0] : null;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @param int $limit number of dates to return
87 87
      * @return array
88 88
      */
89
-    public function getNextSchedules( $fromDateStr = 'now', $limit = 5 )
89
+    public function getNextSchedules($fromDateStr = 'now', $limit = 5)
90 90
     {
91 91
         $dates = [];
92 92
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         foreach ($this->schedules as $schedule) {
100 100
             $d = new \DateTime($fromDateStr);
101 101
 
102
-            for ($i=0, $maxRecursion = 100 * $limit; $i < $limit && $maxRecursion > 0; ++$i, --$maxRecursion) {
102
+            for ($i = 0, $maxRecursion = 100 * $limit; $i < $limit && $maxRecursion > 0; ++$i, --$maxRecursion) {
103 103
 
104 104
                 if (strpos($schedule, '+') !== false) {
105 105
                     if ($this->startTime instanceof \DateTime && $d < $this->startTime->modify($d->format('Y-m-d'))) {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     /**
130 130
      * @param array $dates
131 131
      */
132
-    private function orderDates( &$dates )
132
+    private function orderDates(&$dates)
133 133
     {
134 134
         uasort($dates, function($a, $b) {
135 135
             return strtotime($a->format('Y-m-d H:i:s')) > strtotime($b->format('Y-m-d H:i:s')) ? 1 : -1;
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -104,18 +104,15 @@
 block discarded – undo
104 104
                 if (strpos($schedule, '+') !== false) {
105 105
                     if ($this->startTime instanceof \DateTime && $d < $this->startTime->modify($d->format('Y-m-d'))) {
106 106
                         $d->modify($this->startTime->format('H:i:s'));
107
-                    }
108
-                    elseif ($this->endTime instanceof \DateTime && $d > $this->endTime->modify($d->format('Y-m-d'))) {
107
+                    } elseif ($this->endTime instanceof \DateTime && $d > $this->endTime->modify($d->format('Y-m-d'))) {
109 108
                         $d->modify('next day')->modify($this->startTime->format('H:i:s'));
110 109
                     }
111 110
 
112 111
                     $dates[] = clone $d;
113 112
                     $d->modify($schedule);
114
-                }
115
-                elseif ($this->isInTimeFrame($d->modify($schedule), $fromDateStr)) {
113
+                } elseif ($this->isInTimeFrame($d->modify($schedule), $fromDateStr)) {
116 114
                     $dates[] = clone $d;
117
-                }
118
-                else {
115
+                } else {
119 116
                     --$i;
120 117
                 }
121 118
             }
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
         $dates = [];
92 92
 
93 93
         foreach ($this->oneTimeEvents as $schedule) {
94
-			$dt = new \DateTime($fromDateStr);
95
-			$dt->modify($schedule);
94
+            $dt = new \DateTime($fromDateStr);
95
+            $dt->modify($schedule);
96 96
 			
97 97
             if ($this->isInTimeFrame($dt, $fromDateStr)) {
98 98
                 $dates[] = $dt;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
     /**
133 133
      * @param array $dates
134
-	 * @return array
134
+     * @return array
135 135
      */
136 136
     private function orderDates( &$dates )
137 137
     {
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 
143 143
     /**
144 144
      * @param \DateTime $date
145
-	 * @return bool
145
+     * @return bool
146 146
      */
147 147
     private function isInTimeFrame(\DateTime $date, $fromDateStr = 'now')
148 148
     {
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
         return true;
161 161
     }
162 162
 
163
-	/**
164
-	 * @param string $dateStr \Datetime object valid date string
165
-	 * @return bool
166
-	 */
167
-	private function isDateRelative($dateStr)
168
-	{
169
-		return strpos($dateStr, '+') !== false;
170
-	}
163
+    /**
164
+     * @param string $dateStr \Datetime object valid date string
165
+     * @return bool
166
+     */
167
+    private function isDateRelative($dateStr)
168
+    {
169
+        return strpos($dateStr, '+') !== false;
170
+    }
171 171
 
172 172
 }
173 173
\ No newline at end of file
Please login to merge, or discard this patch.