Passed
Push — master ( de62e4...72070c )
by Vinicius Lourenço
03:08
created
src/Scheduler/Contracts/SchedulerModelTrait.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 interface SchedulerModelInterface
12 12
 {
13
-	/**
13
+    /**
14 14
      * Define an inverse one-to-one or many relationship.
15 15
      *
16 16
      * @param  string  $related
@@ -19,67 +19,67 @@  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
-	/**
39
-	 * Agenda um horário para esta model.
40
-	 *
41
-	 * @param string|\Carbon\Carbon $start_at	Data em que será agendado, pode ser em string ou em numa classe Carbon.
42
-	 * @param string|\Carbon\Carbon|int $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon
43
-	 *                                    ou em int(sendo considerado os minutos de duração).
44
-	 * @param int $status	Status desse horário ao ser agendado.
45
-	 * @return \H4ad\Scheduler\Models\Schedule
46
-	 *
47
-	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
48
-	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
49
-	 * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
50
-	 */
51
-	public function addSchedule($start_at, $end_at = null, $status = null);
38
+    /**
39
+     * Agenda um horário para esta model.
40
+     *
41
+     * @param string|\Carbon\Carbon $start_at	Data em que será agendado, pode ser em string ou em numa classe Carbon.
42
+     * @param string|\Carbon\Carbon|int $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon
43
+     *                                    ou em int(sendo considerado os minutos de duração).
44
+     * @param int $status	Status desse horário ao ser agendado.
45
+     * @return \H4ad\Scheduler\Models\Schedule
46
+     *
47
+     * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
48
+     * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
49
+     * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
50
+     */
51
+    public function addSchedule($start_at, $end_at = null, $status = null);
52 52
 
53
-	/**
54
-	 * Exibe uma lista dos horários do dia de hoje.
55
-	 *
56
-	 * @param  int    $duration Serve para facilitar na hora de buscar horários livres
57
-	 *                          que precisem ter uma certa duração.
58
-	 * @return array
59
-	 */
60
-	public function availableToday($duration = 0);
53
+    /**
54
+     * Exibe uma lista dos horários do dia de hoje.
55
+     *
56
+     * @param  int    $duration Serve para facilitar na hora de buscar horários livres
57
+     *                          que precisem ter uma certa duração.
58
+     * @return array
59
+     */
60
+    public function availableToday($duration = 0);
61 61
 
62
-	/**
63
-	 * Lista os horários livres em um determinado dia.
64
-	 *
65
-	 * @param  string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca.
66
-	 * @param  int    $duration Serve para facilitar na hora de buscar horários livres
67
-	 *                          que precisem ter uma certa duração.
68
-	 * @return array
69
-	 */
70
-	public function availableOn($date, $duration = 0);
62
+    /**
63
+     * Lista os horários livres em um determinado dia.
64
+     *
65
+     * @param  string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca.
66
+     * @param  int    $duration Serve para facilitar na hora de buscar horários livres
67
+     *                          que precisem ter uma certa duração.
68
+     * @return array
69
+     */
70
+    public function availableOn($date, $duration = 0);
71 71
 
72
-	/**
73
-	 * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
74
-	 * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção
75
-	 * se for tentado remover um horário agendado pela data de quando foi marcado.
76
-	 *
77
-	 * @param  int|string|\Carbon\Carbon $schedule    Horário agendado.
78
-	 * @return bool|null
79
-	 *
80
-	 * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong
81
-	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
82
-	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
83
-	 */
84
-	public function removeSchedule($schedule);
72
+    /**
73
+     * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
74
+     * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção
75
+     * se for tentado remover um horário agendado pela data de quando foi marcado.
76
+     *
77
+     * @param  int|string|\Carbon\Carbon $schedule    Horário agendado.
78
+     * @return bool|null
79
+     *
80
+     * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong
81
+     * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
82
+     * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
83
+     */
84
+    public function removeSchedule($schedule);
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Traits/SchedulerModelTrait.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 trait SchedulerModelTrait
28 28
 {
29
-	/**
29
+    /**
30 30
      * Define an inverse one-to-one or many relationship.
31 31
      *
32 32
      * @param  string  $related
@@ -35,94 +35,94 @@  discard block
 block discarded – undo
35 35
      * @param  string  $relation
36 36
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
37 37
      */
38
-	abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null);
38
+    abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null);
39 39
 
40
-	/**
40
+    /**
41 41
      * Get the value of the model's primary key.
42 42
      *
43 43
      * @return mixed
44 44
      */
45
-	abstract public function getKey();
45
+    abstract public function getKey();
46 46
 
47
-	/**
47
+    /**
48 48
      * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
49 49
      *
50 50
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51 51
      */
