Passed
Push — master ( 72070c...1d1702 )
by Vinicius Lourenço
03:38
created
src/Scheduler/Exceptions/CustomException.php 1 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.
src/Scheduler/Scheduler.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -14,107 +14,107 @@
 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|\Carbon\Carbon $start_at
40
-     * @param string|\Carbon\Carbon $end_at
41
-     * @return bool
42
-     */
43
-    public function hasScheduleBetween($model_type, $start_at, $end_at)
44
-    {
45
-        if(!Config::get('scheduler.enable_schedule_conflict'))
46
-            return false;
47
-
48
-        return !is_null(
49
-            Schedule::latest()
50
-                ->where('model_type', $model_type)
51
-                ->where('start_at', '>=', $start_at)
52
-                ->where('end_at', '<=', $end_at)
53
-                ->first()
54
-        );
55
-    }
56
-
57
-    /**
58
-     * Retorna os horários disponiveis hoje para uma determinada model.
59
-     * .
60
-     * @param  string  $model_type Tipo da model
61
-     * @param  int    $duration Serve para facilitar na hora de buscar horários livres
62
-     *                          que precisem ter uma certa duração.
63
-     * @return array
64
-     */
65
-    public function availableToday($model_type, $duration)
66
-    {
67
-        return $this->availableOn($model_type, Carbon::now(), $duration);
68
-    }
69
-
70
-    /**
71
-     * Retorna os horários disponiveis em um determinado dia para uma certa model.
72
-     *
73
-     * @param  string  $model_type Tipo da model
74
-     * @param  string|\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
76
-     *                          que precisem ter uma certa duração.
77
-     * @return array
78
-     */
79
-    public function availableOn($model_type, $today, $durationMinutes)
80
-    {
81
-        $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
82
-        $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
83
-
84
-        $livres = [];
85
-        $today = Carbon::parse($today->toDateString());
86
-        while($openingTime <= $closingTime)
87
-        {
88
-            $add = true;
89
-
90
-            foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) {
91
-            	if($schedule->model_type != $model_type)
92
-            		continue;
93
-
94
-                $start = Carbon::parse($schedule->start_at);
95
-                $begin = Carbon::parse($start->toDateString());
96
-
97
-                if($begin->greaterThan($today))
98
-                    break;
99
-
100
-                if($begin->notEqualTo($today))
101
-                    continue;
102
-
103
-                $end = Carbon::parse($schedule->end_at);
104
-                if($start <= Carbon::parse($openingTime->toDateTimeString())
105
-                && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes))
106
-                    $add = false;
107
-            }
108
-
109
-            if($add)
110
-                $livres[] = [
111
-                    'start_at' => Carbon::parse($openingTime->toDateTimeString()),
112
-                    'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)
113
-                ];
114
-
115
-            $openingTime->addMinutes($durationMinutes);
116
-        }
117
-
118
-        return $livres;
119
-    }
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|\Carbon\Carbon $start_at
40
+	 * @param string|\Carbon\Carbon $end_at
41
+	 * @return bool
42
+	 */
43
+	public function hasScheduleBetween($model_type, $start_at, $end_at)
44
+	{
45
+		if(!Config::get('scheduler.enable_schedule_conflict'))
46
+			return false;
47
+
48
+		return !is_null(
49
+			Schedule::latest()
50
+				->where('model_type', $model_type)
51
+				->where('start_at', '>=', $start_at)
52
+				->where('end_at', '<=', $end_at)
53
+				->first()
54
+		);
55
+	}
56
+
57
+	/**
58
+	 * Retorna os horários disponiveis hoje para uma determinada model.
59
+	 * .
60
+	 * @param  string  $model_type Tipo da model
61
+	 * @param  int    $duration Serve para facilitar na hora de buscar horários livres
62
+	 *                          que precisem ter uma certa duração.
63
+	 * @return array
64
+	 */
65
+	public function availableToday($model_type, $duration)
66
+	{
67
+		return $this->availableOn($model_type, Carbon::now(), $duration);
68
+	}
69
+
70
+	/**
71
+	 * Retorna os horários disponiveis em um determinado dia para uma certa model.
72
+	 *
73
+	 * @param  string  $model_type Tipo da model
74
+	 * @param  string|\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
76
+	 *                          que precisem ter uma certa duração.
77
+	 * @return array
78
+	 */
79
+	public function availableOn($model_type, $today, $durationMinutes)
80
+	{
81
+		$openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today);
82
+		$closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today);
83
+
84
+		$livres = [];
85
+		$today = Carbon::parse($today->toDateString());
86
+		while($openingTime <= $closingTime)
87
+		{
88
+			$add = true;
89
+
90
+			foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) {
91
+				if($schedule->model_type != $model_type)
92
+					continue;
93
+
94
+				$start = Carbon::parse($schedule->start_at);
95
+				$begin = Carbon::parse($start->toDateString());
96
+
97
+				if($begin->greaterThan($today))
98
+					break;
99
+
100
+				if($begin->notEqualTo($today))
101
+					continue;
102
+
103
+				$end = Carbon::parse($schedule->end_at);
104
+				if($start <= Carbon::parse($openingTime->toDateTimeString())
105
+				&& $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes))
106
+					$add = false;
107
+			}
108
+
109
+			if($add)
110
+				$livres[] = [
111
+					'start_at' => Carbon::parse($openingTime->toDateTimeString()),
112
+					'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)
113
+				];
114
+
115
+			$openingTime->addMinutes($durationMinutes);
116
+		}
117
+
118
+		return $livres;
119
+	}
120 120
 }
121 121
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scheduler/Traits/SchedulerModelTrait.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,28 +27,28 @@
 block discarded – undo
27 27
 trait SchedulerModelTrait
28 28
 {
29 29
 	/**
30
-     * Define an inverse one-to-one or many relationship.
31
-     *
32
-     * @param  string  $related
33
-     * @param  string  $foreignKey
34
-     * @param  string  $ownerKey
35
-     * @param  string  $relation
36
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
37
-     */
30
+	 * Define an inverse one-to-one or many relationship.
31
+	 *
32
+	 * @param  string  $related
33
+	 * @param  string  $foreignKey
34
+	 * @param  string  $ownerKey
35
+	 * @param  string  $relation
36
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
37
+	 */
38 38
 	abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null);
39 39
 
40 40
 	/**
41
-     * Get the value of the model's primary key.
42
-     *
43
-     * @return mixed
44
-     */
41
+	 * Get the value of the model's primary key.
42
+	 *
43
+	 * @return mixed
44
+	 */
45 45
 	abstract public function getKey();
46 46
 
47 47
 	/**
48
-     * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
49
-     *
50
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
-     */
48
+	 * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait].
49
+	 *
50
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
+	 */
52 52
 	public function schedules()
53 53
 	{
54 54
 		return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id');
Please login to merge, or discard this patch.