Passed
Push — master ( 566365...3d5699 )
by Vinicius Lourenço
04:03
created
src/Scheduler/Contracts/SchedulerModelTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,21 +19,21 @@  discard block
 block discarded – undo
19 19
      * @param  string  $relation
20 20
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21 21
      */
22
-	abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null);
22
+	abstract public function belongsTo ($related, $foreignKey = null, $ownerKey = null, $relation = null);
23 23
 
24 24
 	/**
25 25
      * Get the value of the model's primary key.
26 26
      *
27 27
      * @return mixed
28 28
      */
29
-	abstract public function getKey();
29
+	abstract public function getKey ();
30 30
 
31 31
 	/**
32 32
      * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
33 33
      *
34 34
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
35 35
      */
36
-	public function schedules();
36
+	public function schedules ();
37 37
 
38 38
 	/**
39 39
 	 * Agenda um horário para esta model.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
49 49
 	 * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
50 50
 	 */
51
-	public function addSchedule($start_at, $end_at = null, $status = null);
51
+	public function addSchedule ($start_at, $end_at = null, $status = null);
52 52
 
53 53
 	/**
54 54
 	 * Exibe uma lista dos horários do dia de hoje.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *                                         Se for nulo, ele busca a referencia da config.
60 60
 	 * @return array
61 61
 	 */
62
-	public function availableToday($duration = 0, $openingTime = null);
62
+	public function availableToday ($duration = 0, $openingTime = null);
63 63
 
64 64
 	/**
65 65
 	 * Lista os horários livres em um determinado dia.
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      *                                         Se for nulo, ele busca a referencia da config.
72 72
 	 * @return array
73 73
 	 */
74
-	public function availableOn($date, $duration = 0, $openingTime = null);
74
+	public function availableOn ($date, $duration = 0, $openingTime = null);
75 75
 
76 76
 	/**
77 77
 	 * Faz um parse na data e retorna uma instância em Carbon.
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument
84 84
 	 */
85
-	public function parseToCarbon($date, $reference = null);
85
+	public function parseToCarbon ($date, $reference = null);
86 86
 
87 87
 	/**
88 88
 	 * Faz um parse e retorna um Schedule.
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @param  \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado.
91 91
 	 * @return \H4ad\Scheduler\Models\Schedule|null
92 92
 	 */
93
-	public function parseToSchedule($value);
93
+	public function parseToSchedule ($value);
94 94
 
95 95
 	/**
96 96
 	 * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
@@ -104,5 +104,5 @@  discard block
 block discarded – undo
104 104
 	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
105 105
 	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
106 106
 	 */
107
-	public function removeSchedule($schedule);
107
+	public function removeSchedule ($schedule);
108 108
 }
109 109
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Traits/SchedulerModelTrait.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -36,21 +36,21 @@  discard block
 block discarded – undo
36 36
      * @param  string  $relation
37 37
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
38 38
      */
39
-	abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null);
39
+	abstract public function belongsTo ($related, $foreignKey = null, $ownerKey = null, $relation = null);
40 40
 
41 41
 	/**
42 42
      * Get the value of the model's primary key.
43 43
      *
44 44
      * @return mixed
45 45
      */
46
-	abstract public function getKey();
46
+	abstract public function getKey ();
47 47
 
48 48
 	/**
49 49
      * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
50 50
      *
51 51
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
52 52
      */
53
-	public function schedules()
53
+	public function schedules ()
54 54
 	{
55 55
 		return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id');
56 56
 	}
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 	 * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
69 69
 	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
70 70
 	 */
