Test Failed
Push — master ( b98178...2ab44c )
by Vinicius Lourenço
07:53
created
src/Scheduler/Exceptions/CustomException.php 3 patches
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -88,8 +88,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -10,124 +10,124 @@
 block discarded – undo
10 10
 
11 11
 class CustomException extends \Exception
12 12
 {
13
-    /**
14
-     * Model que não pertence ao usuário
15
-     *
16
-     * @var mixed
17
-     */
18
-    protected $model;
19
-
20
-    /**
21
-     * Key para o arquivo de tradução de exceções.
22
-     *
23
-     * @var string
24
-     */
25
-    protected $trans;
26
-
27
-    /**
28
-     * HTTP Status Code
29
-     *
30
-     * @var int
31
-     */
32
-    protected $statusCode;
33
-
34
-    /**
35
-     * Atributo usado como key para substituir por um texto.
36
-     *
37
-     * @var array|string
38
-     */
39
-    protected $attributes = 'model';
40
-
41
-    /**
42
-     * Diz se o alias será no singular ou no plural.
43
-     *
44
-     * @var string
45
-     */
46
-    protected $aliastype = 'singular';
47
-
48
-    /**
49
-     * Valor passado para o atributo
50
-     *
51
-     * @var array|string|null
52
-     */
53
-    protected $values = null;
54
-
55
-    /**
56
-     * Indica se a model será printada com lower case.
57
-     *
58
-     * @var boolean
59
-     */
60
-    protected $lowercase = false;
61
-
62
-    /**
63
-     * Construtor da exceção
64
-     *
65
-     * @param mixed $model
66
-     */
67
-    public function __construct($model = 'foo')
68
-    {
69
-        $this->model = $model;
70
-    }
71
-
72
-    /**
73
-     * Render the exception as an HTTP response.
74
-     *
75
-     * @return \Illuminate\Http\JsonResponse
76
-     */
77
-    public function render()
78
-    {
79
-        return response()->
80
-            /** @scrutinizer ignore-call */
81
-            json([
82
-            'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues())
83
-        ], $this->statusCode);
84
-    }
85
-
86
-    /**
87
-     * Dá parse nos valores para a string de tradução.
88
-     *
89
-     * @return array
90
-     */
91
-    protected function parseValues()
92
-    {
93
-        if(is_array($this->attributes) && is_array($this->values))
94
-            return collect($this->attributes)->combine($this->values)->all();
95
-
96
-        return [ $this->attributes => $this->values ?? $this->isLower() ];
97
-    }
98
-
99
-    /**
100
-     * Verifica se é lowercase e retorna de acordo.
101
-     *
102
-     * @return string
103
-     */
104
-    protected function isLower()
105
-    {
106
-        return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias();
107
-    }
108
-
109
-    /**
110
-     * Retorna o alias da model.
111
-     *
112
-     * @return string
113
-     */
114
-    protected function getAlias()
115
-    {
116
-        if(is_object($this->model))
117
-            $this->model = get_class($this->model);
118
-
119
-        return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso';
120
-    }
121
-
122
-    /**
123
-     * Seta os valores.
124
-     *
125
-     * @param mixed $values
126
-     */
127
-    public function setValues($values)
128
-    {
129
-        $this->values = $values;
130
-
131
-        return $this;
132
-    }
13
+	/**
14
+	 * Model que não pertence ao usuário
15
+	 *
16
+	 * @var mixed
17
+	 */
18
+	protected $model;
19
+
20
+	/**
21
+	 * Key para o arquivo de tradução de exceções.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected $trans;
26
+
27
+	/**
28
+	 * HTTP Status Code
29
+	 *
30
+	 * @var int
31
+	 */
32
+	protected $statusCode;
33
+
34
+	/**
35
+	 * Atributo usado como key para substituir por um texto.
36
+	 *
37
+	 * @var array|string
38
+	 */
39
+	protected $attributes = 'model';
40
+
41
+	/**
42
+	 * Diz se o alias será no singular ou no plural.
43
+	 *
44
+	 * @var string
45
+	 */
46
+	protected $aliastype = 'singular';
47
+
48
+	/**
49
+	 * Valor passado para o atributo
50
+	 *
51
+	 * @var array|string|null
52
+	 */
53
+	protected $values = null;
54
+
55
+	/**
56
+	 * Indica se a model será printada com lower case.
57
+	 *
58
+	 * @var boolean
59
+	 */
60
+	protected $lowercase = false;
61
+
62
+	/**
63
+	 * Construtor da exceção
64
+	 *
65
+	 * @param mixed $model
66
+	 */
67
+	public function __construct($model = 'foo')
68
+	{
69
+		$this->model = $model;
70
+	}
71
+
72
+	/**
73
+	 * Render the exception as an HTTP response.
74
+	 *
75
+	 * @return \Illuminate\Http\JsonResponse
76
+	 */
77
+	public function render()
78
+	{
79
+		return response()->
80
+			/** @scrutinizer ignore-call */
81
+			json([
82
+			'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues())
83
+		], $this->statusCode);
84
+	}
85
+
86
+	/**
87
+	 * Dá parse nos valores para a string de tradução.
88
+	 *
89
+	 * @return array
90
+	 */
91
+	protected function parseValues()
92
+	{
93
+		if(is_array($this->attributes) && is_array($this->values))
94
+			return collect($this->attributes)->combine($this->values)->all();
95
+
96
+		return [ $this->attributes => $this->values ?? $this->isLower() ];
97
+	}
98
+
99
+	/**
100
+	 * Verifica se é lowercase e retorna de acordo.
101
+	 *
102
+	 * @return string
103
+	 */
104
+	protected function isLower()
105
+	{
106
+		return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias();
107
+	}
108
+
109
+	/**
110
+	 * Retorna o alias da model.
111
+	 *
112
+	 * @return string
113
+	 */
114
+	protected function getAlias()
115
+	{
116
+		if(is_object($this->model))
117
+			$this->model = get_class($this->model);
118
+
119
+		return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso';
120
+	}
121
+
122
+	/**
123
+	 * Seta os valores.
124
+	 *
125
+	 * @param mixed $values
126
+	 */
127
+	public function setValues($values)
128
+	{
129
+		$this->values = $values;
130
+
131
+		return $this;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @param mixed $model
66 66
      */
67
-    public function __construct($model = 'foo')
67
+    public function __construct ($model = 'foo')
68 68
     {
69 69
         $this->model = $model;
70 70
     }
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return \Illuminate\Http\JsonResponse
76 76
      */
77
-    public function render()
77
+    public function render ()
78 78
     {
79 79
         return response()->
80 80
             /** @scrutinizer ignore-call */
81 81
             json([
82
-            'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues())
82
+            'messages' => trans('scheduler::exceptions.' . $this->trans, $this->parseValues())
83 83
         ], $this->statusCode);
84 84
     }
85 85
 
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return array
90 90
      */
91
-    protected function parseValues()
91
+    protected function parseValues ()
92 92
     {
93
-        if(is_array($this->attributes) && is_array($this->values))
93
+        if (is_array($this->attributes) && is_array($this->values))
94 94
             return collect($this->attributes)->combine($this->values)->all();
95 95
 
96 96
         return [ $this->attributes => $this->values ?? $this->isLower() ];
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return string
103 103
      */
104
-    protected function isLower()
104
+    protected function isLower ()
105 105
     {
106 106
         return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias();
107 107
     }
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
      *
112 112
      * @return string
113 113
      */
114
-    protected function getAlias()
114
+    protected function getAlias ()
115 115
     {
116
-        if(is_object($this->model))
116
+        if (is_object($this->model))
117 117
             $this->model = get_class($this->model);
118 118
 
119
-        return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso';
119
+        return collect(trans('scheduler::exceptions.aliases.' . $this->aliastype))->search($this->model) ?: 'Recurso';
120 120
     }
121 121
 
122 122
     /**
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      *
125 125
      * @param mixed $values
126 126
      */
127
-    public function setValues($values)
127
+    public function setValues ($values)
128 128
     {
129 129
         $this->values = $values;
130 130
 
Please login to merge, or discard this patch.
src/Scheduler/Models/ScheduleStatus.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -14,33 +14,33 @@
 block discarded – undo
14 14
 
15 15
 class ScheduleStatus extends Model
16 16
 {
17
-    use SoftDeletes;
17
+	use SoftDeletes;
18 18
 
19 19
 	/**
20
-     * Os atributos que podem ser atribuíveis em massa.
21
-     *
22
-     * @var array
23
-     */
24
-    protected $fillable = [
25
-    	'name', 'description'
26
-    ];
20
+	 * Os atributos que podem ser atribuíveis em massa.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $fillable = [
25
+		'name', 'description'
26
+	];
27 27
 
28
-    /**
29
-     * Os atributos que devem ser transformados para data.
30
-     *
31
-     * @var array
32
-     */
33
-    protected $dates = [
34
-    	'deleted_at'
35
-    ];
28
+	/**
29
+	 * Os atributos que devem ser transformados para data.
30
+	 *
31
+	 * @var array
32
+	 */
33
+	protected $dates = [
34
+		'deleted_at'
35
+	];
36 36
 
37
-    /**
38
-     * Construtor para inicilizar a váriavel table.
39
-     */
40
-    public function __construct(array $attributes = [])
41
-    {
42
-        parent::__construct($attributes);
37
+	/**
38
+	 * Construtor para inicilizar a váriavel table.
39
+	 */
40
+	public function __construct(array $attributes = [])
41
+	{
42
+		parent::__construct($attributes);
43 43
 
44
-        $this->table = Config::get('scheduler.schedule_status_table');
45
-    }
44
+		$this->table = Config::get('scheduler.schedule_status_table');
45
+	}
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Scheduler/Models/Schedule.php 3 patches
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.
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -19,76 +19,76 @@
 block discarded – undo
19 19
  */
20 20
 class Schedule extends Model
21 21
 {
22
-    use SoftDeletes;
22
+	use SoftDeletes;
23 23
 
24
-    /**
25
-     * Os atributos que devem ser mutados para os tipos nátivos.
26
-     *
27
-     * @var array
28
-     */
29
-    protected $casts = [
30
-        'data' => 'array',
31
-    ];
24
+	/**
25
+	 * Os atributos que devem ser mutados para os tipos nátivos.
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $casts = [
30
+		'data' => 'array',
31
+	];
32 32
 
33 33
 	/**
34
-     * Os atributos que podem ser atribuíveis em massa.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $fillable = [
39
-    	'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data'
40
-    ];
34
+	 * Os atributos que podem ser atribuíveis em massa.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $fillable = [
39
+		'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data'
40
+	];
41 41
 
42
-    /**
43
-     * Os atributos que devem ser transformados para data.
44
-     *
45
-     * @var array
46
-     */
47
-    protected $dates = [
48
-    	'start_at', 'end_at', 'deleted_at'
49
-    ];
42
+	/**
43
+	 * Os atributos que devem ser transformados para data.
44
+	 *
45
+	 * @var array
46
+	 */
47
+	protected $dates = [
48
+		'start_at', 'end_at', 'deleted_at'
49
+	];
50 50
 
51
-    /**
52
-     * Seta um status para o horário agendado.
53
-     *
54
-     * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário.
55
-     */
56
-    public function setStatus($name)
57
-    {
58
-    	$this->fill($this->parseStatusKey($name))->save();
59
-    }
51
+	/**
52
+	 * Seta um status para o horário agendado.
53
+	 *
54
+	 * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário.
55
+	 */
56
+	public function setStatus($name)
57
+	{
58
+		$this->fill($this->parseStatusKey($name))->save();
59
+	}
60 60
 
61
-    /**
62
-     * Retorna o ID do status caso passem o nome do status.
63
-     *
64
-     * @param  int|string $status ID ou o nome do status.
65
-     * @return array
66
-     *
67
-     * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
68
-     */
69
-    public function parseStatusKey($status)
70
-    {
71
-    	if(is_int($status))
72
-    		$status =  ScheduleStatus::find($status);
61
+	/**
62
+	 * Retorna o ID do status caso passem o nome do status.
63
+	 *
64
+	 * @param  int|string $status ID ou o nome do status.
65
+	 * @return array
66
+	 *
67
+	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
68
+	 */
69
+	public function parseStatusKey($status)
70
+	{
71
+		if(is_int($status))
72
+			$status =  ScheduleStatus::find($status);
73 73
 
74
-        if(is_string($status))
75
-        	$status = ScheduleStatus::where('name', $status)->first();
74
+		if(is_string($status))
75
+			$status = ScheduleStatus::where('name', $status)->first();
76 76
 
77
-    	if(is_null($status))
78
-    		throw (new ModelNotFound)->setValues(ScheduleStatus::class);
77
+		if(is_null($status))
78
+			throw (new ModelNotFound)->setValues(ScheduleStatus::class);
79 79
 
80
-    	return ['status' => $status->id];
81
-    }
80
+		return ['status' => $status->id];
81
+	}
82 82
 
83
-    /**
84
-     * Escopo de uma consulta que busca horarios pela data de início.
85
-     *
86
-     * @param \Illuminate\Database\Eloquent\Builder $query
87
-     * @param \Carbon\Carbon|string $start_at
88
-     * @return \Illuminate\Database\Eloquent\Builder
89
-     */
90
-    public function scopeByStartAt($query, $start_at)
91
-    {
92
-        return $query->where('start_at', $start_at);
93
-    }
83
+	/**
84
+	 * Escopo de uma consulta que busca horarios pela data de início.
85
+	 *
86
+	 * @param \Illuminate\Database\Eloquent\Builder $query
87
+	 * @param \Carbon\Carbon|string $start_at
88
+	 * @return \Illuminate\Database\Eloquent\Builder
89
+	 */
90
+	public function scopeByStartAt($query, $start_at)
91
+	{
92
+		return $query->where('start_at', $start_at);
93
+	}
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Migrations/2018_08_18_225944_create_schedules_table.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @return void
22 22
      */
23
-    public function up()
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');
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      *
40 40
      * @return void
41 41
      */
42
-    public function down()
42
+    public function down ()
43 43
     {
44 44
         Schema::drop(Config::get('scheduler.schedules_table'));
45 45
     }
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,33 +15,33 @@
 block discarded – undo
15 15
 
16 16
 class CreateSchedulesTable extends Migration
17 17
 {
18
-    /**
19
-     * Run the migrations.
20
-     *
21
-     * @return void
22
-     */
23
-    public function up()
24
-    {
25
-        Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) {
26
-            $table->increments('id');
27
-            $table->string('model_type');
28
-            $table->integer('model_id');
29
-            $table->timestamp('start_at');
30
-            $table->timestamp('end_at')->nullable();
31
-            $table->integer('status')->nullable();
32
-            $table->json('data')->nullable();
33
-            $table->timestamps();
34
-            $table->softDeletes();
35
-        });
36
-    }
18
+	/**
19
+	 * Run the migrations.
20
+	 *
21
+	 * @return void
22
+	 */
23
+	public function up()
24
+	{
25
+		Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) {
26
+			$table->increments('id');
27
+			$table->string('model_type');
28
+			$table->integer('model_id');
29
+			$table->timestamp('start_at');
30
+			$table->timestamp('end_at')->nullable();
31
+			$table->integer('status')->nullable();
32
+			$table->json('data')->nullable();
33
+			$table->timestamps();
34
+			$table->softDeletes();
35
+		});
36
+	}
37 37
 
38
-    /**
39
-     * Reverse the migrations.
40
-     *
41
-     * @return void
42
-     */
43
-    public function down()
44
-    {
45
-        Schema::drop(Config::get('scheduler.schedules_table'));
46
-    }
38
+	/**
39
+	 * Reverse the migrations.
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function down()
44
+	{
45
+		Schema::drop(Config::get('scheduler.schedules_table'));
46
+	}
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Migrations/2018_08_18_225643_create_schedule_status_table.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -15,29 +15,29 @@
 block discarded – undo
15 15
 
16 16
 class CreateScheduleStatusTable extends Migration
17 17
 {
18
-    /**
19
-     * Run the migrations.
20
-     *
21
-     * @return void
22
-     */
23
-    public function up()
24
-    {
25
-        Schema::create(Config::get('scheduler.schedule_status_table'), function (Blueprint $table) {
26
-            $table->increments('id');
27
-            $table->string('name')->unique();
28
-            $table->text('description')->nullable();
29
-            $table->timestamps();
30
-            $table->softDeletes();
31
-        });
32
-    }
18
+	/**
19
+	 * Run the migrations.
20
+	 *
21
+	 * @return void
22
+	 */
23
+	public function up()
24
+	{
25
+		Schema::create(Config::get('scheduler.schedule_status_table'), function (Blueprint $table) {
26
+			$table->increments('id');
27
+			$table->string('name')->unique();
28
+			$table->text('description')->nullable();
29
+			$table->timestamps();
30
+			$table->softDeletes();
31
+		});
32
+	}
33 33
 
34
-    /**
35
-     * Reverse the migrations.
36
-     *
37
-     * @return void
38
-     */
39
-    public function down()
40
-    {
41
-        Schema::drop(Config::get('scheduler.schedule_status_table'));
42
-    }
34
+	/**
35
+	 * Reverse the migrations.
36
+	 *
37
+	 * @return void
38
+	 */
39
+	public function down()
40
+	{
41
+		Schema::drop(Config::get('scheduler.schedule_status_table'));
42
+	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @return void
22 22
      */
23
-    public function up()
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();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @return void
38 38
      */
39
-    public function down()
39
+    public function down ()
40 40
     {
41 41
         Schema::drop(Config::get('scheduler.schedule_status_table'));
42 42
     }
Please login to merge, or discard this patch.
src/Scheduler/Traits/SchedulerModelTrait.php 3 patches
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -110,16 +110,19 @@
 block discarded – undo
110 110
 	 */
111 111
 	public function removeSchedule($schedule)
112 112
 	{
113
-		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
114
-			throw new CantRemoveByDate;
113
+		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) {
114
+					throw new CantRemoveByDate;
115
+		}
115 116
 
116 117
 		$schedule = Scheduler::parseToSchedule($schedule);
117 118
 
118
-		if(!($schedule instanceof Model))
119
-			throw (new ModelNotFound)->setValues(Schedule::class);
119
+		if(!($schedule instanceof Model)) {
120
+					throw (new ModelNotFound)->setValues(Schedule::class);
121
+		}
120 122
 
121
-		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
122
-			throw new DoesNotBelong;
123
+		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) {
124
+					throw new DoesNotBelong;
125
+		}
123 126
 
124 127
 		return $schedule->delete();
125 128
 	}
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -24,27 +24,27 @@  discard block
 block discarded – undo
24 24
 trait SchedulerModelTrait
25 25
 {
26 26
 	/**
27
-     * Define a one-to-one relationship.
28
-     *
29
-     * @param  string  $related
30
-     * @param  string  $foreignKey
31
-     * @param  string  $localKey
32
-     * @return \Illuminate\Database\Eloquent\Relations\HasOne
33
-     */
34
-    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
27
+	 * Define a one-to-one relationship.
28
+	 *
29
+	 * @param  string  $related
30
+	 * @param  string  $foreignKey
31
+	 * @param  string  $localKey
32
+	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
33
+	 */
34
+	abstract public function hasOne($related, $foreignKey = null, $localKey = null);
35 35
 
36 36
 	/**
37
-     * Get the value of the model's primary key.
38
-     *
39
-     * @return mixed
40
-     */
37
+	 * Get the value of the model's primary key.
38
+	 *
39
+	 * @return mixed
40
+	 */
41 41
 	abstract public function getKey();
42 42
 
43 43
 	/**
44
-     * Retorna apenas o horário que possui o mesmo [model_id] do [parent] dessa [trait].
45
-     *
46
-     * @return \Illuminate\Database\Eloquent\Relations\HasOne
47
-     */
44
+	 * Retorna apenas o horário que possui o mesmo [model_id] do [parent] dessa [trait].
45
+	 *
46
+	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
47
+	 */
48 48
 	public function schedules()
49 49
 	{
50 50
 		return $this->hasOne(Config::get('scheduler.schedules_table'), 'model_id');
@@ -98,27 +98,27 @@  discard block
 block discarded – undo
98 98
 	}
99 99
 
100 100
 	/**
101
-     * Retorna os horários disponiveis hoje para uma determinada model.
102
-     * .
103
-     * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
104
-     * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
105
-     * @return array
106
-     */
107
-    public function availableToday(int $duration, Carbon $openingTime = null)
108
-    {
109
-    	return Scheduler::byModel(self::class)->availableToday($duration, $openingTime);
110
-    }
101
+	 * Retorna os horários disponiveis hoje para uma determinada model.
102
+	 * .
103
+	 * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
104
+	 * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
105
+	 * @return array
106
+	 */
107
+	public function availableToday(int $duration, Carbon $openingTime = null)
108
+	{
109
+		return Scheduler::byModel(self::class)->availableToday($duration, $openingTime);
110
+	}
111 111
 
112
-    /**
113
-     * Retorna os horários disponiveis em um determinado dia para uma certa model.
114
-     *
115
-     * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
116
-     * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
117
-     * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
118
-     * @return array
119
-     */
120
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
121
-    {
122
-    	return Scheduler::byModel(self::class)->availableOn($today, $durationMinutes, $openingTime);
123
-    }
112
+	/**
113
+	 * Retorna os horários disponiveis em um determinado dia para uma certa model.
114
+	 *
115
+	 * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
116
+	 * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
117
+	 * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
118
+	 * @return array
119
+	 */
120
+	public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
121
+	{
122
+		return Scheduler::byModel(self::class)->availableOn($today, $durationMinutes, $openingTime);
123
+	}
124 124
 }
125 125
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -31,21 +31,21 @@  discard block
 block discarded – undo
31 31
      * @param  string  $localKey
32 32
      * @return \Illuminate\Database\Eloquent\Relations\HasOne
33 33
      */
34
-    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
34
+    abstract public function hasOne ($related, $foreignKey = null, $localKey = null);
35 35
 
36 36
 	/**
37 37
      * Get the value of the model's primary key.
38 38
      *
39 39
      * @return mixed
40 40
      */
41
-	abstract public function getKey();
41
+	abstract public function getKey ();
42 42
 
43 43
 	/**
44 44
      * Retorna apenas o horário que possui o mesmo [model_id] do [parent] dessa [trait].
45 45
      *
46 46
      * @return \Illuminate\Database\Eloquent\Relations\HasOne
47 47
      */
48
-	public function schedules()
48
+	public function schedules ()
49 49
 	{
50 50
 		return $this->hasOne(Config::get('scheduler.schedules_table'), 'model_id');
51 51
 	}
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 	 * @param  array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado.
60 60
 	 * @return \H4ad\Scheduler\Models\Schedule
61 61
 	 */
62
-	public function addSchedule($start_at, $end_at = null, int $status = null, array $data = null)
62
+	public function addSchedule ($start_at, $end_at = null, int $status = null, array $data = null)
63 63
 	{
64 64
 		$schedule = Scheduler::setModelType(self::class)->byModel()->validateSchedule($start_at, $end_at, $status);
65 65
 
66
-		$schedule['model_id'] = $this->getKey();
67
-		$schedule['data'] = $data;
66
+		$schedule[ 'model_id' ] = $this->getKey();
67
+		$schedule[ 'data' ] = $data;
68 68
 
69 69
 		return Schedule::create($schedule);
70 70
 	}
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
 	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
82 82
 	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
83 83
 	 */
84
-	public function removeSchedule($schedule)
84
+	public function removeSchedule ($schedule)
85 85
 	{
86
-		if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
86
+		if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule))
87 87
 			throw new CantRemoveByDate;
88 88
 
89 89
 		$schedule = Scheduler::parseToSchedule($schedule);
90 90
 
91
-		if(!($schedule instanceof Model))
91
+		if (!($schedule instanceof Model))
92 92
 			throw (new ModelNotFound)->setValues(Schedule::class);
93 93
 
94
-		if($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
94
+		if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey())
95 95
 			throw new DoesNotBelong;
96 96
 
97 97
 		return $schedule->delete();
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
105 105
      * @return array
106 106
      */
107
-    public function availableToday(int $duration, Carbon $openingTime = null)
107
+    public function availableToday (int $duration, Carbon $openingTime = null)
108 108
     {
109 109
     	return Scheduler::byModel(self::class)->availableToday($duration, $openingTime);
110 110
     }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
118 118
      * @return array
119 119
      */
120
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
120
+    public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null)
121 121
     {
122 122
     	return Scheduler::byModel(self::class)->availableOn($today, $durationMinutes, $openingTime);
123 123
     }
