diff --git a/composer.json b/composer.json
index 3af5364..eacdda9 100644
--- a/composer.json
+++ b/composer.json
@@ -8,5 +8,8 @@
"require-dev": {
"simplemachines/smf2.1": "dev-unittest",
"phpunit/phpunit": "^8.5"
+ },
+ "require": {
+ "php": ">=7.4"
}
}
diff --git a/src/Class-CustomForm.php b/src/Class-CustomForm.php
index 090f14d..625665b 100644
--- a/src/Class-CustomForm.php
+++ b/src/Class-CustomForm.php
@@ -1,5 +1,15 @@
+ * @copyright Copyright (c) 2014, John Rayes
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
interface CustomForm
{
/*
@@ -7,11 +17,10 @@ interface CustomForm
*
* @param array $field The field as returned by {@link total_getCustomForm()}.
* @param string $value Field value.
- * @param bool $exists Whether the value exists/is not empty.
*
* @access public
*/
- public function __construct($field, $value, $exists);
+ public function __construct(array $field, string $value);
/*
* Sets the input so the user can enter a value.
@@ -20,58 +29,55 @@ public function __construct($field, $value, $exists);
* @access public
*/
public function setHtml();
- public function validate();
+
+ /*
+ * Gets the value. This method should handle if a specific field type must be sanitized.
+ *
+ * @access public
+ * @return string
+ */
+ public function getValue(): string;
+ public function validate(): bool;
}
abstract class CustomFormBase implements CustomForm
{
- public $input_html;
- public $output_html;
- protected $field;
- protected $err = false;
- protected $exists = false;
- protected $type_vars = array();
- protected $value = '';
- protected $size = 0;
- protected $default = '';
- protected $required = false;
-
- public function __construct($field, $value, $exists)
+ public string $input_html;
+ public string $output_html;
+ protected array $field;
+ protected array $err = [];
+ protected bool $exists = false;
+ protected array $type_vars = array();
+ protected string $value = '';
+ protected int $size = 0;
+ protected string $default = '';
+ protected bool $required = false;
+
+ public function __construct(array $field, string $value)
{
$this->field = $field;
$this->value = $value;
- $this->exists = $exists;
+ $this->exists = !empty($value);
}
/*
* Gets the error generated by the validation method.
*
* @access public
- * @return string|false The error string or false for no error.
+ * @return array
*/
- public function getError()
+ public function getError(): array
{
return $this->err;
}
- /*
- * Gets the value. This method may be overridden if a specific field type must be sanitized.
- *
- * @access public
- * @return string
- */
- public function getValue()
- {
- return $this->value;
- }
-
/**
* Returns the input so the user can enter a value.
*
* @access public
- * @return mixed
+ * @return string
*/
- public function getInputHtml()
+ public function getInputHtml(): string
{
return $this->input_html;
}
@@ -80,9 +86,9 @@ public function getInputHtml()
* Returns the output. It's the field's value formatted acccording to its criteria.
*
* @access public
- * @return mixed
+ * @return string
*/
- public function getOutputHtml()
+ public function getOutputHtml(): string
{
return $this->output_html;
}
@@ -118,16 +124,23 @@ public function setHtml()
{
global $txt;
$true = (!$this->exists && $this->default) || $this->value;
- $this->input_html = '';
- $this->output_html = $true ? $txt['yes'] : $txt['no'];
+ $this->input_html .= sprintf(
+ '',
+ 'CustomFormField',
+ $this->field['id_field'],
+ $true ? ' checked' : ''
+ );
+ $this->output_html = $txt[$this->getValue()];
}
- public function validate()
+ public function validate(): bool
{
- // Nothing needed here, really. It's just a get out of jail free card. "This card may be kept until needed, or sold."
+ // Nothing needed here, really. It's just a get out of jail
+ // free card. "This card may be kept until needed, or sold."
+ return true;
}
- public function getValue()
+ public function getValue(): string
{
- return (!$this->exists && $this->default) || $this->value;
+ return (!$this->exists && $this->default) || $this->value ? 'yes' : 'no';
}
}
@@ -135,35 +148,40 @@ class CustomForm_select extends CustomFormBase
{
public function setHtml()
{
- $this->input_html = '