@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public function render() |
78 | 78 | { |
79 | 79 | return response()->json([ |
80 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
80 | + 'messages' => trans('scheduler::exceptions.'.$this->trans, $this->parseValues()) |
|
81 | 81 | ], $this->statusCode); |
82 | 82 | } |
83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function parseValues() |
90 | 90 | { |
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
91 | + if (is_array($this->attributes) && is_array($this->values)) |
|
92 | 92 | return collect($this->attributes)->combine($this->values)->all(); |
93 | 93 | |
94 | 94 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function getAlias() |
113 | 113 | { |
114 | - if(is_object($this->model)) |
|
114 | + if (is_object($this->model)) |
|
115 | 115 | $this->model = get_class($this->model); |
116 | 116 | |
117 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
117 | + return collect(trans('scheduler::exceptions.aliases.'.$this->aliastype))->search($this->model) ?: 'Recurso'; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -88,8 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function parseValues() |
90 | 90 | { |
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
92 | - return collect($this->attributes)->combine($this->values)->all(); |
|
91 | + if(is_array($this->attributes) && is_array($this->values)) { |
|
92 | + return collect($this->attributes)->combine($this->values)->all(); |
|
93 | + } |
|
93 | 94 | |
94 | 95 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
95 | 96 | } |
@@ -111,8 +112,9 @@ discard block |
||
111 | 112 | */ |
112 | 113 | protected function getAlias() |
113 | 114 | { |
114 | - if(is_object($this->model)) |
|
115 | - $this->model = get_class($this->model); |
|
115 | + if(is_object($this->model)) { |
|
116 | + $this->model = get_class($this->model); |
|
117 | + } |
|
116 | 118 | |
117 | 119 | return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
118 | 120 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | class CantAddWithSameStartAt extends CustomException |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritDoc} |
|
18 | - */ |
|
19 | - protected $trans = 'cant_add_with_same_start_at'; |
|
16 | + /** |
|
17 | + * {@inheritDoc} |
|
18 | + */ |
|
19 | + protected $trans = 'cant_add_with_same_start_at'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - */ |
|
24 | - protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + */ |
|
24 | + protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -13,13 +13,13 @@ |
||
13 | 13 | class DoesNotBelong extends CustomException |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritDoc} |
|
18 | - */ |
|
19 | - protected $trans = 'does_not_belong'; |
|
16 | + /** |
|
17 | + * {@inheritDoc} |
|
18 | + */ |
|
19 | + protected $trans = 'does_not_belong'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - */ |
|
24 | - protected $statusCode = Response::HTTP_FORBIDDEN; |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + */ |
|
24 | + protected $statusCode = Response::HTTP_FORBIDDEN; |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -13,13 +13,13 @@ |
||
13 | 13 | class CantAddWithoutEnd extends CustomException |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritDoc} |
|
18 | - */ |
|
19 | - protected $trans = 'cant_add_without_end'; |
|
16 | + /** |
|
17 | + * {@inheritDoc} |
|
18 | + */ |
|
19 | + protected $trans = 'cant_add_without_end'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - */ |
|
24 | - protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + */ |
|
24 | + protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | { |
16 | 16 | use SoftDeletes; |
17 | 17 | |
18 | - /** |
|
18 | + /** |
|
19 | 19 | * Os atributos que podem ser atribuíveis em massa. |
20 | 20 | * |
21 | 21 | * @var array |
22 | 22 | */ |
23 | 23 | protected $fillable = [ |
24 | - 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
24 | + 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
25 | 25 | ]; |
26 | 26 | |
27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @var array |
31 | 31 | */ |
32 | 32 | protected $dates = [ |
33 | - 'start_at', 'end_at', 'deleted_at' |
|
33 | + 'start_at', 'end_at', 'deleted_at' |
|
34 | 34 | ]; |
35 | 35 | |
36 | 36 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function setStatus($name) |
42 | 42 | { |
43 | - $this->fill($this->parseStatusKey($name))->save(); |
|
43 | + $this->fill($this->parseStatusKey($name))->save(); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function parseStatusKey($key) |
53 | 53 | { |
54 | - if(is_int($key)) |
|
55 | - return ['status' => $key]; |
|
54 | + if(is_int($key)) |
|
55 | + return ['status' => $key]; |
|
56 | 56 | |
57 | - $status = ScheduleStatus::where('name', $name)->first(); |
|
57 | + $status = ScheduleStatus::where('name', $name)->first(); |
|
58 | 58 | |
59 | - if(is_null($status)) |
|
60 | - throw (new ModelNotFoundException)->setModel(ScheduleStatus::class, $name); |
|
59 | + if(is_null($status)) |
|
60 | + throw (new ModelNotFoundException)->setModel(ScheduleStatus::class, $name); |
|
61 | 61 | |
62 | - return ['status' => $status->id]; |
|
62 | + return ['status' => $status->id]; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -51,15 +51,15 @@ |
||
51 | 51 | */ |
52 | 52 | public function parseStatusKey($key) |
53 | 53 | { |
54 | - if(is_int($key)) |
|
55 | - return ['status' => $key]; |
|
54 | + if (is_int($key)) |
|
55 | + return [ 'status' => $key ]; |
|
56 | 56 | |
57 | 57 | $status = ScheduleStatus::where('name', $name)->first(); |
58 | 58 | |
59 | - if(is_null($status)) |
|
59 | + if (is_null($status)) |
|
60 | 60 | throw (new ModelNotFoundException)->setModel(ScheduleStatus::class, $name); |
61 | 61 | |
62 | - return ['status' => $status->id]; |
|
62 | + return [ 'status' => $status->id ]; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -51,13 +51,15 @@ |
||
51 | 51 | */ |
52 | 52 | public function parseStatusKey($key) |
53 | 53 | { |
54 | - if(is_int($key)) |
|
55 | - return ['status' => $key]; |
|
54 | + if(is_int($key)) { |
|
55 | + return ['status' => $key]; |
|
56 | + } |
|
56 | 57 | |
57 | 58 | $status = ScheduleStatus::where('name', $name)->first(); |
58 | 59 | |
59 | - if(is_null($status)) |
|
60 | - throw (new ModelNotFoundException)->setModel(ScheduleStatus::class, $name); |
|
60 | + if(is_null($status)) { |
|
61 | + throw (new ModelNotFoundException)->setModel(ScheduleStatus::class, $name); |
|
62 | + } |
|
61 | 63 | |
62 | 64 | return ['status' => $status->id]; |
63 | 65 | } |
@@ -16,13 +16,13 @@ discard block |
||
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 | - 'name', 'description' |
|
25 | + 'name', 'description' |
|
26 | 26 | ]; |
27 | 27 | |
28 | 28 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @var array |
32 | 32 | */ |
33 | 33 | protected $dates = [ |
34 | - 'deleted_at' |
|
34 | + 'deleted_at' |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | /** |
@@ -37,7 +37,7 @@ |
||
37 | 37 | /** |
38 | 38 | * Construtor para inicilizar a váriavel table. |
39 | 39 | */ |
40 | - public function __construct(array $attributes = []) |
|
40 | + public function __construct(array $attributes = [ ]) |
|
41 | 41 | { |
42 | 42 | parent::__construct($attributes); |
43 | 43 |
@@ -26,85 +26,85 @@ |
||
26 | 26 | */ |
27 | 27 | trait SchedulerModelTrait |
28 | 28 | { |
29 | - /** |
|
29 | + /** |
|
30 | 30 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
31 | 31 | * |
32 | 32 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
33 | 33 | */ |
34 | - public function schedules() |
|
35 | - { |
|
36 | - return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Agenda um horário para esta model. |
|
41 | - * |
|
42 | - * @param string|Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
43 | - * @param string|Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
44 | - * ou em int(sendo considerado os minutos de duração). |
|
45 | - * @param int $status Status desse horário ao ser agendado. |
|
46 | - * @return \H4ad\Scheduler\Models\Schedule |
|
47 | - * |
|
48 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
49 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
50 | - * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
51 | - */ |
|
52 | - public function addSchedule($start_at, $end_at = null, $status = null) |
|
53 | - { |
|
54 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | - throw new CantAddWithoutEnd; |
|
56 | - |
|
57 | - if(is_string($start_at)) |
|
58 | - $start_at = Carbon::parse($start_at); |
|
59 | - |
|
60 | - if(is_string($end_at)) |
|
61 | - $end_at = Carbon::parse($end_at); |
|
62 | - |
|
63 | - if(is_int($end_at)) |
|
64 | - $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
65 | - |
|
66 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | - throw new CantAddWithSameStartAt; |
|
69 | - |
|
70 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | - throw new EndCantBeforeStart; |
|
72 | - |
|
73 | - $model_id = $this->getKey(); |
|
74 | - $model_type = self::class; |
|
75 | - |
|
76 | - return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type')); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
81 | - * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
82 | - * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
83 | - * |
|
84 | - * @param int|string|Carbon\Carbon $schedule Horário agendado. |
|
85 | - * @return bool|null |
|
86 | - * |
|
87 | - * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
88 | - * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
89 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
90 | - */ |
|
91 | - public function removeSchedule($schedule) |
|
92 | - { |
|
93 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | - throw new CantRemoveByDate; |
|
95 | - |
|
96 | - if(is_int($schedule)) |
|
97 | - $schedule = Schedule::find($schedule); |
|
98 | - |
|
99 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
100 | - $schedule = Schedule::byStartAt($schedule)->first(); |
|
101 | - |
|
102 | - if(!($schedule instanceof Model)) |
|
103 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
104 | - |
|
105 | - if($schedule->model_type != self::class) |
|
106 | - throw new DoesNotBelong; |
|
107 | - |
|
108 | - return $schedule->delete(); |
|
109 | - } |
|
34 | + public function schedules() |
|
35 | + { |
|
36 | + return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Agenda um horário para esta model. |
|
41 | + * |
|
42 | + * @param string|Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
43 | + * @param string|Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
44 | + * ou em int(sendo considerado os minutos de duração). |
|
45 | + * @param int $status Status desse horário ao ser agendado. |
|
46 | + * @return \H4ad\Scheduler\Models\Schedule |
|
47 | + * |
|
48 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
49 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
50 | + * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
51 | + */ |
|
52 | + public function addSchedule($start_at, $end_at = null, $status = null) |
|
53 | + { |
|
54 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | + throw new CantAddWithoutEnd; |
|
56 | + |
|
57 | + if(is_string($start_at)) |
|
58 | + $start_at = Carbon::parse($start_at); |
|
59 | + |
|
60 | + if(is_string($end_at)) |
|
61 | + $end_at = Carbon::parse($end_at); |
|
62 | + |
|
63 | + if(is_int($end_at)) |
|
64 | + $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
65 | + |
|
66 | + if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | + if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | + throw new CantAddWithSameStartAt; |
|
69 | + |
|
70 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | + throw new EndCantBeforeStart; |
|
72 | + |
|
73 | + $model_id = $this->getKey(); |
|
74 | + $model_type = self::class; |
|
75 | + |
|
76 | + return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type')); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
81 | + * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
82 | + * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
83 | + * |
|
84 | + * @param int|string|Carbon\Carbon $schedule Horário agendado. |
|
85 | + * @return bool|null |
|
86 | + * |
|
87 | + * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
88 | + * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
89 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
90 | + */ |
|
91 | + public function removeSchedule($schedule) |
|
92 | + { |
|
93 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | + throw new CantRemoveByDate; |
|
95 | + |
|
96 | + if(is_int($schedule)) |
|
97 | + $schedule = Schedule::find($schedule); |
|
98 | + |
|
99 | + if(is_string($schedule) || $schedule instanceof Carbon) |
|
100 | + $schedule = Schedule::byStartAt($schedule)->first(); |
|
101 | + |
|
102 | + if(!($schedule instanceof Model)) |
|
103 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
104 | + |
|
105 | + if($schedule->model_type != self::class) |
|
106 | + throw new DoesNotBelong; |
|
107 | + |
|
108 | + return $schedule->delete(); |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | \ No newline at end of file |
@@ -51,23 +51,23 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function addSchedule($start_at, $end_at = null, $status = null) |
53 | 53 | { |
54 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
54 | + if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | 55 | throw new CantAddWithoutEnd; |
56 | 56 | |
57 | - if(is_string($start_at)) |
|
57 | + if (is_string($start_at)) |
|
58 | 58 | $start_at = Carbon::parse($start_at); |
59 | 59 | |
60 | - if(is_string($end_at)) |
|
60 | + if (is_string($end_at)) |
|
61 | 61 | $end_at = Carbon::parse($end_at); |
62 | 62 | |
63 | - if(is_int($end_at)) |
|
63 | + if (is_int($end_at)) |
|
64 | 64 | $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
65 | 65 | |
66 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
66 | + if (Config::get('scheduler.enable_schedule_conflict')) |
|
67 | + if (Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | 68 | throw new CantAddWithSameStartAt; |
69 | 69 | |
70 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
70 | + if ($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | 71 | throw new EndCantBeforeStart; |
72 | 72 | |
73 | 73 | $model_id = $this->getKey(); |
@@ -90,19 +90,19 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function removeSchedule($schedule) |
92 | 92 | { |
93 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
93 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | 94 | throw new CantRemoveByDate; |
95 | 95 | |
96 | - if(is_int($schedule)) |
|
96 | + if (is_int($schedule)) |
|
97 | 97 | $schedule = Schedule::find($schedule); |
98 | 98 | |
99 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
99 | + if (is_string($schedule) || $schedule instanceof Carbon) |
|
100 | 100 | $schedule = Schedule::byStartAt($schedule)->first(); |
101 | 101 | |
102 | - if(!($schedule instanceof Model)) |
|
102 | + if (!($schedule instanceof Model)) |
|
103 | 103 | throw (new ModelNotFound)->setValues(Schedule::class); |
104 | 104 | |
105 | - if($schedule->model_type != self::class) |
|
105 | + if ($schedule->model_type != self::class) |
|
106 | 106 | throw new DoesNotBelong; |
107 | 107 | |
108 | 108 | return $schedule->delete(); |
@@ -51,24 +51,30 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function addSchedule($start_at, $end_at = null, $status = null) |
53 | 53 | { |
54 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | - throw new CantAddWithoutEnd; |
|
54 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
55 | + throw new CantAddWithoutEnd; |
|
56 | + } |
|
56 | 57 | |
57 | - if(is_string($start_at)) |
|
58 | - $start_at = Carbon::parse($start_at); |
|
58 | + if(is_string($start_at)) { |
|
59 | + $start_at = Carbon::parse($start_at); |
|
60 | + } |
|
59 | 61 | |
60 | - if(is_string($end_at)) |
|
61 | - $end_at = Carbon::parse($end_at); |
|
62 | + if(is_string($end_at)) { |
|
63 | + $end_at = Carbon::parse($end_at); |
|
64 | + } |
|
62 | 65 | |
63 | - if(is_int($end_at)) |
|
64 | - $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
66 | + if(is_int($end_at)) { |
|
67 | + $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
68 | + } |
|
65 | 69 | |
66 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
70 | + if(Config::get('scheduler.enable_schedule_conflict')) { |
|
71 | + if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | 72 | throw new CantAddWithSameStartAt; |
73 | + } |
|
69 | 74 | |
70 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | - throw new EndCantBeforeStart; |
|
75 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) { |
|
76 | + throw new EndCantBeforeStart; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | $model_id = $this->getKey(); |
74 | 80 | $model_type = self::class; |
@@ -90,20 +96,25 @@ discard block |
||
90 | 96 | */ |
91 | 97 | public function removeSchedule($schedule) |
92 | 98 | { |
93 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | - throw new CantRemoveByDate; |
|
99 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
100 | + throw new CantRemoveByDate; |
|
101 | + } |
|
95 | 102 | |
96 | - if(is_int($schedule)) |
|
97 | - $schedule = Schedule::find($schedule); |
|
103 | + if(is_int($schedule)) { |
|
104 | + $schedule = Schedule::find($schedule); |
|
105 | + } |
|
98 | 106 | |
99 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
100 | - $schedule = Schedule::byStartAt($schedule)->first(); |
|
107 | + if(is_string($schedule) || $schedule instanceof Carbon) { |
|
108 | + $schedule = Schedule::byStartAt($schedule)->first(); |
|
109 | + } |
|
101 | 110 | |
102 | - if(!($schedule instanceof Model)) |
|
103 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
111 | + if(!($schedule instanceof Model)) { |
|
112 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
113 | + } |
|
104 | 114 | |
105 | - if($schedule->model_type != self::class) |
|
106 | - throw new DoesNotBelong; |
|
115 | + if($schedule->model_type != self::class) { |
|
116 | + throw new DoesNotBelong; |
|
117 | + } |
|
107 | 118 | |
108 | 119 | return $schedule->delete(); |
109 | 120 | } |