71
-	public function addSchedule($start_at, $end_at = null, $status = null)
71
+	public function addSchedule ($start_at, $end_at = null, $status = null)
72 72
 	{
73
-		if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
73
+		if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
74 74
 			throw new CantAddWithoutEnd;
75 75
 
76
-		$start_at  = $this->parseToCarbon($start_at);
76
+		$start_at = $this->parseToCarbon($start_at);
77 77
 
78
-		if(!is_null($end_at)) {
78
+		if (!is_null($end_at)) {
79 79
 			$end_at = $this->parseToCarbon($end_at, $start_at);
80 80
 
81
-			if($start_at->greaterThan($end_at))
81
+			if ($start_at->greaterThan($end_at))
82 82
 				throw new EndCantBeforeStart;
83 83
 		}
84 84
 
85
-		if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at))
85
+		if (Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at))
86 86
 			throw new CantAddWithSameStartAt;
87 87
 
88 88
 		$model_id = $this->getKey();
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      *                                         Se for nulo, ele busca a referencia da config.
101 101
 	 * @return array
102 102
 	 */
103
-	public function availableToday($duration = 0, $openingTime = null)
103
+	public function availableToday ($duration = 0, $openingTime = null)
104 104
 	{
105 105
 		return Scheduler::availableToday(self::class, $duration, $openingTime);
106 106
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      *                                         Se for nulo, ele busca a referencia da config.
116 116
 	 * @return array
117 117
 	 */
118
-	public function availableOn($date, $duration = 0, $openingTime = null)
118
+	public function availableOn ($date, $duration = 0, $openingTime = null)
119 119
 	{
120 120
 		return Scheduler::availableOn(self::class, $date, $duration, $openingTime);
121 121
 	}
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument
131 131
 	 */
132
-	public function parseToCarbon($date, $reference = null)
132
+	public function parseToCarbon ($date, $reference = null)
133 133
 	{
134
-		if($date instanceof Carbon)
134
+		if ($date instanceof Carbon)
135 135
 			return $date;
136 136
 
137
-		if(is_string($date))
137
+		if (is_string($date))
138 138
 			return Carbon::parse($date);
139 139
 
140
-		if(is_int($date) && !is_null($reference))
140
+		if (is_int($date) && !is_null($reference))
141 141
 			return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
142 142
 
143 143
 		throw new IntInvalidArgument;
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
 	 * @param  \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado.
150 150
 	 * @return \H4ad\Scheduler\Models\Schedule|null
151 151
 	 */
152
-	public function parseToSchedule($value)
152
+	public function parseToSchedule ($value)
153 153
 	{
154
-		if(is_int($value))
154
+		if (is_int($value))
155 155
 			return Schedule::find($value);
156 156
 
157 157
 		return Schedule::byStartAt($value)->first();
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
 	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
170 170
 	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
171 171
 	 */
172
-	public function removeSchedule($schedule)
172
+	public function removeSchedule ($schedule)
173 173
 	{
174
-		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
174
+		if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
175 175
 			throw new CantRemoveByDate;
176 176
 
177 177
 		$schedule = $this->parseToSchedule($schedule);
178 178
 
179
-		if(!($schedule instanceof Model))
179
+		if (!($schedule instanceof Model))
180 180
 			throw (new ModelNotFound)->setValues(Schedule::class);
181 181
 
182
-		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
182
+		if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
183 183
 			throw new DoesNotBelong;
184 184
 
185 185
 		return $schedule->delete();
Please login to merge, or discard this patch.
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -70,20 +70,23 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function addSchedule($start_at, $end_at = null, $status = null)
72 72
 	{
73
-		if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
74
-			throw new CantAddWithoutEnd;
73
+		if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) {
74
+					throw new CantAddWithoutEnd;
75
+		}
75 76
 
76 77
 		$start_at  = $this->parseToCarbon($start_at);
77 78
 
78 79
 		if(!is_null($end_at)) {
79 80
 			$end_at = $this->parseToCarbon($end_at, $start_at);
80 81
 
81
-			if($start_at->greaterThan($end_at))
82
-				throw new EndCantBeforeStart;
82
+			if($start_at->greaterThan($end_at)) {
83
+							throw new EndCantBeforeStart;
84
+			}
83 85
 		}
84 86
 
85
-		if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at))
86
-			throw new CantAddWithSameStartAt;
87
+		if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) {
88
+					throw new CantAddWithSameStartAt;
89
+		}
87 90
 
88 91
 		$model_id = $this->getKey();
89 92
 		$model_type = self::class;
@@ -131,14 +134,17 @@  discard block
 block discarded – undo
131 134
 	 */
132 135
 	public function parseToCarbon($date, $reference = null)
133 136
 	{
134
-		if($date instanceof Carbon)
135
-			return $date;
137
+		if($date instanceof Carbon) {
138
+					return $date;
139
+		}
136 140
 
137
-		if(is_string($date))
138
-			return Carbon::parse($date);
141
+		if(is_string($date)) {
142
+					return Carbon::parse($date);
143
+		}
139 144
 
140
-		if(is_int($date) && !is_null($reference))
141
-			return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
145
+		if(is_int($date) && !is_null($reference)) {
146
+					return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
147
+		}
142 148
 
143 149
 		throw new IntInvalidArgument;
144 150
 	}
@@ -151,8 +157,9 @@  discard block
 block discarded – undo
151 157
 	 */
152 158
 	public function parseToSchedule($value)
153 159
 	{
154
-		if(is_int($value))
155
-			return Schedule::find($value);
160
+		if(is_int($value)) {
161
+					return Schedule::find($value);
162
+		}
156 163
 
157 164
 		return Schedule::byStartAt($value)->first();
158 165
 	}
@@ -171,16 +178,19 @@  discard block
 block discarded – undo
171 178
 	 */
172 179
 	public function removeSchedule($schedule)
173 180
 	{
174
-		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
175
-			throw new CantRemoveByDate;
181
+		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) {
182
+					throw new CantRemoveByDate;
183
+		}
176 184
 
177 185
 		$schedule = $this->parseToSchedule($schedule);
178 186
 
179
-		if(!($schedule instanceof Model))
180
-			throw (new ModelNotFound)->setValues(Schedule::class);
187
+		if(!($schedule instanceof Model)) {
188
+					throw (new ModelNotFound)->setValues(Schedule::class);
189
+		}
181 190
 
182
-		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
183
-			throw new DoesNotBelong;
191
+		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) {
192
+					throw new DoesNotBelong;
193
+		}
184 194
 
