From 46979352b873c0430a51d76c00555ba8db424d4e Mon Sep 17 00:00:00 2001 From: Dominique FOURNIER Date: Tue, 20 Jun 2023 08:39:29 +0200 Subject: [PATCH] Form/Formfield : Add the return types for the methods --- src/Form.php | 46 ++++++++++++++++++------------------- src/Formfield.php | 58 +++++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/Form.php b/src/Form.php index b4decb3..6909286 100644 --- a/src/Form.php +++ b/src/Form.php @@ -91,7 +91,7 @@ class Form * Set the debug level * @param integer $val The debug value */ - public function debug($val) + public function debug($val): self { $this->debug = $val; return $this; @@ -101,7 +101,7 @@ class Form * Set the csrf enable * @param integer $val The csrf check */ - public function csrf($val) + public function csrf($val): self { $this->csrf = !! $val; return $this; @@ -111,7 +111,7 @@ class Form * Set the method * @param string $val The method to use */ - public function method($val) + public function method($val): self { $this->method = strtolower($val); return $this; @@ -121,7 +121,7 @@ class Form * Set the csrf token name * @param integer $val The csrf token name */ - public function csrfField($val) + public function csrfField($val): self { $this->csrfField = $val; return $this; @@ -131,7 +131,7 @@ class Form * Set the titlewidth * @param integer $val The titlewidth */ - public function titlewidth($val) + public function titlewidth($val): self { $this->titlewidth = $val; return $this; @@ -141,7 +141,7 @@ class Form * Set the fieldwidth * @param integer $val The fieldwidth */ - public function fieldwidth($val) + public function fieldwidth($val): self { $this->fieldwidth = $val; return $this; @@ -151,7 +151,7 @@ class Form * Set the formClass * @param integer $val The formClass */ - public function formClass($val) + public function formClass($val): self { $this->formClass = $val; return $this; @@ -164,7 +164,7 @@ class Form * @param string|null $loggingBasemsg The basemsg added at the beginning of * the log */ - public function logging($loggingCallable, $loggingBasemsg = "") + public function logging($loggingCallable, $loggingBasemsg = ""): void { $this->loggingCallable = $loggingCallable; $this->loggingBasemsg = $loggingBasemsg; @@ -175,7 +175,7 @@ class Form * Can be : Bootstrap3, Bootstrap4 (later Bulma) * @param string $formTemplate The template to use */ - public function formTemplate($formTemplate) + public function formTemplate($formTemplate): self { if ( ! in_array( @@ -195,7 +195,7 @@ class Form * @param integer $prio The priority of the message * @param string $msg The message to store */ - private function loggingCallable($prio, $msg) + private function loggingCallable($prio, $msg): void { if (! is_callable($this->loggingCallable)) { return; @@ -236,7 +236,7 @@ class Form * * @param array $fields The fields to be displayed */ - public function fields($fields) + public function fields($fields): void { $this->fields = $fields; } @@ -246,7 +246,7 @@ class Form * in fields method * @param object $field The field to add */ - public function addfield($field) + public function addfield($field): void { $this->fields[] = $field; } @@ -256,7 +256,7 @@ class Form * NEVER read the values from $_POST in your codes or CSRF will not be * checked */ - public function values() + public function values(): array { $values = []; if ($this->method === "post") { @@ -328,7 +328,7 @@ class Form $method = 'post', $values = null, $errors = [] - ) { + ): string { if (count($this->fields) === 0) { $this->loggingCallable( LOG_ERR, @@ -456,7 +456,7 @@ class Form * Check the token from the user * @param string $tokenFromUser The value form the user's token */ - public function checkToken($tokenFromUser) + public function checkToken($tokenFromUser): void { $csrf = new Csrf(); $csrf->field = $this->csrfField; @@ -468,7 +468,7 @@ class Form /** * Return the token generated in form */ - public function getToken() + public function getToken(): string { if ($this->csrfToken === "") { $csrf = new Csrf(); @@ -485,7 +485,7 @@ class Form * stored one if the value is null) * @return array containing the errors */ - public function verify($values, $fields = []) + public function verify($values, $fields = []): array { if (count($fields) === 0) { if (! isset($_SESSION["domframework"]["form"]["fields"])) { @@ -529,7 +529,7 @@ class Form * $spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]); * $route->redirect ("/admin/space/"); */ - public function redirectIfError($values, $errors, $route, $url = "") + public function redirectIfError($values, $errors, $route, $url = ""): void { $this->saveValuesErrors($values, $errors); if ($url === "") { @@ -548,7 +548,7 @@ class Form * @param array $values The values of the fields filled by the user * @param array|null $errors The errors detected by a verify */ - public function saveValuesErrors($values, $errors = []) + public function saveValuesErrors($values, $errors = []): void { if (isset($_SESSION)) { $_SESSION["domframework"]["form"][$this->formName]["values"] = $values; @@ -560,7 +560,7 @@ class Form * Reset the saved values to provide a clean form next page * 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]["errors"]); @@ -572,7 +572,7 @@ class Form * @param array $values The values returned if there is no stored values * @return array The values to use */ - public function getOldValues($values) + public function getOldValues($values): array { if (isset($_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 * @return array The errors to use */ - public function getOldErrors($errors) + public function getOldErrors($errors): array { if (isset($_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 * @return string */ - public function convertDate($inputDate, $inputFormat, $outputFormat) + public function convertDate($inputDate, $inputFormat, $outputFormat): string { $date = \DateTime::CreateFromFormat($inputFormat, $inputDate); if ($date === false) { diff --git a/src/Formfield.php b/src/Formfield.php index dd540d2..f2bfafc 100644 --- a/src/Formfield.php +++ b/src/Formfield.php @@ -106,7 +106,7 @@ class Formfield /** * Display really the form */ - public function display() + public function display(): string { $func = "field" . $this->formTemplate . $this->type; return $this->$func(); @@ -117,7 +117,7 @@ class Formfield * Set 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; return $this; @@ -127,7 +127,7 @@ class Formfield * Set 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; return $this; @@ -137,7 +137,7 @@ class Formfield * Set 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; return $this; @@ -147,7 +147,7 @@ class Formfield * Set the placeholder * @param string $val The value of the placeholder */ - public function placeholder($val) + public function placeholder($val): self { $this->placeholder = $val; return $this; @@ -157,7 +157,7 @@ class Formfield * Set the multiple * @param string $val The value of the multiple */ - public function multiple($val) + public function multiple($val): self { $this->multiple = $val; return $this; @@ -167,7 +167,7 @@ class Formfield * Set the group * @param string $val The value of the group */ - public function group($val) + public function group($val): self { $this->group = $val; return $this; @@ -177,7 +177,7 @@ class Formfield * Set the readonly * @param string $val The value of the readonly */ - public function readonly($val) + public function readonly($val): self { $this->readonly = !! $val; return $this; @@ -187,7 +187,7 @@ class Formfield * Set the mandatory * @param string $val The value of the mandatory */ - public function mandatory($val) + public function mandatory($val): self { $this->mandatory = !! $val; return $this; @@ -197,7 +197,7 @@ class Formfield * Set the rows * @param string $val The value of the rows */ - public function rows($val) + public function rows($val): self { $this->rows = $val; return $this; @@ -207,7 +207,7 @@ class Formfield * Set the cols * @param string $val The value of the cols */ - public function cols($val) + public function cols($val): self { $this->cols = $val; return $this; @@ -219,7 +219,7 @@ class Formfield /** * Return the checkbox defined */ - private function fieldBootstrap3checkbox() + private function fieldBootstrap3checkbox(): string { // No $this->multiple, $this->rows $this->cols $this->placeholder, // $this->maxlength @@ -366,7 +366,7 @@ class Formfield /** * Return the hidden field defined */ - private function fieldBootstrap3hidden() + private function fieldBootstrap3hidden(): string { $res = ""; // No $this->label, $this->multiple, $this->readonly, $this->hidden, @@ -388,7 +388,7 @@ class Formfield /** * Return the password field defined */ - private function fieldBootstrap3password() + private function fieldBootstrap3password(): string { $res = ""; // No $this->multiple, $this->rows $this->cols @@ -472,7 +472,7 @@ class Formfield /** * Return the radio field defined */ - private function fieldBootstrap3radio() + private function fieldBootstrap3radio(): string { $res = ""; // No $this->multiple, $this->rows $this->cols $this->placeholder @@ -574,7 +574,7 @@ class Formfield /** * Return the checkbox defined */ - private function fieldBootstrap3select() + private function fieldBootstrap3select(): string { // No $this->placeholder $this->maxlength $res = ""; @@ -704,7 +704,7 @@ class Formfield /** * Return the submit defined */ - private function fieldBootstrap3submit() + private function fieldBootstrap3submit(): string { $res = ""; // No $this->label, $this->multiple, $this->error, $this->rows, @@ -749,7 +749,7 @@ class Formfield /** * Return the textarea defined */ - private function fieldBootstrap3textarea() + private function fieldBootstrap3textarea(): string { $res = ""; // No $this->multiple, $this->titles @@ -835,7 +835,7 @@ class Formfield /** * Return the text defined */ - private function fieldBootstrap3text() + private function fieldBootstrap3text(): string { $res = ""; // No $this->multiple, $this->titles, $this->rows, $this->cols @@ -919,7 +919,7 @@ class Formfield /** * Return the file defined */ - private function fieldBootstrap3file() + private function fieldBootstrap3file(): string { $res = ""; // No $this->multiple, $this->titles, $this->rows, $this->cols @@ -1021,7 +1021,7 @@ class Formfield /** * Return the checkbox defined */ - private function fieldBootstrap4checkbox() + private function fieldBootstrap4checkbox(): string { // No $this->multiple, $this->rows $this->cols $this->placeholder, // $this->maxlength @@ -1176,7 +1176,7 @@ class Formfield /** * Return the hidden field defined */ - private function fieldBootstrap4hidden() + private function fieldBootstrap4hidden(): string { $res = ""; // No $this->label, $this->multiple, $this->readonly, $this->hidden, @@ -1198,7 +1198,7 @@ class Formfield /** * Return the password field defined */ - private function fieldBootstrap4password() + private function fieldBootstrap4password(): string { $res = ""; // No $this->multiple, $this->rows $this->cols @@ -1290,7 +1290,7 @@ class Formfield /** * Return the radio field defined */ - private function fieldBootstrap4radio() + private function fieldBootstrap4radio(): string { $res = ""; // No $this->multiple, $this->rows $this->cols $this->placeholder @@ -1400,7 +1400,7 @@ class Formfield /** * Return the checkbox defined */ - private function fieldBootstrap4select() + private function fieldBootstrap4select(): string { // No $this->placeholder $this->maxlength $res = ""; @@ -1538,7 +1538,7 @@ class Formfield /** * Return the submit defined */ - private function fieldBootstrap4submit() + private function fieldBootstrap4submit(): string { $res = ""; // No $this->label, $this->multiple, $this->error, $this->rows, @@ -1583,7 +1583,7 @@ class Formfield /** * Return the textarea defined */ - private function fieldBootstrap4textarea() + private function fieldBootstrap4textarea(): string { $res = ""; // No $this->multiple, $this->titles @@ -1677,7 +1677,7 @@ class Formfield /** * Return the text defined */ - private function fieldBootstrap4text() + private function fieldBootstrap4text(): string { $res = ""; // No $this->multiple, $this->titles, $this->rows, $this->cols @@ -1769,7 +1769,7 @@ class Formfield /** * Return the file defined */ - private function fieldBootstrap4file() + private function fieldBootstrap4file(): string { $res = ""; // No $this->multiple, $this->titles, $this->rows, $this->cols