Form/Formfield : Add the return types for the methods

This commit is contained in:
2023-06-20 08:39:29 +02:00
parent 9f028ac798
commit 46979352b8
2 changed files with 52 additions and 52 deletions

View File

@@ -91,7 +91,7 @@ class Form
* Set the debug level * Set the debug level
* @param integer $val The debug value * @param integer $val The debug value
*/ */
public function debug($val) public function debug($val): self
{ {
$this->debug = $val; $this->debug = $val;
return $this; return $this;
@@ -101,7 +101,7 @@ class Form
* Set the csrf enable * Set the csrf enable
* @param integer $val The csrf check * @param integer $val The csrf check
*/ */
public function csrf($val) public function csrf($val): self
{ {
$this->csrf = !! $val; $this->csrf = !! $val;
return $this; return $this;
@@ -111,7 +111,7 @@ class Form
* Set the method * Set the method
* @param string $val The method to use * @param string $val The method to use
*/ */
public function method($val) public function method($val): self
{ {
$this->method = strtolower($val); $this->method = strtolower($val);
return $this; return $this;
@@ -121,7 +121,7 @@ class Form
* Set the csrf token name * Set the csrf token name
* @param integer $val The csrf token name * @param integer $val The csrf token name
*/ */
public function csrfField($val) public function csrfField($val): self
{ {
$this->csrfField = $val; $this->csrfField = $val;
return $this; return $this;
@@ -131,7 +131,7 @@ class Form
* Set the titlewidth * Set the titlewidth
* @param integer $val The titlewidth * @param integer $val The titlewidth
*/ */
public function titlewidth($val) public function titlewidth($val): self
{ {
$this->titlewidth = $val; $this->titlewidth = $val;
return $this; return $this;
@@ -141,7 +141,7 @@ class Form
* Set the fieldwidth * Set the fieldwidth
* @param integer $val The fieldwidth * @param integer $val The fieldwidth
*/ */
public function fieldwidth($val) public function fieldwidth($val): self
{ {
$this->fieldwidth = $val; $this->fieldwidth = $val;
return $this; return $this;
@@ -151,7 +151,7 @@ class Form
* Set the formClass * Set the formClass
* @param integer $val The formClass * @param integer $val The formClass
*/ */
public function formClass($val) public function formClass($val): self
{ {
$this->formClass = $val; $this->formClass = $val;
return $this; return $this;
@@ -164,7 +164,7 @@ class Form
* @param string|null $loggingBasemsg The basemsg added at the beginning of * @param string|null $loggingBasemsg The basemsg added at the beginning of
* the log * the log
*/ */
public function logging($loggingCallable, $loggingBasemsg = "") public function logging($loggingCallable, $loggingBasemsg = ""): void
{ {
$this->loggingCallable = $loggingCallable; $this->loggingCallable = $loggingCallable;
$this->loggingBasemsg = $loggingBasemsg; $this->loggingBasemsg = $loggingBasemsg;
@@ -175,7 +175,7 @@ class Form
* Can be : Bootstrap3, Bootstrap4 (later Bulma) * Can be : Bootstrap3, Bootstrap4 (later Bulma)
* @param string $formTemplate The template to use * @param string $formTemplate The template to use
*/ */
public function formTemplate($formTemplate) public function formTemplate($formTemplate): self
{ {
if ( if (
! in_array( ! in_array(
@@ -195,7 +195,7 @@ class Form
* @param integer $prio The priority of the message * @param integer $prio The priority of the message
* @param string $msg The message to store * @param string $msg The message to store
*/ */
private function loggingCallable($prio, $msg) private function loggingCallable($prio, $msg): void
{ {
if (! is_callable($this->loggingCallable)) { if (! is_callable($this->loggingCallable)) {
return; return;
@@ -236,7 +236,7 @@ class Form
* *
* @param array $fields The fields to be displayed * @param array $fields The fields to be displayed
*/ */
public function fields($fields) public function fields($fields): void
{ {
$this->fields = $fields; $this->fields = $fields;
} }
@@ -246,7 +246,7 @@ class Form
* in fields method * in fields method
* @param object $field The field to add * @param object $field The field to add
*/ */
public function addfield($field) public function addfield($field): void
{ {
$this->fields[] = $field; $this->fields[] = $field;
} }
@@ -256,7 +256,7 @@ class Form
* NEVER read the values from $_POST in your codes or CSRF will not be * NEVER read the values from $_POST in your codes or CSRF will not be
* checked * checked
*/ */
public function values() public function values(): array
{ {
$values = []; $values = [];
if ($this->method === "post") { if ($this->method === "post") {
@@ -328,7 +328,7 @@ class Form
$method = 'post', $method = 'post',
$values = null, $values = null,
$errors = [] $errors = []
) { ): string {
if (count($this->fields) === 0) { if (count($this->fields) === 0) {
$this->loggingCallable( $this->loggingCallable(
LOG_ERR, LOG_ERR,
@@ -456,7 +456,7 @@ class Form
* Check the token from the user * Check the token from the user
* @param string $tokenFromUser The value form the user's token * @param string $tokenFromUser The value form the user's token
*/ */
public function checkToken($tokenFromUser) public function checkToken($tokenFromUser): void
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$csrf->field = $this->csrfField; $csrf->field = $this->csrfField;
@@ -468,7 +468,7 @@ class Form
/** /**
* Return the token generated in form * Return the token generated in form
*/ */
public function getToken() public function getToken(): string
{ {
if ($this->csrfToken === "") { if ($this->csrfToken === "") {
$csrf = new Csrf(); $csrf = new Csrf();
@@ -485,7 +485,7 @@ class Form
* stored one if the value is null) * stored one if the value is null)
* @return array containing the errors * @return array containing the errors
*/ */
public function verify($values, $fields = []) public function verify($values, $fields = []): array
{ {
if (count($fields) === 0) { if (count($fields) === 0) {
if (! isset($_SESSION["domframework"]["form"]["fields"])) { if (! isset($_SESSION["domframework"]["form"]["fields"])) {
@@ -529,7 +529,7 @@ class Form
* $spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]); * $spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]);
* $route->redirect ("/admin/space/"); * $route->redirect ("/admin/space/");
*/ */
public function redirectIfError($values, $errors, $route, $url = "") public function redirectIfError($values, $errors, $route, $url = ""): void
{ {
$this->saveValuesErrors($values, $errors); $this->saveValuesErrors($values, $errors);
if ($url === "") { if ($url === "") {
@@ -548,7 +548,7 @@ class Form
* @param array $values The values of the fields filled by the user * @param array $values The values of the fields filled by the user
* @param array|null $errors The errors detected by a verify * @param array|null $errors The errors detected by a verify
*/ */
public function saveValuesErrors($values, $errors = []) public function saveValuesErrors($values, $errors = []): void
{ {
if (isset($_SESSION)) { if (isset($_SESSION)) {
$_SESSION["domframework"]["form"][$this->formName]["values"] = $values; $_SESSION["domframework"]["form"][$this->formName]["values"] = $values;
@@ -560,7 +560,7 @@ class Form
* Reset the saved values to provide a clean form next page * Reset the saved values to provide a clean form next page
* Need the session to work * Need the session to work
*/ */
public function saveValuesErrorsReset() public function saveValuesErrorsReset(): void
{ {
unset($_SESSION["domframework"]["form"][$this->formName]["values"]); unset($_SESSION["domframework"]["form"][$this->formName]["values"]);
unset($_SESSION["domframework"]["form"][$this->formName]["errors"]); unset($_SESSION["domframework"]["form"][$this->formName]["errors"]);
@@ -572,7 +572,7 @@ class Form
* @param array $values The values returned if there is no stored values * @param array $values The values returned if there is no stored values
* @return array The values to use * @return array The values to use
*/ */
public function getOldValues($values) public function getOldValues($values): array
{ {
if (isset($_SESSION["domframework"]["form"][$this->formName]["values"])) { if (isset($_SESSION["domframework"]["form"][$this->formName]["values"])) {
$values = $_SESSION["domframework"]["form"][$this->formName]["values"]; $values = $_SESSION["domframework"]["form"][$this->formName]["values"];
@@ -587,7 +587,7 @@ class Form
* @param array $errors The values returned if there is no stored values * @param array $errors The values returned if there is no stored values
* @return array The errors to use * @return array The errors to use
*/ */
public function getOldErrors($errors) public function getOldErrors($errors): array
{ {
if (isset($_SESSION["domframework"]["form"][$this->formName]["errors"])) { if (isset($_SESSION["domframework"]["form"][$this->formName]["errors"])) {
$errors = $_SESSION["domframework"]["form"][$this->formName]["errors"]; $errors = $_SESSION["domframework"]["form"][$this->formName]["errors"];
@@ -606,7 +606,7 @@ class Form
* @param string $outputFormat The output format of the date * @param string $outputFormat The output format of the date
* @return string * @return string
*/ */
public function convertDate($inputDate, $inputFormat, $outputFormat) public function convertDate($inputDate, $inputFormat, $outputFormat): string
{ {
$date = \DateTime::CreateFromFormat($inputFormat, $inputDate); $date = \DateTime::CreateFromFormat($inputFormat, $inputDate);
if ($date === false) { if ($date === false) {

View File

@@ -106,7 +106,7 @@ class Formfield
/** /**
* Display really the form * Display really the form
*/ */
public function display() public function display(): string
{ {
$func = "field" . $this->formTemplate . $this->type; $func = "field" . $this->formTemplate . $this->type;
return $this->$func(); return $this->$func();
@@ -117,7 +117,7 @@ class Formfield
* Set the type of the field * Set the type of the field
* @param string $val The value of the type of the field * @param string $val The value of the type of the field
*/ */
public function type($val) public function type($val): self
{ {
$this->type = $val; $this->type = $val;
return $this; return $this;
@@ -127,7 +127,7 @@ class Formfield
* Set the hidden of the field * Set the hidden of the field
* @param string $val The value of the hidden of the field * @param string $val The value of the hidden of the field
*/ */
public function hidden($val) public function hidden($val): self
{ {
$this->hidden = !! $val; $this->hidden = !! $val;
return $this; return $this;
@@ -137,7 +137,7 @@ class Formfield
* Set the help of the field * Set the help of the field
* @param string $val The value of the help of the field * @param string $val The value of the help of the field
*/ */
public function help($val) public function help($val): self
{ {
$this->help = $val; $this->help = $val;
return $this; return $this;
@@ -147,7 +147,7 @@ class Formfield
* Set the placeholder * Set the placeholder
* @param string $val The value of the placeholder * @param string $val The value of the placeholder
*/ */
public function placeholder($val) public function placeholder($val): self
{ {
$this->placeholder = $val; $this->placeholder = $val;
return $this; return $this;
@@ -157,7 +157,7 @@ class Formfield
* Set the multiple * Set the multiple
* @param string $val The value of the multiple * @param string $val The value of the multiple
*/ */
public function multiple($val) public function multiple($val): self
{ {
$this->multiple = $val; $this->multiple = $val;
return $this; return $this;
@@ -167,7 +167,7 @@ class Formfield
* Set the group * Set the group
* @param string $val The value of the group * @param string $val The value of the group
*/ */
public function group($val) public function group($val): self
{ {
$this->group = $val; $this->group = $val;
return $this; return $this;
@@ -177,7 +177,7 @@ class Formfield
* Set the readonly * Set the readonly
* @param string $val The value of the readonly * @param string $val The value of the readonly
*/ */
public function readonly($val) public function readonly($val): self
{ {
$this->readonly = !! $val; $this->readonly = !! $val;
return $this; return $this;
@@ -187,7 +187,7 @@ class Formfield
* Set the mandatory * Set the mandatory
* @param string $val The value of the mandatory * @param string $val The value of the mandatory
*/ */
public function mandatory($val) public function mandatory($val): self
{ {
$this->mandatory = !! $val; $this->mandatory = !! $val;
return $this; return $this;
@@ -197,7 +197,7 @@ class Formfield
* Set the rows * Set the rows
* @param string $val The value of the rows * @param string $val The value of the rows
*/ */
public function rows($val) public function rows($val): self
{ {
$this->rows = $val; $this->rows = $val;
return $this; return $this;
@@ -207,7 +207,7 @@ class Formfield
* Set the cols * Set the cols
* @param string $val The value of the cols * @param string $val The value of the cols
*/ */
public function cols($val) public function cols($val): self
{ {
$this->cols = $val; $this->cols = $val;
return $this; return $this;
@@ -219,7 +219,7 @@ class Formfield
/** /**
* Return the checkbox defined * Return the checkbox defined
*/ */
private function fieldBootstrap3checkbox() private function fieldBootstrap3checkbox(): string
{ {
// No $this->multiple, $this->rows $this->cols $this->placeholder, // No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength // $this->maxlength
@@ -366,7 +366,7 @@ class Formfield
/** /**
* Return the hidden field defined * Return the hidden field defined
*/ */
private function fieldBootstrap3hidden() private function fieldBootstrap3hidden(): string
{ {
$res = ""; $res = "";
// No $this->label, $this->multiple, $this->readonly, $this->hidden, // No $this->label, $this->multiple, $this->readonly, $this->hidden,
@@ -388,7 +388,7 @@ class Formfield
/** /**
* Return the password field defined * Return the password field defined
*/ */
private function fieldBootstrap3password() private function fieldBootstrap3password(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols // No $this->multiple, $this->rows $this->cols
@@ -472,7 +472,7 @@ class Formfield
/** /**
* Return the radio field defined * Return the radio field defined
*/ */
private function fieldBootstrap3radio() private function fieldBootstrap3radio(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols $this->placeholder // No $this->multiple, $this->rows $this->cols $this->placeholder
@@ -574,7 +574,7 @@ class Formfield
/** /**
* Return the checkbox defined * Return the checkbox defined
*/ */
private function fieldBootstrap3select() private function fieldBootstrap3select(): string
{ {
// No $this->placeholder $this->maxlength // No $this->placeholder $this->maxlength
$res = ""; $res = "";
@@ -704,7 +704,7 @@ class Formfield
/** /**
* Return the submit defined * Return the submit defined
*/ */
private function fieldBootstrap3submit() private function fieldBootstrap3submit(): string
{ {
$res = ""; $res = "";
// No $this->label, $this->multiple, $this->error, $this->rows, // No $this->label, $this->multiple, $this->error, $this->rows,
@@ -749,7 +749,7 @@ class Formfield
/** /**
* Return the textarea defined * Return the textarea defined
*/ */
private function fieldBootstrap3textarea() private function fieldBootstrap3textarea(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles // No $this->multiple, $this->titles
@@ -835,7 +835,7 @@ class Formfield
/** /**
* Return the text defined * Return the text defined
*/ */
private function fieldBootstrap3text() private function fieldBootstrap3text(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols // No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -919,7 +919,7 @@ class Formfield
/** /**
* Return the file defined * Return the file defined
*/ */
private function fieldBootstrap3file() private function fieldBootstrap3file(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols // No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -1021,7 +1021,7 @@ class Formfield
/** /**
* Return the checkbox defined * Return the checkbox defined
*/ */
private function fieldBootstrap4checkbox() private function fieldBootstrap4checkbox(): string
{ {
// No $this->multiple, $this->rows $this->cols $this->placeholder, // No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength // $this->maxlength
@@ -1176,7 +1176,7 @@ class Formfield
/** /**
* Return the hidden field defined * Return the hidden field defined
*/ */
private function fieldBootstrap4hidden() private function fieldBootstrap4hidden(): string
{ {
$res = ""; $res = "";
// No $this->label, $this->multiple, $this->readonly, $this->hidden, // No $this->label, $this->multiple, $this->readonly, $this->hidden,
@@ -1198,7 +1198,7 @@ class Formfield
/** /**
* Return the password field defined * Return the password field defined
*/ */
private function fieldBootstrap4password() private function fieldBootstrap4password(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols // No $this->multiple, $this->rows $this->cols
@@ -1290,7 +1290,7 @@ class Formfield
/** /**
* Return the radio field defined * Return the radio field defined
*/ */
private function fieldBootstrap4radio() private function fieldBootstrap4radio(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols $this->placeholder // No $this->multiple, $this->rows $this->cols $this->placeholder
@@ -1400,7 +1400,7 @@ class Formfield
/** /**
* Return the checkbox defined * Return the checkbox defined
*/ */
private function fieldBootstrap4select() private function fieldBootstrap4select(): string
{ {
// No $this->placeholder $this->maxlength // No $this->placeholder $this->maxlength
$res = ""; $res = "";
@@ -1538,7 +1538,7 @@ class Formfield
/** /**
* Return the submit defined * Return the submit defined
*/ */
private function fieldBootstrap4submit() private function fieldBootstrap4submit(): string
{ {
$res = ""; $res = "";
// No $this->label, $this->multiple, $this->error, $this->rows, // No $this->label, $this->multiple, $this->error, $this->rows,
@@ -1583,7 +1583,7 @@ class Formfield
/** /**
* Return the textarea defined * Return the textarea defined
*/ */
private function fieldBootstrap4textarea() private function fieldBootstrap4textarea(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles // No $this->multiple, $this->titles
@@ -1677,7 +1677,7 @@ class Formfield
/** /**
* Return the text defined * Return the text defined
*/ */
private function fieldBootstrap4text() private function fieldBootstrap4text(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols // No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -1769,7 +1769,7 @@ class Formfield
/** /**
* Return the file defined * Return the file defined
*/ */
private function fieldBootstrap4file() private function fieldBootstrap4file(): string
{ {
$res = ""; $res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols // No $this->multiple, $this->titles, $this->rows, $this->cols