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