| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | */ | 
| 39 | 39 | public function register() | 
| 40 | 40 |      { | 
| 41 | -        $this->app->singleton(Scheduler::class, function ($app) { | |
| 41 | +        $this->app->singleton(Scheduler::class, function($app) { | |
| 42 | 42 | return new Scheduler($app); | 
| 43 | 43 | }); | 
| 44 | 44 | |
| @@ -77,9 +77,9 @@ discard block | ||
| 77 | 77 |          $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); | 
| 78 | 78 |          $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); | 
| 79 | 79 | |
| 80 | - $livres = []; | |
| 80 | + $livres = [ ]; | |
| 81 | 81 | $today = Carbon::parse($today->toDateString()); | 
| 82 | - while($openingTime <= $closingTime) | |
| 82 | + while ($openingTime <= $closingTime) | |
| 83 | 83 |          { | 
| 84 | 84 | $add = true; | 
| 85 | 85 | |
| @@ -87,20 +87,20 @@ discard block | ||
| 87 | 87 | $start = Carbon::parse($schedule->start_at); | 
| 88 | 88 | $begin = Carbon::parse($start->toDateString()); | 
| 89 | 89 | |
| 90 | - if($begin->greaterThan($today)) | |
| 90 | + if ($begin->greaterThan($today)) | |
| 91 | 91 | break; | 
| 92 | 92 | |
| 93 | - if($begin->notEqualTo($today)) | |
| 93 | + if ($begin->notEqualTo($today)) | |
| 94 | 94 | continue; | 
| 95 | 95 | |
| 96 | 96 | $end = Carbon::parse($schedule->end_at); | 
| 97 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) | |
| 97 | + if ($start <= Carbon::parse($openingTime->toDateTimeString()) | |
| 98 | 98 | && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) | 
| 99 | 99 | $add = false; | 
| 100 | 100 | } | 
| 101 | 101 | |
| 102 | - if($add) | |
| 103 | - $livres[] = [ | |
| 102 | + if ($add) | |
| 103 | + $livres[ ] = [ | |
| 104 | 104 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), | 
| 105 | 105 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) | 
| 106 | 106 | ]; | 
| @@ -87,23 +87,27 @@ | ||
| 87 | 87 | $start = Carbon::parse($schedule->start_at); | 
| 88 | 88 | $begin = Carbon::parse($start->toDateString()); | 
| 89 | 89 | |
| 90 | - if($begin->greaterThan($today)) | |
| 91 | - break; | |
| 90 | +                if($begin->greaterThan($today)) { | |
| 91 | + break; | |
| 92 | + } | |
| 92 | 93 | |
| 93 | - if($begin->notEqualTo($today)) | |
| 94 | - continue; | |
| 94 | +                if($begin->notEqualTo($today)) { | |
| 95 | + continue; | |
| 96 | + } | |
| 95 | 97 | |
| 96 | 98 | $end = Carbon::parse($schedule->end_at); | 
| 97 | 99 | if($start <= Carbon::parse($openingTime->toDateTimeString()) | 
| 98 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) | |
| 99 | - $add = false; | |
| 100 | +                && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { | |
| 101 | + $add = false; | |
| 102 | + } | |
| 100 | 103 | } | 
| 101 | 104 | |
| 102 | - if($add) | |
| 103 | - $livres[] = [ | |
| 105 | +            if($add) { | |
| 106 | + $livres[] = [ | |
| 104 | 107 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), | 
| 105 | 108 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) | 
| 106 | 109 | ]; | 
| 110 | + } | |
| 107 | 111 | |
| 108 | 112 | $openingTime->addMinutes($durationMinutes); | 
| 109 | 113 | } | 
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | */ | 
| 23 | 23 | public function up() | 
| 24 | 24 |      { | 
| 25 | -        Schema::create(Config::get('scheduler.schedule_status_table'), function (Blueprint $table) { | |
| 25 | +        Schema::create(Config::get('scheduler.schedule_status_table'), function(Blueprint $table) { | |
| 26 | 26 |              $table->increments('id'); | 
| 27 | 27 |              $table->string('name')->unique(); | 
| 28 | 28 |              $table->text('description')->nullable(); | 
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | */ | 
| 23 | 23 | public function up() | 
| 24 | 24 |      { | 
| 25 | -        Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { | |
| 25 | +        Schema::create(Config::get('scheduler.schedules_table'), function(Blueprint $table) { | |
| 26 | 26 |              $table->increments('id'); | 
| 27 | 27 |              $table->string('model_type'); | 
| 28 | 28 |              $table->integer('model_id'); | 
| @@ -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 | } | 
| @@ -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 | } | 
| @@ -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 | |
| @@ -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 | } |