Please login to merge, or discard this patch.
src/Scheduler/Facades/Scheduler.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@
 block discarded – undo
28 28
  */
29 29
 class Scheduler extends Facade
30 30
 {
31
-    /**
32
-     * Get the registered name of the component.
33
-     *
34
-     * @return string
35
-     */
36
-    protected static function getFacadeAccessor()
37
-    {
38
-        return static::$app['scheduler']->newInstance();
39
-    }
31
+	/**
32
+	 * Get the registered name of the component.
33
+	 *
34
+	 * @return string
35
+	 */
36
+	protected static function getFacadeAccessor()
37
+	{
38
+		return static::$app['scheduler']->newInstance();
39
+	}
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@
 block discarded – undo
33 33
      *
34 34
      * @return string
35 35
      */
36
-    protected static function getFacadeAccessor()
36
+    protected static function getFacadeAccessor ()
37 37
     {
38
-        return static::$app['scheduler']->newInstance();
38
+        return static::$app[ 'scheduler' ]->newInstance();
39 39
     }
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Scheduler.php 3 patches
Indentation   +287 added lines, -287 removed lines patch added patch discarded remove patch
@@ -21,300 +21,300 @@
 block discarded – undo
21 21
 
22 22
 class Scheduler
23 23
 {
24
-    use Macroable;
25
-
26
-    /**
27
-     * Query a ser executada.
28
-     *
29
-     * @var void
30
-     */
31
-    protected $query;
32
-
33
-    /**
34
-     * Tipo de model usada para validar.
35
-     *
36
-     * @var string
37
-     */
38
-    protected $model_type;
39
-
40
-    /**
41
-     * Closure de boot.
42
-     *
43
-     * @var Closure
44
-     */
45
-    protected static $boot;
46
-
47
-    /**
48
-     * Construtor da classe.
49
-     */
50
-    public function __construct()
51
-    {
52
-        $this->query = Schedule::query();
53
-    }
54
-
55
-    /**
56
-     * Define método executado toda vez que é gerada uma nova instância do Scheduler.
57
-     * Há apenas um unico parâmetro passado para a função que é o query.
58
-     *
59
-     * @param  \Closure $boot_method
60
-     * @return void
61
-     */
62
-    public function init(Closure $boot)
63
-    {
64
-        static::$boot = $boot;
65
-    }
66
-
67
-    /**
68
-     * Ignora uma lista de ids da model.
69
-     *
70
-     * @param  array  $model_ids
71
-     * @return $this
72
-     */
73
-    public function avoid(array $model_ids)
74
-    {
75
-        $this->query->whereNotIn('model_id', $model_ids);
76
-
77
-        return $this;
78
-    }
79
-
80
-    /**
81
-     * Verifica se há conflito de horários registrados em um intervalo de tempo.
82
-     *
83
-     * @param  \Carbon\Carbon|string $start_at
84
-     * @param  \Carbon\Carbon|string $end_at
85
-     * @return boolean
86
-     */
87
-    public function hasConflict($start_at, $end_at)
88
-    {
89
-        if(!Config::get('scheduler.enable_schedule_conflict'))
90
-            return false;
91
-
92
-        $this->byModel();
93
-        $this->whereBetween($start_at, $end_at);
94
-
95
-        return $this->query->exists();
96
-    }
97
-
98
-    /**
99
-     * Busca horários que estejam dentro um intervalo de tempo.
100
-     *
101
-     * @param  \Carbon\Carbon|string $start_at
102
-     * @param  \Carbon\Carbon|string $end_at
103
-     * @return $this
104
-     */
105
-    public function whereBetween($start_at, $end_at)
106
-    {
107
-        $this->query->where('start_at', '>=', $start_at)
108
-              ->where('end_at', '<=', $end_at);
109
-
110
-        return $this;
111
-    }
112
-
113
-    /**
114
-     * Define o tipo de model buscada.
115
-     *
116
-     * @param  string|null $model_type
117
-     * @return $this
118
-     */
119
-    public function byModel()
120
-    {
121
-        $this->query->where('model_type', $this->getModelType());
122
-
123
-        return $this;
124
-    }
125
-
126
-    /**
127
-     * Seta a model padrão.
128
-     *
129
-     * @param string $model_type
130
-     * @return $this
131
-     */
132
-    public function setModelType(string $model_type)
133
-    {
134
-        $this->model_type = $model_type;
135
-
136
-        return $this;
137
-    }
138
-
139
-    /**
140
-     * Retorna a model type.
141
-     *
142
-     * @return string
143
-     */
144
-    public function getModelType()
145
-    {
146
-        return $this->model_type ?? Config::get('scheduler.default_model');
147
-    }
148
-    /**
149
-     * Retorna os horários disponiveis hoje para uma determinada model.
150
-     * .
151
-     * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
152
-     * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
153
-     * @return array
154
-     */
155
-    public function availableToday(int $duration, Carbon $openingTime = null)
156
-    {
157
-        return $this->availableOn(Carbon::today(), $duration, $openingTime);
158
-    }
159
-
160
-    /**
161
-     * Retorna os horários disponiveis em um determinado dia para uma certa model.
162
-     *
163
-     * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
164
-     * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
165
-     * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
166
-     * @return array
167
-     */
168
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
169
-    {
170
-        $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
171
-        $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
172
-
173
-        $livres = [];
174
-        $today = Carbon::parse($today->toDateString());
175
-        while($openingTime <= $closingTime)
176
-        {
177
-            $add = true;
178
-
179
-            $opening = Carbon::parse($openingTime->toDateTimeString());
180
-            $closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
181
-
182
-            foreach ($this->query->orderBy('start_at', 'DESC')->cursor() as $schedule) {
183
-                $start = Carbon::parse($schedule->start_at);
184
-                $begin = Carbon::parse($start->toDateString());
185
-
186
-                if($begin->greaterThan($today))
187
-                    break;
188
-
189
-                if($begin->notEqualTo($today))
190
-                    continue;
191
-
192
-                $end = Carbon::parse($schedule->end_at);
193
-
194
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
195
-                    $add = false;
196
-            }
197
-
198
-            if($add && $closing->lessThanOrEqualTo($closingTime))
199
-                $livres[] = [
200
-                    'start_at' => $opening,
201
-                    'end_at' => $closing
202
-                ];
203
-
204
-            $openingTime->addMinutes($durationMinutes);
205
-        }
206
-
207
-        return $livres;
208
-    }
209
-
210
-    /**
211
-     * Verifica se ele não deve ser adicionado ao array de horários livres.
212
-     *
213
-     * @param  \Carbon\Carbon  $opening
214
-     * @param  \Carbon\Carbon  $closing
215
-     * @param  \Carbon\Carbon  $start
216
-     * @param  \Carbon\Carbon  $end
217
-     * @return boolean
218
-     */
219
-    private function isShouldntAdd(Carbon $opening, Carbon $closing, Carbon $start, Carbon $end)
220
-    {
221
-        return $start <= $opening && $end >= $closing;
222
-    }
223
-
224
-    /**
225
-     * Valida e retorna os dados formatados de forma correta em um [array].
226
-     *
227
-     * @param  \Carbon\Carbon|string $start_at  Data em que será agendado, pode ser em string ou em numa classe Carbon.
228
-     * @param  \Carbon\Carbon|string|int|null $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon ou em int(sendo considerado os minutos de duração).
229
-     * @param  int|null $status Status desse horário ao ser agendado.
230
-     * @return array
231
-     *
232
-     * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
233
-     * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
234
-     * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
235
-     */
236
-    public function validateSchedule($start_at, $end_at = null, int $status = null)
237
-    {
238
-        if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
239
-            throw new CantAddWithoutEnd;
240
-
241
-        $start_at  = $this->parseToCarbon($start_at);
242
-
243
-        if(isset($end_at)) {
244
-            $end_at = $this->parseToCarbon($end_at, $start_at);
245
-
246
-            if($start_at->greaterThan($end_at))
247
-                throw new EndCantBeforeStart;
248
-        }
249
-
250
-        if(isset($status))
251
-            ScheduleStatus::findOrFail($status);
252
-
253
-        if($this->hasConflict($start_at, $end_at ?? $start_at))
254
-            throw new CantAddWithSameStartAt;
255
-
256
-        $model_type = $this->getModelType();
257
-
258
-        return compact('model_type', 'start_at', 'end_at', 'status');
259
-    }
260
-
261
-    /**
262
-     * Faz um parse na data e retorna uma instância em Carbon.
263
-     *
264
-     * @param  \Carbon\Carbon|string|int $date Data final que será transformada numa instancia Carbon.
265
-     * @param  \Carbon\Carbon $reference Data de referencia quando o [date] é inteiro.
266
-     * @return \Carbon\Carbon
267
-     *
268
-     * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument
269
-     */
270
-    public function parseToCarbon($date, $reference = null)
271
-    {
272
-        if($date instanceof Carbon)
273
-            return $date;
274
-
275
-        if(is_string($date))
276
-            return Carbon::parse($date);
277
-
278
-        if(is_int($date) && !is_null($reference))
279
-            return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
280
-
281
-        throw new IntInvalidArgument;
282
-    }
283
-
284
-    /**
285
-     * Faz um parse e retorna um Schedule.
286
-     *
287
-     * @param  \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado.
288
-     * @return \H4ad\Scheduler\Models\Schedule|null
289
-     */
290
-    public function parseToSchedule($value)
291
-    {
292
-        if(is_int($value))
293
-            return Schedule::find($value);
294
-
295
-        return Schedule::byStartAt($value)->first();
24
+	use Macroable;
25
+
26
+	/**
27
+	 * Query a ser executada.
28
+	 *
29
+	 * @var void
30
+	 */
31
+	protected $query;
32
+
33
+	/**
34
+	 * Tipo de model usada para validar.
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $model_type;
39
+
40
+	/**
41
+	 * Closure de boot.
42
+	 *
43
+	 * @var Closure
44
+	 */
45
+	protected static $boot;
46
+
47
+	/**
48
+	 * Construtor da classe.
49
+	 */
50
+	public function __construct()
51
+	{
52
+		$this->query = Schedule::query();
53
+	}
54
+
55
+	/**
56
+	 * Define método executado toda vez que é gerada uma nova instância do Scheduler.
57
+	 * Há apenas um unico parâmetro passado para a função que é o query.
58
+	 *
59
+	 * @param  \Closure $boot_method
60
+	 * @return void
61
+	 */
62
+	public function init(Closure $boot)
63
+	{
64
+		static::$boot = $boot;
65
+	}
66
+
67
+	/**
68
+	 * Ignora uma lista de ids da model.
69
+	 *
70
+	 * @param  array  $model_ids
71
+	 * @return $this
72
+	 */
73
+	public function avoid(array $model_ids)
74
+	{
75
+		$this->query->whereNotIn('model_id', $model_ids);
76
+
77
+		return $this;
78
+	}
79
+
80
+	/**
81
+	 * Verifica se há conflito de horários registrados em um intervalo de tempo.
82
+	 *
83
+	 * @param  \Carbon\Carbon|string $start_at
84
+	 * @param  \Carbon\Carbon|string $end_at
85
+	 * @return boolean
86
+	 */
87
+	public function hasConflict($start_at, $end_at)
88
+	{
89
+		if(!Config::get('scheduler.enable_schedule_conflict'))
90
+			return false;
91
+
92
+		$this->byModel();
93
+		$this->whereBetween($start_at, $end_at);
94
+
95
+		return $this->query->exists();
96
+	}
97
+
98
+	/**
99
+	 * Busca horários que estejam dentro um intervalo de tempo.
100
+	 *
101
+	 * @param  \Carbon\Carbon|string $start_at
102
+	 * @param  \Carbon\Carbon|string $end_at
103
+	 * @return $this
104
+	 */
105
+	public function whereBetween($start_at, $end_at)
106
+	{
107
+		$this->query->where('start_at', '>=', $start_at)
108
+			  ->where('end_at', '<=', $end_at);
109
+
110
+		return $this;
111
+	}
112
+
113
+	/**
114
+	 * Define o tipo de model buscada.
115
+	 *
116
+	 * @param  string|null $model_type
117
+	 * @return $this
118
+	 */
119
+	public function byModel()
120
+	{
121
+		$this->query->where('model_type', $this->getModelType());
122
+
123
+		return $this;
124
+	}
125
+
126
+	/**
127
+	 * Seta a model padrão.
128
+	 *
129
+	 * @param string $model_type
130
+	 * @return $this
131
+	 */
132
+	public function setModelType(string $model_type)
133
+	{
134
+		$this->model_type = $model_type;
135
+
136
+		return $this;
137
+	}
138
+
139
+	/**
140
+	 * Retorna a model type.
141
+	 *
142
+	 * @return string
143
+	 */
144
+	public function getModelType()
145
+	{
146
+		return $this->model_type ?? Config::get('scheduler.default_model');
147
+	}
148
+	/**
149
+	 * Retorna os horários disponiveis hoje para uma determinada model.
150
+	 * .
151
+	 * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
152
+	 * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
153
+	 * @return array
154
+	 */
155
+	public function availableToday(int $duration, Carbon $openingTime = null)
156
+	{
157
+		return $this->availableOn(Carbon::today(), $duration, $openingTime);
158
+	}
159
+
160
+	/**
161
+	 * Retorna os horários disponiveis em um determinado dia para uma certa model.
162
+	 *
163
+	 * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
164
+	 * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
165
+	 * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
166
+	 * @return array
167
+	 */
168
+	public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
169
+	{
170
+		$openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
171
+		$closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
172
+
173
+		$livres = [];
174
+		$today = Carbon::parse($today->toDateString());
175
+		while($openingTime <= $closingTime)
176
+		{
177
+			$add = true;
178
+
179
+			$opening = Carbon::parse($openingTime->toDateTimeString());
180
+			$closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes);
181
+
182
+			foreach ($this->query->orderBy('start_at', 'DESC')->cursor() as $schedule) {
183
+				$start = Carbon::parse($schedule->start_at);
184
+				$begin = Carbon::parse($start->toDateString());
185
+
186
+				if($begin->greaterThan($today))
187
+					break;
188
+
189
+				if($begin->notEqualTo($today))
190
+					continue;
191
+
192
+				$end = Carbon::parse($schedule->end_at);
193
+
194
+				if($this->isShouldntAdd($opening, $closing, $start, $end))
195
+					$add = false;
196
+			}
197
+
198
+			if($add && $closing->lessThanOrEqualTo($closingTime))
199
+				$livres[] = [
200
+					'start_at' => $opening,
201
+					'end_at' => $closing
202
+				];
203
+
204
+			$openingTime->addMinutes($durationMinutes);
205
+		}
206
+
207
+		return $livres;
208
+	}
209
+
210
+	/**
211
+	 * Verifica se ele não deve ser adicionado ao array de horários livres.
212
+	 *
213
+	 * @param  \Carbon\Carbon  $opening
214
+	 * @param  \Carbon\Carbon  $closing
215
+	 * @param  \Carbon\Carbon  $start
216
+	 * @param  \Carbon\Carbon  $end
217
+	 * @return boolean
218
+	 */
219
+	private function isShouldntAdd(Carbon $opening, Carbon $closing, Carbon $start, Carbon $end)
220
+	{
221
+		return $start <= $opening && $end >= $closing;
222
+	}
223
+
224
+	/**
225
+	 * Valida e retorna os dados formatados de forma correta em um [array].
226
+	 *
227
+	 * @param  \Carbon\Carbon|string $start_at  Data em que será agendado, pode ser em string ou em numa classe Carbon.
228
+	 * @param  \Carbon\Carbon|string|int|null $end_at   Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon ou em int(sendo considerado os minutos de duração).
229
+	 * @param  int|null $status Status desse horário ao ser agendado.
230
+	 * @return array
231
+	 *
232
+	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd
233
+	 * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
234
+	 * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
235
+	 */
236
+	public function validateSchedule($start_at, $end_at = null, int $status = null)
237
+	{
238
+		if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
239
+			throw new CantAddWithoutEnd;
240
+
241
+		$start_at  = $this->parseToCarbon($start_at);
242
+
243
+		if(isset($end_at)) {
244
+			$end_at = $this->parseToCarbon($end_at, $start_at);
245
+
246
+			if($start_at->greaterThan($end_at))
247
+				throw new EndCantBeforeStart;
248
+		}
249
+
250
+		if(isset($status))
251
+			ScheduleStatus::findOrFail($status);
252
+
253
+		if($this->hasConflict($start_at, $end_at ?? $start_at))
254
+			throw new CantAddWithSameStartAt;
255
+
256
+		$model_type = $this->getModelType();
257
+
258
+		return compact('model_type', 'start_at', 'end_at', 'status');
259
+	}
260
+
261
+	/**
262
+	 * Faz um parse na data e retorna uma instância em Carbon.
263
+	 *
264
+	 * @param  \Carbon\Carbon|string|int $date Data final que será transformada numa instancia Carbon.
265
+	 * @param  \Carbon\Carbon $reference Data de referencia quando o [date] é inteiro.
266
+	 * @return \Carbon\Carbon
267
+	 *
268
+	 * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument
269
+	 */
270
+	public function parseToCarbon($date, $reference = null)
271
+	{
272
+		if($date instanceof Carbon)
273
+			return $date;
274
+
275
+		if(is_string($date))
276
+			return Carbon::parse($date);
277
+
278
+		if(is_int($date) && !is_null($reference))
279
+			return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
280
+
281
+		throw new IntInvalidArgument;
282
+	}
283
+
284
+	/**
285
+	 * Faz um parse e retorna um Schedule.
286
+	 *
287
+	 * @param  \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado.
288
+	 * @return \H4ad\Scheduler\Models\Schedule|null
289
+	 */
290
+	public function parseToSchedule($value)
291
+	{
292
+		if(is_int($value))
293
+			return Schedule::find($value);
294
+
295
+		return Schedule::byStartAt($value)->first();
296 296
    }
297 297
 
298
-    /**
299
-     * Retorna uma instância do Scheduler.
300
-     *
301
-     * @return $this
302
-     */
303
-    public function newInstance()
304
-    {
305
-        return clone $this;
306
-    }
298
+	/**
299
+	 * Retorna uma instância do Scheduler.
300
+	 *
301
+	 * @return $this
302
+	 */
303
+	public function newInstance()
304
+	{
305
+		return clone $this;
306
+	}
307 307
 
308 308
    /**
309 309
     * Callback apos chamar um clone.
310 310
     *
311 311
     * @return void
312 312
     */
313
-    public function __clone()
314
-    {
315
-        $this->query = Schedule::query();
313
+	public function __clone()
314
+	{
315
+		$this->query = Schedule::query();
316 316
 
317
-        if(isset(static::$boot))
318
-            (static::$boot)($this);
319
-    }
317
+		if(isset(static::$boot))
318
+			(static::$boot)($this);
319
+	}
320 320
 }
321 321
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * Construtor da classe.
49 49
      */
50
-    public function __construct()
50
+    public function __construct ()
51 51
     {
52 52
         $this->query = Schedule::query();
53 53
     }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      * @param  \Closure $boot_method
60 60
      * @return void
61 61
      */
62
-    public function init(Closure $boot)
62
+    public function init (Closure $boot)
63 63
     {
64 64
         static::$boot = $boot;
65 65
     }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * @param  array  $model_ids
71 71
      * @return $this
72 72
      */
73
-    public function avoid(array $model_ids)
73
+    public function avoid (array $model_ids)
74 74
     {
75 75
         $this->query->whereNotIn('model_id', $model_ids);
76 76
 
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
      * @param  \Carbon\Carbon|string $end_at
85 85
      * @return boolean
86 86
      */
87
-    public function hasConflict($start_at, $end_at)
87
+    public function hasConflict ($start_at, $end_at)
88 88
     {
89
-        if(!Config::get('scheduler.enable_schedule_conflict'))
89
+        if (!Config::get('scheduler.enable_schedule_conflict'))
90 90
             return false;
91 91
 
92 92
         $this->byModel();
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param  \Carbon\Carbon|string $end_at
103 103
      * @return $this
104 104
      */
105
-    public function whereBetween($start_at, $end_at)
105
+    public function whereBetween ($start_at, $end_at)
106 106
     {
107 107
         $this->query->where('start_at', '>=', $start_at)
108 108
               ->where('end_at', '<=', $end_at);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * @param  string|null $model_type
117 117
      * @return $this
118 118
      */
119
-    public function byModel()
119
+    public function byModel ()
120 120
     {
121 121
         $this->query->where('model_type', $this->getModelType());
122 122
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * @param string $model_type
130 130
      * @return $this
131 131
      */
132
-    public function setModelType(string $model_type)
132
+    public function setModelType (string $model_type)
133 133
     {
134 134
         $this->model_type = $model_type;
135 135
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      *
142 142
      * @return string
143 143
      */
144
-    public function getModelType()
144
+    public function getModelType ()
145 145
     {
146 146
         return $this->model_type ?? Config::get('scheduler.default_model');
147 147
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
153 153
      * @return array
154 154
      */
155
-    public function availableToday(int $duration, Carbon $openingTime = null)
155
+    public function availableToday (int $duration, Carbon $openingTime = null)
156 156
     {
157 157
         return $this->availableOn(Carbon::today(), $duration, $openingTime);
158 158
     }
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
      * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
166 166
      * @return array
167 167
      */
168
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null)
168
+    public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null)
169 169
     {
170 170
         $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
171 171
         $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
172 172
 
173
-        $livres = [];
173
+        $livres = [ ];
174 174
         $today = Carbon::parse($today->toDateString());
175
-        while($openingTime <= $closingTime)
175
+        while ($openingTime <= $closingTime)
176 176
         {
177 177
             $add = true;
178 178
 
@@ -183,20 +183,20 @@  discard block
 block discarded – undo
183 183
                 $start = Carbon::parse($schedule->start_at);
184 184
                 $begin = Carbon::parse($start->toDateString());
185 185
 
186
-                if($begin->greaterThan($today))
186
+                if ($begin->greaterThan($today))
187 187
                     break;
188 188
 
189
-                if($begin->notEqualTo($today))
189
+                if ($begin->notEqualTo($today))
190 190
                     continue;
191 191
 
192 192
                 $end = Carbon::parse($schedule->end_at);
193 193
 
194
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
194
+                if ($this->isShouldntAdd($opening, $closing, $start, $end))
195 195
                     $add = false;
196 196
             }
197 197
 
198
-            if($add && $closing->lessThanOrEqualTo($closingTime))
199
-                $livres[] = [
198
+            if ($add && $closing->lessThanOrEqualTo($closingTime))
199
+                $livres[ ] = [
200 200
                     'start_at' => $opening,
201 201
                     'end_at' => $closing
202 202
                 ];
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      * @param  \Carbon\Carbon  $end
217 217
      * @return boolean
218 218
      */
219
-    private function isShouldntAdd(Carbon $opening, Carbon $closing, Carbon $start, Carbon $end)
219
+    private function isShouldntAdd (Carbon $opening, Carbon $closing, Carbon $start, Carbon $end)
220 220
     {
221 221
         return $start <= $opening && $end >= $closing;
222 222
     }
@@ -233,24 +233,24 @@  discard block
 block discarded – undo
233 233
      * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart
234 234
      * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt
235 235
      */
236
-    public function validateSchedule($start_at, $end_at = null, int $status = null)
236
+    public function validateSchedule ($start_at, $end_at = null, int $status = null)
237 237
     {
238
-        if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
238
+        if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
239 239
             throw new CantAddWithoutEnd;
240 240
 
241
-        $start_at  = $this->parseToCarbon($start_at);
241
+        $start_at = $this->parseToCarbon($start_at);
242 242
 
243
-        if(isset($end_at)) {
243
+        if (isset($end_at)) {
244 244
             $end_at = $this->parseToCarbon($end_at, $start_at);
245 245
 
246
-            if($start_at->greaterThan($end_at))
246
+            if ($start_at->greaterThan($end_at))
247 247
                 throw new EndCantBeforeStart;
248 248
         }
249 249
 
250
-        if(isset($status))
250
+        if (isset($status))
251 251
             ScheduleStatus::findOrFail($status);
252 252
 
253
-        if($this->hasConflict($start_at, $end_at ?? $start_at))
253
+        if ($this->hasConflict($start_at, $end_at ?? $start_at))
254 254
             throw new CantAddWithSameStartAt;
255 255
 
256 256
         $model_type = $this->getModelType();
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
      *
268 268
      * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument
269 269
      */
270
-    public function parseToCarbon($date, $reference = null)
270
+    public function parseToCarbon ($date, $reference = null)
271 271
     {
272
-        if($date instanceof Carbon)
272
+        if ($date instanceof Carbon)
273 273
             return $date;
274 274
 
275
-        if(is_string($date))
275
+        if (is_string($date))
276 276
             return Carbon::parse($date);
277 277
 
278
-        if(is_int($date) && !is_null($reference))
278
+        if (is_int($date) && !is_null($reference))
279 279
             return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
280 280
 
281 281
         throw new IntInvalidArgument;
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
      * @param  \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado.
288 288
      * @return \H4ad\Scheduler\Models\Schedule|null
289 289
      */
290
-    public function parseToSchedule($value)
290
+    public function parseToSchedule ($value)
291 291
     {
292
-        if(is_int($value))
292
+        if (is_int($value))
293 293
             return Schedule::find($value);
294 294
 
295 295
         return Schedule::byStartAt($value)->first();
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      *
301 301
      * @return $this
302 302
      */
303
-    public function newInstance()
303
+    public function newInstance ()
304 304
     {
305 305
         return clone $this;
306 306
     }
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
     *
311 311
     * @return void
312 312
     */
313
-    public function __clone()
313
+    public function __clone ()
314 314
     {
315 315
         $this->query = Schedule::query();
316 316
 
317
-        if(isset(static::$boot))
317
+        if (isset(static::$boot))
318 318
             (static::$boot)($this);
319 319
     }
320 320
 }
321 321
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +42 added lines, -28 removed lines patch added patch discarded remove patch
@@ -86,8 +86,9 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function hasConflict($start_at, $end_at)
88 88
     {
89
-        if(!Config::get('scheduler.enable_schedule_conflict'))
90
-            return false;
89
+        if(!Config::get('scheduler.enable_schedule_conflict')) {
90
+                    return false;
91
+        }
91 92
 
92 93
         $this->byModel();
93 94
         $this->whereBetween($start_at, $end_at);
@@ -183,23 +184,27 @@  discard block
 block discarded – undo
183 184
                 $start = Carbon::parse($schedule->start_at);
184 185
                 $begin = Carbon::parse($start->toDateString());
185 186
 
186
-                if($begin->greaterThan($today))
187
-                    break;
187
+                if($begin->greaterThan($today)) {
188
+                                    break;
189
+                }
188 190
 
189
-                if($begin->notEqualTo($today))
190
-                    continue;
191
+                if($begin->notEqualTo($today)) {
192
+                                    continue;
193
+                }
191 194
 
192 195
                 $end = Carbon::parse($schedule->end_at);
193 196
 
194
-                if($this->isShouldntAdd($opening, $closing, $start, $end))
195
-                    $add = false;
197
+                if($this->isShouldntAdd($opening, $closing, $start, $end)) {
198
+                                    $add = false;
199
+                }
196 200
             }
197 201
 
198
-            if($add && $closing->lessThanOrEqualTo($closingTime))
199
-                $livres[] = [
202
+            if($add && $closing->lessThanOrEqualTo($closingTime)) {
203
+                            $livres[] = [
200 204
                     'start_at' => $opening,
201 205
                     'end_at' => $closing
202 206
                 ];
207
+            }
203 208
 
204 209
             $openingTime->addMinutes($durationMinutes);
205 210
         }
@@ -235,23 +240,27 @@  discard block
 block discarded – undo
235 240
      */
236 241
     public function validateSchedule($start_at, $end_at = null, int $status = null)
237 242
     {
238
-        if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at))
239
-            throw new CantAddWithoutEnd;
243
+        if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) {
244
+                    throw new CantAddWithoutEnd;
245
+        }
240 246
 
241 247
         $start_at  = $this->parseToCarbon($start_at);
242 248
 
243 249
         if(isset($end_at)) {
244 250
             $end_at = $this->parseToCarbon($end_at, $start_at);
245 251
 
246
-            if($start_at->greaterThan($end_at))
247
-                throw new EndCantBeforeStart;
252
+            if($start_at->greaterThan($end_at)) {
253
+                            throw new EndCantBeforeStart;
254
+            }
248 255
         }
249 256
 
250
-        if(isset($status))
251
-            ScheduleStatus::findOrFail($status);
257
+        if(isset($status)) {
258
+                    ScheduleStatus::findOrFail($status);
259
+        }
252 260
 
253
-        if($this->hasConflict($start_at, $end_at ?? $start_at))
254
-            throw new CantAddWithSameStartAt;
261
+        if($this->hasConflict($start_at, $end_at ?? $start_at)) {
262
+                    throw new CantAddWithSameStartAt;
263
+        }
255 264
 
256 265
         $model_type = $this->getModelType();
257 266
 
@@ -269,14 +278,17 @@  discard block
 block discarded – undo
269 278
      */
270 279
     public function parseToCarbon($date, $reference = null)
271 280
     {
272
-        if($date instanceof Carbon)
273
-            return $date;
281
+        if($date instanceof Carbon) {
282
+                    return $date;
283
+        }
274 284
 
275
-        if(is_string($date))
276
-            return Carbon::parse($date);
285
+        if(is_string($date)) {
286
+                    return Carbon::parse($date);
287
+        }
277 288
 
278
-        if(is_int($date) && !is_null($reference))
279
-            return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
289
+        if(is_int($date) && !is_null($reference)) {
290
+                    return Carbon::parse($reference->toDateTimeString())->addMinutes($date);
291
+        }
280 292
 
281 293
         throw new IntInvalidArgument;
282 294
     }
@@ -289,8 +301,9 @@  discard block
 block discarded – undo
289 301
      */
290 302
     public function parseToSchedule($value)
291 303
     {
292
-        if(is_int($value))
293
-            return Schedule::find($value);
304
+        if(is_int($value)) {
305
+                    return Schedule::find($value);
306
+        }
294 307
 
295 308
         return Schedule::byStartAt($value)->first();
296 309
    }
@@ -314,7 +327,8 @@  discard block
 block discarded – undo
314 327
     {
315 328
         $this->query = Schedule::query();
316 329
 
317
-        if(isset(static::$boot))
318
-            (static::$boot)($this);
330
+        if(isset(static::$boot)) {
331
+                    (static::$boot)($this);
332
+        }
319 333
     }
320 334
 }
321 335
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Contracts/SchedulerModelTrait.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -11,27 +11,27 @@  discard block
 block discarded – undo
11 11
 interface SchedulerModelInterface
12 12
 {
13 13
 	/**
14
-     * Define a one-to-one relationship.
15
-     *
16
-     * @param  string  $related
17
-     * @param  string  $foreignKey
18
-     * @param  string  $localKey
19
-     * @return \Illuminate\Database\Eloquent\Relations\HasOne
20
-     */
21
-    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
14
+	 * Define a one-to-one relationship.
15
+	 *
16
+	 * @param  string  $related
17
+	 * @param  string  $foreignKey
18
+	 * @param  string  $localKey
19
+	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
20
+	 */
21
+	abstract public function hasOne($related, $foreignKey = null, $localKey = null);
22 22
 
23 23
 	/**
24
-     * Get the value of the model's primary key.
25
-     *
26
-     * @return mixed
27
-     */
24
+	 * Get the value of the model's primary key.
25
+	 *
26
+	 * @return mixed
27
+	 */
28 28
 	abstract public function getKey();
29 29
 
30 30
 	/**
31
-     * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
32
-     *
33
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
34
-     */
31
+	 * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
32
+	 *
33
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
34
+	 */
35 35
 	public function schedules();
36 36
 
37 37
 	/**
@@ -60,21 +60,21 @@  discard block
 block discarded – undo
60 60
 	public function removeSchedule($schedule);
61 61
 
62 62
 	/**
63
-     * Retorna os horários disponiveis hoje para uma determinada model.
64
-     * .
65
-     * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
66
-     * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
67
-     * @return array
68
-     */
69
-    public function availableToday(int $duration, Carbon $openingTime = null);
63
+	 * Retorna os horários disponiveis hoje para uma determinada model.
64
+	 * .
65
+	 * @param  int $duration Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
66
+	 * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
67
+	 * @return array
68
+	 */
69
+	public function availableToday(int $duration, Carbon $openingTime = null);
70 70
 
71
-    /**
72
-     * Retorna os horários disponiveis em um determinado dia para uma certa model.
73
-     *
74
-     * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
75
-     * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
76
-     * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
77
-     * @return array
78
-     */
79
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null);
71
+	/**
72
+	 * Retorna os horários disponiveis em um determinado dia para uma certa model.
73
+	 *
74
+	 * @param  \Carbon\Carbon $today Data para o qual ele irá fazer a busca.
75
+	 * @param  int $durationMinutes Serve para facilitar na hora de buscar horários livres que precisem ter uma certa duração.
76
+	 * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
77
+	 * @return array
78
+	 */
79
+	public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null);
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,21 +18,21 @@  discard block
 block discarded – undo
18 18
      * @param  string  $localKey
19 19
      * @return \Illuminate\Database\Eloquent\Relations\HasOne
20 20
      */
21
-    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
21
+    abstract public function hasOne ($related, $foreignKey = null, $localKey = null);
22 22
 
23 23
 	/**
24 24
      * Get the value of the model's primary key.
25 25
      *
26 26
      * @return mixed
27 27
      */
28
-	abstract public function getKey();
28
+	abstract public function getKey ();
29 29
 
30 30
 	/**
31 31
      * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
32 32
      *
33 33
      * @return \Illuminate\Database\Eloquent\Relations\HasMany
34 34
      */
35
-	public function schedules();
35
+	public function schedules ();
36 36
 
37 37
 	/**
38 38
 	 * Agenda um horário para esta model.
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @param  array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado.
44 44
 	 * @return \H4ad\Scheduler\Models\Schedule
45 45
 	 */
46
-	public function addSchedule($start_at, $end_at = null, int $status = null, array $data = null);
46
+	public function addSchedule ($start_at, $end_at = null, int $status = null, array $data = null);
47 47
 
48 48
 	/**
49 49
 	 * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado.
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate
58 58
 	 * @throws \H4ad\Scheduler\Exceptions\ModelNotFound
59 59
 	 */
60
-	public function removeSchedule($schedule);
60
+	public function removeSchedule ($schedule);
61 61
 
62 62
 	/**
63 63
      * Retorna os horários disponiveis hoje para uma determinada model.
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
67 67
      * @return array
68 68
      */
69
-    public function availableToday(int $duration, Carbon $openingTime = null);
69
+    public function availableToday (int $duration, Carbon $openingTime = null);
70 70
 
71 71
     /**
72 72
      * Retorna os horários disponiveis em um determinado dia para uma certa model.
@@ -76,5 +76,5 @@  discard block
 block discarded – undo
76 76
      * @param  \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config.
77 77
      * @return array
78 78
      */
79
-    public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null);
79
+    public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null);
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.