From 2dda30becdb7f00ea61d159354a7b94ffbf99eb0 Mon Sep 17 00:00:00 2001 From: Bart Jaskulski <bartek.jaskulski@wpdesk.net> Date: Wed, 8 Sep 2021 13:45:03 +0200 Subject: [PATCH] fix: correct type issues --- src/ContainerForm.php | 9 ++++++--- src/Field/BasicField.php | 6 ++++-- src/Field/Traits/HtmlAttributes.php | 4 +--- src/Form.php | 4 ++-- src/Form/FormWithFields.php | 6 ++++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ContainerForm.php b/src/ContainerForm.php index 0510706..1d4cf05 100644 --- a/src/ContainerForm.php +++ b/src/ContainerForm.php @@ -2,7 +2,6 @@ namespace WPDesk\Forms; -use Psr\Container\ContainerInterface; use WPDesk\Persistence\PersistentContainer; /** @@ -11,8 +10,12 @@ use WPDesk\Persistence\PersistentContainer; * @package WPDesk\Forms */ interface ContainerForm { - /** @return void */ - public function set_data( ContainerInterface $data ); + /** + * @param \Psr\Container\ContainerInterface $data + * + * @return void + */ + public function set_data( $data ); /** * Put data from form into a container. diff --git a/src/Field/BasicField.php b/src/Field/BasicField.php index 842241e..69e460d 100644 --- a/src/Field/BasicField.php +++ b/src/Field/BasicField.php @@ -200,11 +200,13 @@ abstract class BasicField implements Field { return isset( $this->meta['class'][ $name ] ); } - public function get_default_value(): string { + /** @return mixed */ + public function get_default_value() { return $this->default_value; } - public function set_default_value( string $value ): Field { + /** @param mixed $value */ + public function set_default_value( $value ): Field { $this->default_value = $value; return $this; diff --git a/src/Field/Traits/HtmlAttributes.php b/src/Field/Traits/HtmlAttributes.php index afc1e08..5ae190a 100644 --- a/src/Field/Traits/HtmlAttributes.php +++ b/src/Field/Traits/HtmlAttributes.php @@ -2,8 +2,6 @@ namespace WPDesk\Forms\Field\Traits; -use WPDesk\Forms\Field; - /** * Implementation of HTML attributes like id, name, action etc. * @@ -54,6 +52,6 @@ trait HtmlAttributes { } public function get_attribute( string $name, string $default = null ): string { - return $this->attributes[ $name ] ?? $default; + return $this->attributes[ $name ] ?? $default ?? ''; } } diff --git a/src/Form.php b/src/Form.php index 8ea2d78..504ebbe 100644 --- a/src/Form.php +++ b/src/Form.php @@ -42,7 +42,7 @@ interface Form { * * @return void */ - public function set_data( array $data ); + public function set_data( $data ); /** * Use to render the form to string. @@ -69,6 +69,6 @@ interface Form { /** * Form if you ever need to have more than one form at once. */ - public function get_form_id(): int; + public function get_form_id(): string; } diff --git a/src/Form/FormWithFields.php b/src/Form/FormWithFields.php index 45dc515..ba13928 100644 --- a/src/Form/FormWithFields.php +++ b/src/Form/FormWithFields.php @@ -113,7 +113,9 @@ class FormWithFields implements Form, ContainerForm, FieldProvider { /** * Data could be saved in some place. Use this method to transmit them to form. * - * @param array|ContainerInterface $data Data consistent with Form and ContainerForm interface. + * @param array|ContainerInterface $data Data consistent with Form or ContainerForm interface. + * + * @return void */ public function set_data( $data ) { if ( is_array( $data ) ) { @@ -208,7 +210,7 @@ class FormWithFields implements Form, ContainerForm, FieldProvider { return $fields; } - public function get_form_id(): int { + public function get_form_id(): string { return $this->form_id; } -- GitLab