Skip to content
Snippets Groups Projects
Unverified Commit 573bfb70 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

feat: add strong typing to the package

parent 398bb2eb
No related branches found
No related tags found
3 merge requests!28release: 3.0.0,!23Feature/strong typing pp,!19Add strong typing for 3.0 version
Pipeline #5964 passed
Showing
with 345 additions and 335 deletions
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/
# Configuration for PhpStorm
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
tab_width = 4
ij_continuation_indent_size = 4
[*.scss]
ij_scss_enforce_quotes_on_format = true
ij_scss_hex_color_long_format = true
ij_scss_hex_color_lower_case = true
[{*.cjs,*.js}]
indent_style = space
indent_size = 2
ij_javascript_do_while_brace_force = always
ij_javascript_if_brace_force = always
ij_javascript_import_sort_module_name = true
ij_javascript_reformat_c_style_comments = true
ij_javascript_space_after_unary_not = true
ij_javascript_space_before_unary_not = true
ij_javascript_spaces_within_array_initializer_brackets = true
ij_javascript_spaces_within_brackets = true
ij_javascript_spaces_within_catch_parentheses = true
ij_javascript_spaces_within_for_parentheses = true
ij_javascript_spaces_within_if_parentheses = true
ij_javascript_spaces_within_imports = true
ij_javascript_spaces_within_interpolation_expressions = true
ij_javascript_spaces_within_method_call_parentheses = true
ij_javascript_spaces_within_method_parentheses = true
ij_javascript_spaces_within_object_literal_braces = true
ij_javascript_spaces_within_parentheses = true
ij_javascript_spaces_within_switch_parentheses = true
ij_javascript_spaces_within_while_parentheses = true
ij_javascript_while_brace_force = always
[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}]
ij_php_align_assignments = true
ij_php_align_class_constants = true
ij_php_align_key_value_pairs = true
ij_php_align_phpdoc_comments = true
ij_php_align_phpdoc_param_names = true
ij_php_class_brace_style = end_of_line
ij_php_comma_after_last_array_element = true
ij_php_else_if_style = combine
ij_php_force_short_declaration_array_style = true
ij_php_getters_setters_naming_style = snake_case
ij_php_if_brace_force = always
ij_php_lower_case_boolean_const = true
ij_php_lower_case_null_const = true
ij_php_method_brace_style = end_of_line
ij_php_phpdoc_blank_line_before_tags = true
ij_php_phpdoc_blank_lines_around_parameters = true
ij_php_phpdoc_keep_blank_lines = false
ij_php_phpdoc_wrap_long_lines = true
ij_php_space_after_type_cast = true
ij_php_space_after_unary_not = true
ij_php_space_before_unary_not = true
ij_php_spaces_around_var_within_brackets = true
ij_php_spaces_within_array_initializer_braces = true
ij_php_spaces_within_catch_parentheses = true
ij_php_spaces_within_for_parentheses = true
ij_php_spaces_within_if_parentheses = true
ij_php_spaces_within_method_call_parentheses = true
ij_php_spaces_within_method_parentheses = true
ij_php_spaces_within_parentheses = true
ij_php_spaces_within_switch_parentheses = true
ij_php_spaces_within_while_parentheses = true
ij_php_ternary_operation_signs_on_next_line = true
ij_php_variable_naming_style = snake_case
[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}]
ij_html_add_new_line_before_tags = div,p,a
ij_html_align_attributes = false
ij_html_do_not_indent_children_of_tags = html,thead,tbody,tfoot
ij_html_new_line_after_last_attribute = when multiline
ij_html_space_inside_empty_tag = true
ij_html_uniform_ident = true
WP_ROOT_FOLDER="${APACHE_DOCUMENT_ROOT}"
TEST_SITE_WP_ADMIN_PATH="/wp-admin"
TEST_SITE_DB_NAME="wptest"
TEST_SITE_DB_HOST="mysqltests"
TEST_SITE_DB_USER="mysql"
TEST_SITE_DB_PASSWORD="mysql"
TEST_SITE_TABLE_PREFIX="wp_"
TEST_DB_NAME="wptest"
TEST_DB_HOST="mysqltests"
TEST_DB_USER="mysql"
TEST_DB_PASSWORD="mysql"
TEST_TABLE_PREFIX="wp_"
TEST_SITE_WP_URL="http://${WOOTESTS_IP}"
TEST_SITE_WP_DOMAIN="${WOOTESTS_IP}"
TEST_SITE_ADMIN_EMAIL="grola@seostudio.pl"
TEST_SITE_ADMIN_USERNAME="admin"
TEST_SITE_ADMIN_PASSWORD="admin"
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
composer.lock composer.lock
build-coverage build-coverage
swagger swagger
.phpcs-cache
...@@ -24,10 +24,11 @@ ...@@ -24,10 +24,11 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "<7", "phpunit/phpunit": "<7",
"wp-coding-standards/wpcs": "^0.14.1", "phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.0.2", "wpdesk/wp-code-sniffer": "^1.2.3",
"mockery/mockery": "*", "10up/wp_mock": "*",
"10up/wp_mock": "*" "szepeviktor/phpstan-wordpress": "^0.7.7",
"phpstan/extension-installer": "^1.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for WP Desk Plugin">
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->
<!-- Scan all files. -->
<file>./src</file>
<file>./templates</file>
<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
<!-- Show progress, show the error codes for each message (source). -->
<arg value="sp"/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>
<!-- Cache outcomes for better performance. Remember to add the file to .gitignore. -->
<arg name="cache" value="./.phpcs-cache"/>
<!--
#############################################################################
USE THE WPDeskCS RULESET
#############################################################################
-->
<!-- Define plugin text domain for i18n. -->
<config name="text_domain" value="shopmagic-for-woocommerce"/>
<!-- This value should be aligned with WordPress support version declared in plugin header -->
<config name="minimum_supported_wp_version" value="5.0"/>
<!-- Set value aligned with supported PHP Version for PHPCompatibilityWP check. -->
<config name="testVersion" value="7.0-"/>
<rule ref="WPDeskPlugin"/>
<rule ref="Squiz.Commenting.ClassComment.Missing">
<exclude name="Squiz.Commenting.ClassComment.Missing"/>
</rule>
</ruleset>
parameters:
level: max
paths:
- src/
...@@ -13,11 +13,5 @@ ...@@ -13,11 +13,5 @@
</whitelist> </whitelist>
</filter> </filter>
<logging>
<log type="junit" target="build-coverage/report.junit.xml"/>
<log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build-coverage/coverage.txt"/>
<log type="coverage-clover" target="build-coverage/clover.xml"/>
</logging>
</phpunit> </phpunit>
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace WPDesk\Forms; namespace WPDesk\Forms;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use WPDesk\Persistence\PersistentContainer; use WPDesk\Persistence\PersistentContainer;
...@@ -12,18 +11,12 @@ use WPDesk\Persistence\PersistentContainer; ...@@ -12,18 +11,12 @@ use WPDesk\Persistence\PersistentContainer;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
interface ContainerForm { interface ContainerForm {
/** /** @return void */
* @param ContainerInterface $data public function set_data( ContainerInterface $data );
*
* @return void
*/
public function set_data( $data );
/** /**
* Put data from form into a container. * Put data from form into a container.
* *
* @param PersistentContainer $container Target container.
*
* @return void * @return void
*/ */
public function put_data( PersistentContainer $container ); public function put_data( PersistentContainer $container );
......
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
namespace WPDesk\Forms; namespace WPDesk\Forms;
interface Escaper { interface Escaper {
/** /** @param mixed $value */
* @param mixed $value public function escape( $value ): string;
*
* @return string
*/
public function escape( $value );
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
namespace WPDesk\Forms; namespace WPDesk\Forms;
use WPDesk\Forms\Field\BasicField;
/** /**
* The idea is that from the moment the factory returns this interface it's values cannot be changed. * The idea is that from the moment the factory returns this interface it's values cannot be changed.
* And that is why here are only the getters. * And that is why here are only the getters.
...@@ -13,157 +11,88 @@ use WPDesk\Forms\Field\BasicField; ...@@ -13,157 +11,88 @@ use WPDesk\Forms\Field\BasicField;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
interface Field { interface Field {
/** @return string */ public function get_name(): string;
public function get_name();
/** @return mixed */ /** @return mixed */
public function get_default_value(); public function get_default_value();
/** @return string */ public function get_template_name(): string;
public function get_template_name();
/** /** When this field is used on form this field will force it's own template. */
* When this field is used on form this field will force it's own template. public function should_override_form_template(): bool;
*
* return bool
*/
public function should_override_form_template();
/** /** HTML label. */
* HTML label. public function get_label(): string;
*
* @return string
*/
public function get_label();
/** bool */ public function has_label(): bool;
public function has_label();
/** public function get_description(): string;
* Description for field. It can be shown near the field.
*
* @return string
*/
public function get_description();
/** /** Additional field description that should be shown in optional hover tip. */
* Additional field description that should be shown in optional hover tip. public function get_description_tip(): string;
*
* @return string
*/
public function get_description_tip();
/** @return bool */ public function has_description_tip(): bool;
public function has_description_tip();
/** @return bool */ public function has_description(): bool;
public function has_description();
/** public function is_readonly(): bool;
* @return bool
*/
public function is_readonly();
/** @return bool */ public function is_disabled(): bool;
public function is_disabled();
/** @return string */ public function get_id(): string;
public function get_id();
/** @bool */ public function is_required(): bool;
public function is_required();
/** @return bool */ public function has_placeholder(): bool;
public function has_placeholder();
/** @return string */ public function get_placeholder(): string;
public function get_placeholder();
/** /**
* @param string[] $except * @param string[] $except
* *
* @return string[] name->value * @return string[] name->value
*/ */
public function get_attributes( $except = [] ); public function get_attributes( array $except = [] ): array;
/** /**
* @param string $name * @param string $name
* @param string $default * @param ?string $default
* *
* @return string * @return string
*/ */
public function get_attribute( $name, $default = null ); public function get_attribute( string $name, $default = null ): string;
/** @return bool */ public function is_attribute_set( string $name ): bool;
public function is_attribute_set( $name );
/** public function get_meta_value( string $name ): string;
* @param string $name
*
* @return string
*/
public function get_meta_value( $name );
/** @return bool */ public function is_meta_value_set( string $name ): bool;
public function is_meta_value_set( $name );
/** public function get_classes(): string;
* @return string
*/
public function get_classes();
/** bool */ public function has_classes(): bool;
public function has_classes();
/** @return bool */ public function is_class_set( string $name ): bool;
public function is_class_set( $name );
/** bool */ public function has_data(): bool;
public function has_data();
/** /** @return array<string,int> */
* @return array public function get_data(): array;
*/
public function get_data();
/** public function add_data( string $data_name, string $data_value ): self;
* @param string $data_name
* @param string $data_value
*
* @return $this
*/
public function add_data( $data_name, $data_value );
/** public function unset_data( string $data_name ): self;
* @param string $data_name
*
* @return $this
*/
public function unset_data( $data_name );
/** /** @return mixed */
* @return mixed
*/
public function get_possible_values(); public function get_possible_values();
/** public function is_multiple(): bool;
* @return bool
*/
public function is_multiple();
/** public function get_validator(): Validator;
* @return Validator
*/
public function get_validator();
/** public function get_sanitizer(): Sanitizer;
* @return Sanitizer
*/
public function get_sanitizer();
/** @return Serializer */ public function get_serializer(): Serializer;
public function get_serializer();
/** @return int */ public function get_priority(): int;
public function get_priority();
} }
...@@ -4,9 +4,11 @@ namespace WPDesk\Forms\Field; ...@@ -4,9 +4,11 @@ namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field; use WPDesk\Forms\Field;
use WPDesk\Forms\Form\FormWithFields; use WPDesk\Forms\Form\FormWithFields;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\NoSanitize; use WPDesk\Forms\Sanitizer\NoSanitize;
use WPDesk\Forms\Serializer; use WPDesk\Forms\Serializer;
use WPDesk\Forms\Serializer\NoSerialize; use WPDesk\Forms\Serializer\NoSerialize;
use WPDesk\Forms\Validator;
use WPDesk\Forms\Validator\ChainValidator; use WPDesk\Forms\Validator\ChainValidator;
use WPDesk\Forms\Validator\RequiredValidator; use WPDesk\Forms\Validator\RequiredValidator;
...@@ -19,209 +21,164 @@ use WPDesk\Forms\Validator\RequiredValidator; ...@@ -19,209 +21,164 @@ use WPDesk\Forms\Validator\RequiredValidator;
abstract class BasicField implements Field { abstract class BasicField implements Field {
use Field\Traits\HtmlAttributes; use Field\Traits\HtmlAttributes;
/** @var array[] */ const DEFAULT_PRIORITY = 10;
/** @var array<string,int,bool> */
protected $meta; protected $meta;
/** @var string */
protected $default_value; protected $default_value;
public function __construct() { public function __construct() {
$this->meta['class'] = []; $this->meta['class'] = [];
$this->meta['priority'] = 10; $this->meta['priority'] = self::DEFAULT_PRIORITY;
} }
public function get_label() { public function get_label(): string {
return $this->meta['label']; return $this->meta['label'];
} }
/** public function set_label( string $value ): self {
* @param string $value
*
* @return $this
*/
public function set_label( $value ) {
$this->meta['label'] = $value; $this->meta['label'] = $value;
return $this; return $this;
} }
public function get_description_tip() { public function get_description_tip(): string {
return $this->meta['description_tip']; return $this->meta['description_tip'];
} }
public function has_description_tip() { public function has_description_tip(): bool {
return isset( $this->meta['description_tip'] ); return isset( $this->meta['description_tip'] );
} }
public function should_override_form_template() { public function should_override_form_template(): bool {
return isset( $this->attributes['overrite_template'] ) ? $this->attributes['overrite_template'] : false; return $this->attributes['overrite_template'] ?? false;
} }
public function get_description() { public function get_description(): string {
return $this->meta['description']; return $this->meta['description'];
} }
public function has_label() { public function has_label(): bool {
return isset( $this->meta['label'] ); return isset( $this->meta['label'] );
} }
public function has_description() { public function has_description(): bool {
return isset( $this->meta['description'] ); return isset( $this->meta['description'] );
} }
public function set_description( $value ) { public function set_description( string $value ): self {
$this->meta['description'] = $value; $this->meta['description'] = $value;
return $this; return $this;
} }
public function set_description_tip( $value ) { public function set_description_tip( string $value ): self {
$this->meta['description_tip'] = $value; $this->meta['description_tip'] = $value;
return $this; return $this;
} }
/** public function get_type(): string {
* @return array
*
* @deprecated not sure if needed. TODO: Check later.
*/
public function get_type() {
return $this->attributes['type']; return $this->attributes['type'];
} }
/** public function set_placeholder( string $value ): self {
* @param string $value
*
* @return $this
*/
public function set_placeholder( $value ) {
$this->meta['placeholder'] = $value; $this->meta['placeholder'] = $value;
return $this; return $this;
} }
public function has_placeholder() { public function has_placeholder(): bool {
return isset( $this->meta['placeholder'] ); return isset( $this->meta['placeholder'] );
} }
public function get_placeholder() { public function get_placeholder(): string {
return $this->meta['placeholder']; return $this->meta['placeholder'];
} }
/** public function set_name( string $name ): self {
* @param string $name
*
* @return $this
*/
public function set_name( $name ) {
$this->attributes['name'] = $name; $this->attributes['name'] = $name;
return $this; return $this;
} }
public function get_meta_value( $name ) { public function get_meta_value( string $name ): string {
return $this->meta[ $name ]; return $this->meta[ $name ];
} }
public function get_classes() { public function get_classes(): string {
return implode( ' ', $this->meta['class'] ); return implode( ' ', $this->meta['class'] );
} }
public function has_classes() { public function has_classes(): bool {
return ! empty( $this->meta['class'] ); return ! empty( $this->meta['class'] );
} }
public function has_data() { public function has_data(): bool {
return ! empty( $this->meta['data'] ); return ! empty( $this->meta['data'] );
} }
/** public function get_data(): array {
* @return array return $this->meta['data'] ?: [];
*/
public function get_data() {
return empty( $this->meta['data'] ) ? [] : $this->meta['data'];
} }
public function get_possible_values() { public function get_possible_values() {
return isset( $this->meta['possible_values'] ) ? $this->meta['possible_values'] : []; return isset( $this->meta['possible_values'] ) ? $this->meta['possible_values'] : [];
} }
public function get_id() { public function get_id(): string {
return isset( $this->attributes['id'] ) ? $this->attributes['id'] : sanitize_title( $this->get_name() ); return $this->attributes['id'] ?? sanitize_title( $this->get_name() );
} }
public function get_name() { public function get_name(): string {
return $this->attributes['name']; return $this->attributes['name'];
} }
public function is_multiple() { public function is_multiple(): bool {
return isset( $this->attributes['multiple'] ) ? $this->attributes['multiple'] : false; return $this->attributes['multiple'] ?? false;
} }
/** public function set_disabled(): self {
* @return $this
*/
public function set_disabled() {
$this->attributes['disabled'] = true; $this->attributes['disabled'] = true;
return $this; return $this;
} }
public function is_disabled() { public function is_disabled(): bool {
return isset( $this->attributes['disabled'] ) ? $this->attributes['disabled'] : false; return $this->attributes['disabled'] ?? false;
} }
/** public function set_readonly(): self {
* @return $this
*/
public function set_readonly() {
$this->attributes['readonly'] = true; $this->attributes['readonly'] = true;
return $this; return $this;
} }
public function is_readonly() { public function is_readonly(): bool {
return isset( $this->attributes['readonly'] ) ? $this->attributes['readonly'] : false; return $this->attributes['readonly'] ?? false;
} }
/** public function set_required(): self {
* @return $this
*/
public function set_required() {
$this->meta['required'] = true; $this->meta['required'] = true;
return $this; return $this;
} }
/** public function add_class( string $class_name ): self {
* @param string $class_name
*
* @return $this
*/
public function add_class( $class_name ) {
$this->meta['class'][ $class_name ] = $class_name; $this->meta['class'][ $class_name ] = $class_name;
return $this; return $this;
} }
/** public function unset_class( string $class_name ): self {
* @param string $class_name
*
* @return $this
*/
public function unset_class( $class_name ) {
unset( $this->meta['class'][ $class_name ] ); unset( $this->meta['class'][ $class_name ] );
return $this; return $this;
} }
/** public function add_data( string $data_name, string $data_value ): self {
* @param string $data_name
* @param string $data_value
*
* @return $this
*/
public function add_data( $data_name, $data_value ) {
if ( ! isset( $this->meta['data'] ) ) { if ( ! isset( $this->meta['data'] ) ) {
$this->meta['data'] = []; $this->meta['data'] = [];
} }
...@@ -230,44 +187,31 @@ abstract class BasicField implements Field { ...@@ -230,44 +187,31 @@ abstract class BasicField implements Field {
return $this; return $this;
} }
/** public function unset_data( string $data_name ): self {
* @param string $data_name
*
* @return $this
*/
public function unset_data( $data_name ) {
unset( $this->meta['data'][ $data_name ] ); unset( $this->meta['data'][ $data_name ] );
return $this; return $this;
} }
public function is_meta_value_set( $name ) { public function is_meta_value_set( string $name ): bool {
return isset( $this->meta[ $name ] ); return isset( $this->meta[ $name ] );
} }
public function is_class_set( $name ) { public function is_class_set( string $name ): bool {
return isset( $this->meta['class'][ $name ] ); return isset( $this->meta['class'][ $name ] );
} }
public function get_default_value() { public function get_default_value(): string {
return $this->default_value; return $this->default_value;
} }
/** public function set_default_value( string $value ): self {
* @param string $value
*
* @return $this
*/
public function set_default_value( $value ) {
$this->default_value = $value; $this->default_value = $value;
return $this; return $this;
} }
/** public function get_validator(): Validator {
* @return ChainValidator
*/
public function get_validator() {
$chain = new ChainValidator(); $chain = new ChainValidator();
if ( $this->is_required() ) { if ( $this->is_required() ) {
$chain->attach( new RequiredValidator() ); $chain->attach( new RequiredValidator() );
...@@ -276,18 +220,15 @@ abstract class BasicField implements Field { ...@@ -276,18 +220,15 @@ abstract class BasicField implements Field {
return $chain; return $chain;
} }
public function is_required() { public function is_required(): bool {
return isset( $this->meta['required'] ) ? $this->meta['required'] : false; return $this->meta['required'] ?? false;
} }
public function get_sanitizer() { public function get_sanitizer(): Sanitizer {
return new NoSanitize(); return new NoSanitize();
} }
/** public function get_serializer(): Serializer {
* @return Serializer
*/
public function get_serializer() {
if ( isset( $this->meta['serializer'] ) && $this->meta['serializer'] instanceof Serializer ) { if ( isset( $this->meta['serializer'] ) && $this->meta['serializer'] instanceof Serializer ) {
return $this->meta['serializer']; return $this->meta['serializer'];
} }
...@@ -295,7 +236,7 @@ abstract class BasicField implements Field { ...@@ -295,7 +236,7 @@ abstract class BasicField implements Field {
return new NoSerialize(); return new NoSerialize();
} }
public function set_serializer( Serializer $serializer ) { public function set_serializer( Serializer $serializer ): self {
$this->meta['serializer'] = $serializer; $this->meta['serializer'] = $serializer;
return $this; return $this;
......
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class ButtonField extends NoValueField class ButtonField extends NoValueField {
{
public function get_template_name() public function get_template_name(): string {
{
return 'button'; return 'button';
} }
public function get_type() public function get_type(): string {
{
return 'button'; return 'button';
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class CheckboxField extends BasicField { class CheckboxField extends BasicField {
const VALUE_TRUE = 'yes'; const VALUE_TRUE = 'yes';
const VALUE_FALSE = 'no'; const VALUE_FALSE = 'no';
...@@ -12,21 +11,21 @@ class CheckboxField extends BasicField { ...@@ -12,21 +11,21 @@ class CheckboxField extends BasicField {
$this->set_attribute( 'type', 'checkbox' ); $this->set_attribute( 'type', 'checkbox' );
} }
public function get_template_name() { public function get_template_name(): string {
return 'input-checkbox'; return 'input-checkbox';
} }
public function get_sublabel() { public function get_sublabel(): string {
return $this->meta['sublabel']; return $this->meta['sublabel'];
} }
public function set_sublabel( $value ) { public function set_sublabel( string $value ): self {
$this->meta['sublabel'] = $value; $this->meta['sublabel'] = $value;
return $this; return $this;
} }
public function has_sublabel() { public function has_sublabel(): bool {
return isset( $this->meta['sublabel'] ); return isset( $this->meta['sublabel'] );
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class DatePickerField extends BasicField { class DatePickerField extends BasicField {
...@@ -13,11 +14,11 @@ class DatePickerField extends BasicField { ...@@ -13,11 +14,11 @@ class DatePickerField extends BasicField {
$this->set_attribute( 'type', 'text' ); $this->set_attribute( 'type', 'text' );
} }
public function get_sanitizer() { public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer(); return new TextFieldSanitizer();
} }
public function get_template_name() { public function get_template_name(): string {
return 'input-date-picker'; return 'input-date-picker';
} }
} }
...@@ -8,15 +8,15 @@ class Header extends NoValueField { ...@@ -8,15 +8,15 @@ class Header extends NoValueField {
$this->meta['header_size'] = ''; $this->meta['header_size'] = '';
} }
public function get_template_name() { public function get_template_name(): string {
return 'header'; return 'header';
} }
public function should_override_form_template() { public function should_override_form_template(): bool {
return true; return true;
} }
public function set_header_size( $value ) { public function set_header_size( int $value ): self {
$this->meta['header_size'] = $value; $this->meta['header_size'] = $value;
return $this; return $this;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class HiddenField extends BasicField { class HiddenField extends BasicField {
...@@ -11,11 +12,11 @@ class HiddenField extends BasicField { ...@@ -11,11 +12,11 @@ class HiddenField extends BasicField {
$this->set_attribute( 'type', 'hidden' ); $this->set_attribute( 'type', 'hidden' );
} }
public function get_sanitizer() { public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer(); return new TextFieldSanitizer();
} }
public function get_template_name() { public function get_template_name(): string {
return 'input-hidden'; return 'input-hidden';
} }
} }
...@@ -10,10 +10,7 @@ class ImageInputField extends BasicField { ...@@ -10,10 +10,7 @@ class ImageInputField extends BasicField {
$this->set_attribute( 'type', 'text' ); $this->set_attribute( 'type', 'text' );
} }
/** public function get_template_name(): string {
* @return string
*/
public function get_template_name() {
return 'input-image'; return 'input-image';
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputNumberField extends BasicField { class InputNumberField extends BasicField {
...@@ -11,11 +12,11 @@ class InputNumberField extends BasicField { ...@@ -11,11 +12,11 @@ class InputNumberField extends BasicField {
$this->set_attribute( 'type', 'number' ); $this->set_attribute( 'type', 'number' );
} }
public function get_sanitizer() { public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer(); return new TextFieldSanitizer();
} }
public function get_template_name() { public function get_template_name(): string {
return 'input-number'; return 'input-number';
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputTextField extends BasicField { class InputTextField extends BasicField {
...@@ -11,11 +12,11 @@ class InputTextField extends BasicField { ...@@ -11,11 +12,11 @@ class InputTextField extends BasicField {
$this->set_attribute( 'type', 'text' ); $this->set_attribute( 'type', 'text' );
} }
public function get_sanitizer() { public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer(); return new TextFieldSanitizer();
} }
public function get_template_name() { public function get_template_name(): string {
return 'input-text'; return 'input-text';
} }
} }
...@@ -4,10 +4,7 @@ namespace WPDesk\Forms\Field; ...@@ -4,10 +4,7 @@ namespace WPDesk\Forms\Field;
class MultipleInputTextField extends InputTextField { class MultipleInputTextField extends InputTextField {
/** public function get_template_name(): string {
* @return string
*/
public function get_template_name() {
return 'input-text-multiple'; return 'input-text-multiple';
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment