Passed
Push — master ( a20c82...390b23 )
by Vinicius Lourenço
04:01
created
src/Scheduler/Models/Schedule.php 3 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -19,67 +19,67 @@
 block discarded – undo
19 19
  */
20 20
 class Schedule extends Model
21 21
 {
22
-    use SoftDeletes;
22
+	use SoftDeletes;
23 23
 
24 24
 	/**
25
-     * Os atributos que podem ser atribuíveis em massa.
26
-     *
27
-     * @var array
28
-     */
29
-    protected $fillable = [
30
-    	'model_type', 'model_id', 'start_at', 'end_at', 'status'
31
-    ];
25
+	 * Os atributos que podem ser atribuíveis em massa.
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $fillable = [
30
+		'model_type', 'model_id', 'start_at', 'end_at', 'status'
31
+	];
32 32
 
33
-    /**
34
-     * Os atributos que devem ser transformados para data.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $dates = [
39
-    	'start_at', 'end_at', 'deleted_at'
40
-    ];
33
+	/**
34
+	 * Os atributos que devem ser transformados para data.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $dates = [
39
+		'start_at', 'end_at', 'deleted_at'
40
+	];
41 41
 
42
-    /**
43
-     * Seta um status para o horário agendado.
44
-     *
45
-     * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário.
46
-     */
47
-    public function setStatus($name)
48
-    {
49
-    	$this->fill($this->parseStatusKey($name))->save();
50
-    }
42
+	/**
43
+	 * Seta um status para o horário agendado.
44
+	 *
45
+	 * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário.
46
+	 */
47
+	public function setStatus($name)
48
+	{
49
+		$this->fill($this->parseStatusKey($name))->save();
50
+	}
51 51
 
52
-    /**
53
-     * Retorna o ID do status caso passem o nome do status.
54
-     *
55
-     * @param  int|string $status ID ou o nome do status.
56
-     * @return array
57
-     *
58
-     * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
59
-     */
60
-    public function parseStatusKey($status)
61
-    {
62
-    	if(is_int($status))
63
-    		$status =  ScheduleStatus::find($status);
52
+	/**
53
+	 * Retorna o ID do status caso passem o nome do status.
54
+	 *
55
+	 * @param  int|string $status ID ou o nome do status.
56
+	 * @return array
57
+	 *
58
+	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
59
+	 */
60
+	public function parseStatusKey($status)
61
+	{
62
+		if(is_int($status))
63
+			$status =  ScheduleStatus::find($status);
64 64
 
65
-        if(is_string($status))
66
-        	$status = ScheduleStatus::where('name', $status)->first();
65
+		if(is_string($status))
66
+			$status = ScheduleStatus::where('name', $status)->first();
67 67
 
68
-    	if(is_null($status))
69
-    		throw (new ModelNotFound)->setValues(ScheduleStatus::class);
68
+		if(is_null($status))
69
+			throw (new ModelNotFound)->setValues(ScheduleStatus::class);
70 70
 
71
-    	return ['status' => $status->id];
72
-    }
71
+		return ['status' => $status->id];
72
+	}
73 73
 
74
-    /**
75
-     * Escopo de uma consulta que busca horarios pela data de início.
76
-     *
77
-     * @param \Illuminate\Database\Eloquent\Builder $query
78
-     * @param \Carbon\Carbon|string $start_at
79
-     * @return \Illuminate\Database\Eloquent\Builder
80
-     */
81
-    public function scopeByStartAt($query, $start_at)
82
-    {
83
-        return $query->where('start_at', $start_at);
84
-    }
74
+	/**
75
+	 * Escopo de uma consulta que busca horarios pela data de início.
76
+	 *
77
+	 * @param \Illuminate\Database\Eloquent\Builder $query
78
+	 * @param \Carbon\Carbon|string $start_at
79
+	 * @return \Illuminate\Database\Eloquent\Builder
80
+	 */
81
+	public function scopeByStartAt($query, $start_at)
82
+	{
83
+		return $query->where('start_at', $start_at);
84
+	}
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário.
46 46
      */
47
-    public function setStatus($name)
47
+    public function setStatus ($name)
48 48
     {
49 49
     	$this->fill($this->parseStatusKey($name))->save();
50 50
     }
@@ -57,18 +57,18 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
59 59
      */
60
-    public function parseStatusKey($status)
60
+    public function parseStatusKey ($status)
61 61
     {
62
-    	if(is_int($status))
63
-    		$status =  ScheduleStatus::find($status);
62
+    	if (is_int($status))
63
+    		$status = ScheduleStatus::find($status);
64 64
 
65
-        if(is_string($status))
65
+        if (is_string($status))
66 66
         	$status = ScheduleStatus::where('name', $status)->first();
67 67
 
68
-    	if(is_null($status))
68
+    	if (is_null($status))
69 69
     		throw (new ModelNotFound)->setValues(ScheduleStatus::class);
70 70
 
71
-    	return ['status' => $status->id];
71
+    	return [ 'status' => $status->id ];
72 72
     }
73 73
 
74 74
     /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      * @param \Carbon\Carbon|string $start_at
79 79
      * @return \Illuminate\Database\Eloquent\Builder
80 80
      */
81
-    public function scopeByStartAt($query, $start_at)
81
+    public function scopeByStartAt ($query, $start_at)
82 82
     {
83 83
         return $query->where('start_at', $start_at);
84 84
     }
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,14 +59,17 @@
 block discarded – undo
59 59
      */
60 60
     public function parseStatusKey($status)
61 61
     {
62
-    	if(is_int($status))
63
-    		$status =  ScheduleStatus::find($status);
62
+    	if(is_int($status)) {
63
+    	    		$status =  ScheduleStatus::find($status);
64
+    	}
64 65
 
65
-        if(is_string($status))
66
-        	$status = ScheduleStatus::where('name', $status)->first();
66
+        if(is_string($status)) {
67
+                	$status = ScheduleStatus::where('name', $status)->first();
68
+        }
67 69
 
68
-    	if(is_null($status))
69
-    		throw (new ModelNotFound)->setValues(ScheduleStatus::class);
70
+    	if(is_null($status)) {
71
+    	    		throw (new ModelNotFound)->setValues(ScheduleStatus::class);
72
+    	}
70 73
 
71 74
     	return ['status' => $status->id];
72 75
     }
Please login to merge, or discard this patch.
src/Scheduler/Scheduler.php 3 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -14,126 +14,126 @@
 block discarded – undo
14 14
 
15 15
 class Scheduler
16 16
 {
17
-    /**
18
-     * Laravel application
19
-     *
20
-     * @var \Illuminate\Foundation\Application
21
-     */
22
-    public $app;
23
-
24
-    /**
25
-     * Create a new confide instance.
26
-     *
27
-     * @param \Illuminate\Foundation\Application $app
28
-     *
29
-     * @return void
30
-     */
31
-    public function __construct($app)
32
-    {
33
-        $this->app = $app;
34
-    }
35
-
36
-    /**
37
-     * Escopo de uma consulta que busca horarios pela data de início.
38
-     *
39
-     * @param string $model_type
40
-     * @param string|\Carbon\Carbon $start_at
41
-     * @param string|\Carbon\Carbon $end_at
42
-     * @return bool
43
-     */
44
-    public function hasScheduleBetween($model_type, $start_at, $end_at)
45
-    {
46
-        if(!Config::get('scheduler.enable_schedule_conflict'))
47
-            return false;
48
-
49
-        return !is_null(
50
-            Schedule::latest()
51
-                ->where('model_type', $model_type)
52
-                ->where('start_at', '>=', $start_at)
53
-                ->where('end_at', '<=', $end_at)
54
-                ->first()
55
-        );
56
-    }
57
-
58
-    /**
59
-     * Retorna os horários disponiveis hoje para uma determinada model.
60
-     * .
61
-     * @param  string  $model_type Tipo da model
62
-     * @param  int    $duration Serve para facilitar na hora de buscar horários livres
63
-     *                          que precisem ter uma certa duração.
64
-     * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres.
65
-     *                                         Se for nulo, ele busca a referencia da config.
66
-     * @return array
67
-     */
68
-    public function availableToday($model_type, $duration, $openingTime = null)
69
-    {
70
-        return $this->availableOn($model_type, Carbon::now(), $duration, $openingTime);
71
-    }
72
-
73
-    /**
74
-     * Retorna os horários disponiveis em um determinado dia para uma certa model.
75
-     *
76
-     * @param  string  $model_type Tipo da model
77
-     * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
78
-     * @param  int    $durationMinutes Serve para facilitar na hora de buscar horários livres
79
-     *                          que precisem ter uma certa duração.
80
-     * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres.
81
-     *                                         Se for nulo, ele busca a referencia da config.
82
-     * @return array
83
-     */
84
-    public function availableOn($model_type, $today, $durationMinutes, $openingTime = null)
85
-    {
86
-        $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
87
-        $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
88
-
89
-        $livres = [];
90
-        $today = Carbon::parse($today->toDateString());
91
-        while($openingTime <= $closingTime)
92
-        {
93
-            $add = true;
94
-
95
-            $opening = Carbon::parse($openingTime->toDateTimeString());
96
-            $closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
97
-
98
-            foreach (Schedule::where('model_type', $model_type)->orderBy('start_at', 'DESC')->cursor() as $schedule) {
99
-                $start = Carbon::parse($schedule->start_at);
100
-                $begin = Carbon::parse($start->toDateString());
101
-
102
-                if($begin->greaterThan($today))
103
-                    break;
104
-
105
-                if($begin->notEqualTo($today))
106
-                    continue;
107
-
108
-                $end = Carbon::parse($schedule->end_at);
109
-
110
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
111
-                    $add = false;
112
-            }
113
-
114
-            if($add && $closing->lessThanOrEqualTo($closingTime))
115
-                $livres[] = [
116
-                    'start_at' => $opening,
117
-                    'end_at' => $closing
118
-                ];
119
-
120
-            $openingTime->addMinutes($durationMinutes);
121
-        }
122
-
123
-        return $livres;
124
-    }
125
-
126
-    /**
127
-     * Verifica se ele não deve ser adicionado ao array de horários livres.
128
-     *
129
-     * @param  \Carbon\Carbon  $opening
130
-     * @param  \Carbon\Carbon  $closing
131
-     * @param  \Carbon\Carbon  $start
132
-     * @param  \Carbon\Carbon  $end
133
-     * @return boolean
134
-     */
135
-    private function isShouldntAdd($opening, $closing, $start, $end)
136
-    {
137
-        return $start <= $opening && $end >= $closing;
138
-    }
17
+	/**
18
+	 * Laravel application
19
+	 *
20
+	 * @var \Illuminate\Foundation\Application
21
+	 */
22
+	public $app;
23
+
24
+	/**
25
+	 * Create a new confide instance.
26
+	 *
27
+	 * @param \Illuminate\Foundation\Application $app
28
+	 *
29
+	 * @return void
30
+	 */
31
+	public function __construct($app)
32
+	{
33
+		$this->app = $app;
34
+	}
35
+
36
+	/**
37
+	 * Escopo de uma consulta que busca horarios pela data de início.
38
+	 *
39
+	 * @param string $model_type
40
+	 * @param string|\Carbon\Carbon $start_at
41
+	 * @param string|\Carbon\Carbon $end_at
42
+	 * @return bool
43
+	 */
44
+	public function hasScheduleBetween($model_type, $start_at, $end_at)
45
+	{
46
+		if(!Config::get('scheduler.enable_schedule_conflict'))
47
+			return false;
48
+
49
+		return !is_null(
50
+			Schedule::latest()
51
+				->where('model_type', $model_type)
52
+				->where('start_at', '>=', $start_at)
53
+				->where('end_at', '<=', $end_at)
54
+				->first()
55
+		);
56
+	}
57
+
58
+	/**
59
+	 * Retorna os horários disponiveis hoje para uma determinada model.
60
+	 * .
61
+	 * @param  string  $model_type Tipo da model
62
+	 * @param  int    $duration Serve para facilitar na hora de buscar horários livres
63
+	 *                          que precisem ter uma certa duração.
64
+	 * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres.
65
+	 *                                         Se for nulo, ele busca a referencia da config.
66
+	 * @return array
67
+	 */
68
+	public function availableToday($model_type, $duration, $openingTime = null)
69
+	{
70
+		return $this->availableOn($model_type, Carbon::now(), $duration, $openingTime);
71
+	}
72
+
73
+	/**
74
+	 * Retorna os horários disponiveis em um determinado dia para uma certa model.
75
+	 *
76
+	 * @param  string  $model_type Tipo da model
77
+	 * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
78
+	 * @param  int    $durationMinutes Serve para facilitar na hora de buscar horários livres
79
+	 *                          que precisem ter uma certa duração.
80
+	 * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres.
81
+	 *                                         Se for nulo, ele busca a referencia da config.
82
+	 * @return array
83
+	 */
84
+	public function availableOn($model_type, $today, $durationMinutes, $openingTime = null)
85
+	{
86
+		$openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
87
+		$closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
88
+
89
+		$livres = [];
90
+		$today = Carbon::parse($today->toDateString());
91
+		while($openingTime <= $closingTime)
92
+		{
93
+			$add = true;
94
+
95
+			$opening = Carbon::parse($openingTime->toDateTimeString());
96
+			$closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
97
+
98
+			foreach (Schedule::where('model_type', $model_type)->orderBy('start_at', 'DESC')->cursor() as $schedule) {
99
+				$start = Carbon::parse($schedule->start_at);
100
+				$begin = Carbon::parse($start->toDateString());
101
+
102
+				if($begin->greaterThan($today))
103
+					break;
104
+
105
+				if($begin->notEqualTo($today))
106
+					continue;
107
+
108
+				$end = Carbon::parse($schedule->end_at);
109
+
110
+				if($this->isShouldntAdd($opening, $closing, $start, $end))
111
+					$add = false;
112
+			}
113
+
114
+			if($add && $closing->lessThanOrEqualTo($closingTime))
115
+				$livres[] = [
116
+					'start_at' => $opening,
117
+					'end_at' => $closing
118
+				];
119
+
120
+			$openingTime->addMinutes($durationMinutes);
121
+		}
122
+
123
+		return $livres;
124
+	}
125
+
126
+	/**
127
+	 * Verifica se ele não deve ser adicionado ao array de horários livres.
128
+	 *
129
+	 * @param  \Carbon\Carbon  $opening
130
+	 * @param  \Carbon\Carbon  $closing
131
+	 * @param  \Carbon\Carbon  $start
132
+	 * @param  \Carbon\Carbon  $end
133
+	 * @return boolean
134
+	 */
135
+	private function isShouldntAdd($opening, $closing, $start, $end)
136
+	{
137
+		return $start <= $opening && $end >= $closing;
138
+	}
139 139
 }
140 140
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 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,14 +81,14 @@  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
         $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
87 87
         $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
88 88
 
89
-        $livres = [];
89
+        $livres = [ ];
90 90
         $today = Carbon::parse($today->toDateString());
91
-        while($openingTime <= $closingTime)
91
+        while ($openingTime <= $closingTime)
92 92
         {
93 93
             $add = true;
94 94
 
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
                 $start = Carbon::parse($schedule->start_at);
100 100
                 $begin = Carbon::parse($start->toDateString());
101 101
 
102
-                if($begin->greaterThan($today))
102
+                if ($begin->greaterThan($today))
103 103
                     break;
104 104
 
105
-                if($begin->notEqualTo($today))
105
+                if ($begin->notEqualTo($today))
106 106
                     continue;
107 107
 
108 108
                 $end = Carbon::parse($schedule->end_at);
109 109
 
110
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
110
+                if ($this->isShouldntAdd($opening, $closing, $start, $end))
111 111
                     $add = false;
112 112
             }
113 113
 
114
-            if($add && $closing->lessThanOrEqualTo($closingTime))
115
-                $livres[] = [
114
+            if ($add && $closing->lessThanOrEqualTo($closingTime))
115
+                $livres[ ] = [
116 116
                     'start_at' => $opening,
117 117
                     'end_at' => $closing
118 118
                 ];
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      * @param  \Carbon\Carbon  $end
133 133
      * @return boolean
134 134
      */
135
-    private function isShouldntAdd($opening, $closing, $start, $end)
135
+    private function isShouldntAdd ($opening, $closing, $start, $end)
136 136
     {
137 137
         return $start <= $opening && $end >= $closing;
138 138
     }
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 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()
@@ -99,23 +100,27 @@  discard block
 block discarded – undo
99 100
                 $start = Carbon::parse($schedule->start_at);
100 101
                 $begin = Carbon::parse($start->toDateString());
101 102
 
102
-                if($begin->greaterThan($today))
103
-                    break;
103
+                if($begin->greaterThan($today)) {
104
+                                    break;
105
+                }
104 106
 
105
-                if($begin->notEqualTo($today))
106
-                    continue;
107
+                if($begin->notEqualTo($today)) {
108
+                                    continue;
109
+                }
107 110
 
108 111
                 $end = Carbon::parse($schedule->end_at);
109 112
 
110
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
111
-                    $add = false;
113
+                if($this->isShouldntAdd($opening, $closing, $start, $end)) {
114
+                                    $add = false;
115
+                }
112 116
             }
113 117
 
114
-            if($add && $closing->lessThanOrEqualTo($closingTime))
115
-                $livres[] = [
118
+            if($add && $closing->lessThanOrEqualTo($closingTime)) {
119
+                            $livres[] = [
116 120
                     'start_at' => $opening,
117 121
                     'end_at' => $closing
118 122
                 ];
123
+            }
119 124
 
120 125
             $openingTime->addMinutes($durationMinutes);
121 126
         }
Please login to merge, or discard this patch.