Skip to content

Commit

Permalink
Refactor input classes to implement required interface. (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 8, 2024
1 parent 8677a7d commit 8f11b05
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 16 deletions.
1 change: 1 addition & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"PHPForge\\Html\\Attribute\\HasId::getId",
"PHPForge\\Html\\Attribute\\HasId::id",
"PHPForge\\Html\\Attribute\\Input\\CanBeChecked::checked",
"PHPForge\\Html\\Attribute\\Input\\CanBeRequired::required",
"PHPForge\\Html\\Attribute\\Input\\HasName::name",
"PHPForge\\Html\\Attribute\\Input\\HasPlaceholder::placeholder",
"PHPForge\\Html\\Attribute\\Input\\HasValue::value",
Expand Down
9 changes: 6 additions & 3 deletions src/Input/Base/AbstractChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use PHPForge\Html\Attribute;
use PHPForge\Html\Input\Checkbox;
use PHPForge\Html\Input\CheckedValueInterface;
use PHPForge\Html\Input\Contract\ChoiceInterface;
use PHPForge\Html\Input\Contract;
use PHPForge\Html\Input\Radio;
use PHPForge\Html\Tag;
use PHPForge\Widget\Element;

abstract class AbstractChoiceList extends Element implements CheckedValueInterface, ChoiceInterface
abstract class AbstractChoiceList extends Element implements
Contract\CheckedValueInterface,
Contract\ChoiceInterface,
Contract\RequiredInterface
{
use Attribute\Aria\HasAriaDescribedBy;
use Attribute\Aria\HasAriaLabel;
Expand All @@ -31,6 +33,7 @@ abstract class AbstractChoiceList extends Element implements CheckedValueInterfa
use Attribute\HasTabindex;
use Attribute\Input\CanBeChecked;
use Attribute\Input\CanBeRequired;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasName;
use Attribute\Input\HasValue;

Expand Down
8 changes: 5 additions & 3 deletions src/Input/Base/AbstractInputChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
namespace PHPForge\Html\Input\Base;

use PHPForge\Html\Attribute;
use PHPForge\Html\Input\CheckedValueInterface;
use PHPForge\Html\Input\Contract\ChoiceInterface;
use PHPForge\Html\Input\Contract;
use PHPForge\Html\Label;
use PHPForge\Html\Tag;
use PHPForge\Widget\Element;

/**
* Provides a foundation for creating HTML elements with various attributes and content.
*/
abstract class AbstractInputChoice extends Element implements CheckedValueInterface, ChoiceInterface
abstract class AbstractInputChoice extends Element implements
Contract\CheckedValueInterface,
Contract\ChoiceInterface,
Contract\RequiredInterface
{
use Attribute\Aria\HasAriaDescribedBy;
use Attribute\Aria\HasAriaLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Input;
namespace PHPForge\Html\Input\Contract;

/**
* Provide methods for handling HTML checked value-related attributes and properties.
Expand Down
24 changes: 24 additions & 0 deletions src/Input/Contract/RequiredInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace PHPForge\Html\Input\Contract;

/**
* Provide methods for handling HTML validation-related required attributes.
*/
interface RequiredInterface
{
/**
* Set the required attribute which, if present, indicates that the user must specify a value for the input before
* the owning form can be submitted.
*
* The required attribute is supported by text, search, url, tel, email, date, month, week, time, datetime-local,
* number, password, checkbox, radio, and file inputs.
*
* @return static A new instance of the current class with the specified required value.
*
* @link https://www.w3.org/TR/html52/sec-forms.html#the-required-attribute
*/
public function required(): static;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Input;
namespace PHPForge\Html\Input\Contract;

/**
* Provide methods for handling HTML rule-related attributes from validators.
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.date.html#input.date
*/
final class Date extends Base\AbstractInput
final class Date extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.datetime.html#input.datetime
*/
final class Datetime extends Base\AbstractInput
final class Datetime extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/DatetimeLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.datetime-local.html#input.datetime-local
*/
final class DatetimeLocal extends Base\AbstractInput
final class DatetimeLocal extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.month.html#input.month
*/
final class Month extends Base\AbstractInput
final class Month extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down
6 changes: 4 additions & 2 deletions src/Input/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace PHPForge\Html\Input;

use PHPForge\Html\Attribute;
use PHPForge\Html\Input\Contract\PlaceholderInterface;

/**
* The input element with a type attribute whose value is "text" represents a one-line plain text edit control for the
* input element’s value.
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.text.html#input.text
*/
final class Text extends Base\AbstractInput implements RuleHtmlByAttributeInterface, PlaceholderInterface
final class Text extends Base\AbstractInput implements
Contract\PlaceholderInterface,
Contract\RequiredInterface,
Contract\RuleHtmlByAttributeInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.time.html#input.time
*/
final class Time extends Base\AbstractInput
final class Time extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.week.html#input.week
*/
final class Week extends Base\AbstractInput
final class Week extends Base\AbstractInput implements Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMax;
use Attribute\Input\HasMin;
use Attribute\Input\HasStep;
Expand Down

0 comments on commit 8f11b05

Please sign in to comment.