Form/Formfield : Add the return types for the methods
This commit is contained in:
46
src/Form.php
46
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) {
|
||||
|
||||
Reference in New Issue
Block a user