185 195
 		return $schedule->delete();
186 196
 	}
Please login to merge, or discard this patch.
src/Scheduler/Scheduler.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @return void
30 30
      */
31
-    public function __construct($app)
31
+    public function __construct ($app)
32 32
     {
33 33
         $this->app = $app;
34 34
     }
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
      * @param string|\Carbon\Carbon $end_at
42 42
      * @return bool
43 43
      */
44
-    public function hasScheduleBetween($model_type, $start_at, $end_at)
44
+    public function hasScheduleBetween ($model_type, $start_at, $end_at)
45 45
     {
46
-        if(!Config::get('scheduler.enable_schedule_conflict'))
46
+        if (!Config::get('scheduler.enable_schedule_conflict'))
47 47
             return false;
48 48
 
49 49
         return !is_null(
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      *                                         Se for nulo, ele busca a referencia da config.
66 66
      * @return array
67 67
      */
68
-    public function availableToday($model_type, $duration, $openingTime = null)
68
+    public function availableToday ($model_type, $duration, $openingTime = null)
69 69
     {
70 70
         return $this->availableOn($model_type, Carbon::now(), $duration, $openingTime);
71 71
     }
@@ -81,42 +81,42 @@  discard block
 block discarded – undo
81 81
      *                                         Se for nulo, ele busca a referencia da config.
82 82
      * @return array
83 83
      */
84
-    public function availableOn($model_type, $today, $durationMinutes, $openingTime = null)
84
+    public function availableOn ($model_type, $today, $durationMinutes, $openingTime = null)
85 85
     {
86 86
         //TODO: Melhorar a performance desse método.
87
-        if(is_null($openingTime))
87
+        if (is_null($openingTime))
88 88
             $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
89 89
 
90 90
         $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
91 91
 
92
-        $livres = [];
92
+        $livres = [ ];
93 93
         $today = Carbon::parse($today->toDateString());
94
-        while($openingTime <= $closingTime)
94
+        while ($openingTime <= $closingTime)
95 95
         {
96 96
             $add = true;
97 97
 
98 98
             foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) {
99
-            	if($schedule->model_type != $model_type)
99
+            	if ($schedule->model_type != $model_type)
100 100
             		continue;
101 101
 
102 102
                 $start = Carbon::parse($schedule->start_at);
103 103
                 $begin = Carbon::parse($start->toDateString());
104 104
 
105
-                if($begin->greaterThan($today))
105
+                if ($begin->greaterThan($today))
106 106
                     break;
107 107
 
108
-                if($begin->notEqualTo($today))
108
+                if ($begin->notEqualTo($today))
109 109
                     continue;
110 110
 
111 111
                 $end = Carbon::parse($schedule->end_at);
112
-                if($start <= Carbon::parse($openingTime->toDateTimeString())
112
+                if ($start <= Carbon::parse($openingTime->toDateTimeString())
113 113
                 && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes))
114 114
                     $add = false;
115 115
             }
116 116
 
117 117
             $endTime = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
118
-            if($add && $endTime->lessThanOrEqualTo($closingTime))
119
-                $livres[] = [
118
+            if ($add && $endTime->lessThanOrEqualTo($closingTime))
119
+                $livres[ ] = [
120 120
                     'start_at' => Carbon::parse($openingTime->toDateTimeString()),
121 121
                     'end_at' => $endTime
122 122
                 ];
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -43,8 +43,9 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function hasScheduleBetween($model_type, $start_at, $end_at)
45 45
     {
46
-        if(!Config::get('scheduler.enable_schedule_conflict'))
47
-            return false;
46
+        if(!Config::get('scheduler.enable_schedule_conflict')) {
47
+                    return false;
48
+        }
48 49
 
49 50
         return !is_null(
50 51
             Schedule::latest()
@@ -84,8 +85,9 @@  discard block
 block discarded – undo
84 85
     public function availableOn($model_type, $today, $durationMinutes, $openingTime = null)
85 86
     {
86 87
         //TODO: Melhorar a performance desse método.
87
-        if(is_null($openingTime))
88
-            $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
88
+        if(is_null($openingTime)) {
89
+                    $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
90
+        }
89 91
 
90 92
         $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
91 93
 
@@ -96,30 +98,35 @@  discard block
 block discarded – undo
96 98
             $add = true;
97 99
 
98 100
             foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) {
99
-            	if($schedule->model_type != $model_type)
100
-            		continue;
101
+            	if($schedule->model_type != $model_type) {
102
+            	            		continue;
103
+            	}
101 104
 
102 105
                 $start = Carbon::parse($schedule->start_at);
103 106
                 $begin = Carbon::parse($start->toDateString());
104 107
 
105
-                if($begin->greaterThan($today))
106
-                    break;
108
+                if($begin->greaterThan($today)) {
109
+                                    break;
110
+                }
107 111
 
108
-                if($begin->notEqualTo($today))
109
-                    continue;
112
+                if($begin->notEqualTo($today)) {
113
+                                    continue;
114
+                }
110 115
 
111 116
                 $end = Carbon::parse($schedule->end_at);
112 117
                 if($start <= Carbon::parse($openingTime->toDateTimeString())
113
-                && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes))
114
-                    $add = false;
118
+                && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) {
119
+                                    $add = false;
120
+                }
115 121
             }
116 122
 
117 123
             $endTime = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
118
-            if($add && $endTime->lessThanOrEqualTo($closingTime))
119
-                $livres[] = [
124
+            if($add && $endTime->lessThanOrEqualTo($closingTime)) {
125
+                            $livres[] = [
120 126
                     'start_at' => Carbon::parse($openingTime->toDateTimeString()),
121 127
                     'end_at' => $endTime
122 128
                 ];
129
+            }
123 130
 
124 131
             $openingTime->addMinutes($durationMinutes);
125 132
         }
Please login to merge, or discard this patch.