Skip to content

Commit 851b8f3

Browse files
committed
Se agregan métodos a StatusInterface para poder conocer el tipo de estado por categoría.
1 parent 3003d6f commit 851b8f3

2 files changed

Lines changed: 125 additions & 11 deletions

File tree

src/Contract/StatusInterface.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,52 @@ public function getBadgeClass(): string;
9393
public function getBtnClass(): string;
9494

9595
/**
96-
* Bootstrap Icons class name (requires bootstrap-icons).
96+
* Icon classes.
9797
*
98-
* @return string e.g. "bi-check-circle-fill"
98+
* For example Font Awesome or Bootstrap Icons.
99+
*
100+
* @return string e.g. "fa-solid fa-circle-check"
99101
*/
100102
public function getIcon(): string;
103+
104+
/**
105+
* Returns true if this status represents a successful outcome.
106+
*/
107+
public function isSuccess(): bool;
108+
109+
/**
110+
* Returns true if this status represents an error or failure.
111+
*/
112+
public function isError(): bool;
113+
114+
/**
115+
* Returns true if this status represents a non-critical warning.
116+
*/
117+
public function isWarning(): bool;
118+
119+
/**
120+
* Returns true if this status represents an informational message.
121+
*/
122+
public function isInfo(): bool;
123+
124+
/**
125+
* Returns true if this status is decorative or has no semantic outcome.
126+
*
127+
* Covers primary, secondary, light, and dark in the default implementation.
128+
*/
129+
public function isNeutral(): bool;
130+
131+
/**
132+
* Returns true if this status has a positive connotation.
133+
*
134+
* Covers success and info in the default implementation.
135+
*/
136+
public function isPositive(): bool;
137+
138+
/**
139+
* Returns true if this status has a negative connotation.
140+
*
141+
* Covers danger and warning in the default implementation.
142+
*/
143+
public function isNegative(): bool;
101144
}

src/Status.php

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Derafu: Enum - Yet Another List of Enumerations for PHP.
77
*
8-
* Copyright (c) 2025 Esteban De La Fuente Rubio / Derafu <https://www.derafu.dev>
8+
* Copyright (c) 2026 Esteban De La Fuente Rubio / Derafu <https://www.derafu.dev>
99
* Licensed under the MIT License.
1010
* See LICENSE file for more details.
1111
*/
@@ -139,19 +139,90 @@ public function getBtnClass(): string
139139
}
140140

141141
/**
142+
* Font Awesome icon classes.
143+
*
144+
* User must add the fa-fw class if needed.
145+
*
142146
* {@inheritDoc}
143147
*/
144148
public function getIcon(): string
145149
{
146150
return match($this) {
147-
Status::Success => 'bi-check-circle-fill',
148-
Status::Danger => 'bi-x-circle-fill',
149-
Status::Warning => 'bi-exclamation-triangle-fill',
150-
Status::Info => 'bi-info-circle-fill',
151-
Status::Primary => 'bi-star-fill',
152-
Status::Secondary => 'bi-circle-fill',
153-
Status::Light => 'bi-sun-fill',
154-
Status::Dark => 'bi-moon-fill',
151+
Status::Success => 'fa-solid fa-circle-check',
152+
Status::Danger => 'fa-solid fa-circle-xmark',
153+
Status::Warning => 'fa-solid fa-triangle-exclamation',
154+
Status::Info => 'fa-solid fa-circle-info',
155+
Status::Primary => 'fa-solid fa-star',
156+
Status::Secondary => 'fa-solid fa-circle',
157+
Status::Light => 'fa-solid fa-sun',
158+
Status::Dark => 'fa-solid fa-moon',
155159
};
156160
}
161+
162+
/**
163+
* {@inheritDoc}
164+
*/
165+
public function isSuccess(): bool
166+
{
167+
return $this === Status::Success;
168+
}
169+
170+
/**
171+
* {@inheritDoc}
172+
*/
173+
public function isError(): bool
174+
{
175+
return $this === Status::Danger;
176+
}
177+
178+
/**
179+
* {@inheritDoc}
180+
*/
181+
public function isWarning(): bool
182+
{
183+
return $this === Status::Warning;
184+
}
185+
186+
/**
187+
* {@inheritDoc}
188+
*/
189+
public function isInfo(): bool
190+
{
191+
return $this === Status::Info;
192+
}
193+
194+
/**
195+
* {@inheritDoc}
196+
*/
197+
public function isNeutral(): bool
198+
{
199+
return in_array($this, [
200+
Status::Primary,
201+
Status::Secondary,
202+
Status::Light,
203+
Status::Dark,
204+
], strict: true);
205+
}
206+
207+
/**
208+
* {@inheritDoc}
209+
*/
210+
public function isPositive(): bool
211+
{
212+
return in_array($this, [
213+
Status::Success,
214+
Status::Info,
215+
], strict: true);
216+
}
217+
218+
/**
219+
* {@inheritDoc}
220+
*/
221+
public function isNegative(): bool
222+
{
223+
return in_array($this, [
224+
Status::Danger,
225+
Status::Warning,
226+
], strict: true);
227+
}
157228
}

0 commit comments

Comments
 (0)