52
-	public function schedules()
53
-	{
54
-		return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class);
55
-	}
56
-
57
-	/**
58
-	 * Agenda um horário para esta model.
59
-	 *
60
-	 * @param string|\Carbon\Carbon $start_at	Data em que será agendado, pode ser em string ou em numa classe Carbon.
61
-	 * @param string|\Carbon\Carbon|int $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon
62
-	 *                                           ou em int(sendo considerado os minutos de duração).
63
-	 * @param int $status	Status desse horário ao ser agendado.
64
-	 * @return \H4ad\Scheduler\Models\Schedule
65
-	 *
66
-	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
67
-	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
68
-	 * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
69
-	 */
70
-	public function addSchedule($start_at, $end_at = null, $status = null)
71
-	{
72
-		if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
73
-			throw new CantAddWithoutEnd;
74
-
75
-		if(is_string($start_at))
76
-			$start_at = Carbon::parse($start_at);
77
-
78
-		if(is_string($end_at))
79
-			$end_at = Carbon::parse($end_at);
80
-
81
-		if(is_int($end_at))
82
-			$end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at);
83
-
84
-		if(Config::get('scheduler.enable_schedule_conflict'))
85
-			if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at))
86
-				throw new CantAddWithSameStartAt;
87
-
88
-		if($start_at->greaterThan($end_at) && !is_null($end_at))
89
-			throw new EndCantBeforeStart;
90
-
91
-		$model_id = $this->getKey();
92
-		$model_type = self::class;
93
-
94
-		return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type'));
95
-	}
96
-
97
-	/**
98
-	 * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
99
-	 * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção
100
-	 * se for tentado remover um horário agendado pela data de quando foi marcado.
101
-	 *
102
-	 * @param  int|string|\Carbon\Carbon $schedule    Horário agendado.
103
-	 * @return bool|null
104
-	 *
105
-	 * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong
106
-	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
107
-	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
108
-	 */
109
-	public function removeSchedule($schedule)
110
-	{
111
-		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
112
-			throw new CantRemoveByDate;
113
-
114
-		if(is_int($schedule))
115
-			$schedule = Schedule::find($schedule);
116
-
117
-		if(is_string($schedule) || $schedule instanceof Carbon)
118
-			$schedule = Schedule::byStartAt($schedule)->first();
119
-
120
-		if(!($schedule instanceof Model))
121
-			throw (new ModelNotFound)->setValues(Schedule::class);
122
-
123
-		if($schedule->model_type != self::class)
124
-			throw new DoesNotBelong;
125
-
126
-		return $schedule->delete();
127
-	}
52
+    public function schedules()
53
+    {
54
+        return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class);
55
+    }
56
+
57
+    /**
58
+     * Agenda um horário para esta model.
59
+     *
60
+     * @param string|\Carbon\Carbon $start_at	Data em que será agendado, pode ser em string ou em numa classe Carbon.
61
+     * @param string|\Carbon\Carbon|int $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon
62
+     *                                           ou em int(sendo considerado os minutos de duração).
63
+     * @param int $status	Status desse horário ao ser agendado.
64
+     * @return \H4ad\Scheduler\Models\Schedule
65
+     *
66
+     * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
67
+     * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
68
+     * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
69
+     */
70
+    public function addSchedule($start_at, $end_at = null, $status = null)
71
+    {
72
+        if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
73
+            throw new CantAddWithoutEnd;
74
+
75
+        if(is_string($start_at))
76
+            $start_at = Carbon::parse($start_at);
77
+
78
+        if(is_string($end_at))
79
+            $end_at = Carbon::parse($end_at);
80
+
81
+        if(is_int($end_at))
82
+            $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at);
83
+
84
+        if(Config::get('scheduler.enable_schedule_conflict'))
85
+            if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at))
86
+                throw new CantAddWithSameStartAt;
87
+
88
+        if($start_at->greaterThan($end_at) && !is_null($end_at))
89
+            throw new EndCantBeforeStart;
90
+
91
+        $model_id = $this->getKey();
92
+        $model_type = self::class;
93
+
94
+        return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type'));
95
+    }
96
+
97
+    /**
98
+     * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
99
+     * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção
100
+     * se for tentado remover um horário agendado pela data de quando foi marcado.
101
+     *
102
+     * @param  int|string|\Carbon\Carbon $schedule    Horário agendado.
103
+     * @return bool|null
104
+     *
105
+     * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong
106
+     * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
107
+     * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
108
+     */
109
+    public function removeSchedule($schedule)
110
+    {
111
+        if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
112
+            throw new CantRemoveByDate;
113
+
114
+        if(is_int($schedule))
115
+            $schedule = Schedule::find($schedule);
116
+
117
+        if(is_string($schedule) || $schedule instanceof Carbon)
118
+            $schedule = Schedule::byStartAt($schedule)->first();
119
+
120
+        if(!($schedule instanceof Model))
121
+            throw (new ModelNotFound)->setValues(Schedule::class);
122
+
123
+        if($schedule->model_type != self::class)
124
+            throw new DoesNotBelong;
125
+
126
+        return $schedule->delete();
127
+    }
128 128
 }
129 129
\ No newline at end of file
Please login to merge, or discard this patch.