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

fix: correct returning self signature

parent eb83afaa
No related branches found
No related tags found
2 merge requests!28release: 3.0.0,!19Add strong typing for 3.0 version
......@@ -73,9 +73,9 @@ interface Field {
/** @return array<string,int> */
public function get_data(): array;
public function add_data( string $data_name, string $data_value ): self;
public function add_data( string $data_name, string $data_value ): Field;
public function unset_data( string $data_name ): self;
public function unset_data( string $data_name ): Field;
/** @return mixed */
public function get_possible_values();
......
......@@ -3,7 +3,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
use WPDesk\Forms\Form\FormWithFields;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\NoSanitize;
use WPDesk\Forms\Serializer;
......@@ -38,7 +37,7 @@ abstract class BasicField implements Field {
return $this->meta['label'];
}
public function set_label( string $value ): self {
public function set_label( string $value ): Field {
$this->meta['label'] = $value;
return $this;
......@@ -68,13 +67,13 @@ abstract class BasicField implements Field {
return isset( $this->meta['description'] );
}
public function set_description( string $value ): self {
public function set_description( string $value ): Field {
$this->meta['description'] = $value;
return $this;
}
public function set_description_tip( string $value ): self {
public function set_description_tip( string $value ): Field {
$this->meta['description_tip'] = $value;
return $this;
......@@ -84,7 +83,7 @@ abstract class BasicField implements Field {
return $this->attributes['type'];
}
public function set_placeholder( string $value ): self {
public function set_placeholder( string $value ): Field {
$this->meta['placeholder'] = $value;
return $this;
......@@ -98,7 +97,7 @@ abstract class BasicField implements Field {
return $this->meta['placeholder'];
}
public function set_name( string $name ): self {
public function set_name( string $name ): Field {
$this->attributes['name'] = $name;
return $this;
......@@ -140,7 +139,7 @@ abstract class BasicField implements Field {
return $this->attributes['multiple'] ?? false;
}
public function set_disabled(): self {
public function set_disabled(): Field {
$this->attributes['disabled'] = true;
return $this;
......@@ -150,7 +149,7 @@ abstract class BasicField implements Field {
return $this->attributes['disabled'] ?? false;
}
public function set_readonly(): self {
public function set_readonly(): Field {
$this->attributes['readonly'] = true;
return $this;
......@@ -160,25 +159,25 @@ abstract class BasicField implements Field {
return $this->attributes['readonly'] ?? false;
}
public function set_required(): self {
public function set_required(): Field {
$this->meta['required'] = true;
return $this;
}
public function add_class( string $class_name ): self {
public function add_class( string $class_name ): Field {
$this->meta['class'][ $class_name ] = $class_name;
return $this;
}
public function unset_class( string $class_name ): self {
public function unset_class( string $class_name ): Field {
unset( $this->meta['class'][ $class_name ] );
return $this;
}
public function add_data( string $data_name, string $data_value ): self {
public function add_data( string $data_name, string $data_value ): Field {
if ( ! isset( $this->meta['data'] ) ) {
$this->meta['data'] = [];
}
......@@ -187,7 +186,7 @@ abstract class BasicField implements Field {
return $this;
}
public function unset_data( string $data_name ): self {
public function unset_data( string $data_name ): Field {
unset( $this->meta['data'][ $data_name ] );
return $this;
......@@ -205,7 +204,7 @@ abstract class BasicField implements Field {
return $this->default_value;
}
public function set_default_value( string $value ): self {
public function set_default_value( string $value ): Field {
$this->default_value = $value;
return $this;
......@@ -236,7 +235,7 @@ abstract class BasicField implements Field {
return new NoSerialize();
}
public function set_serializer( Serializer $serializer ): self {
public function set_serializer( Serializer $serializer ): Field {
$this->meta['serializer'] = $serializer;
return $this;
......@@ -251,7 +250,7 @@ abstract class BasicField implements Field {
*
* @see FormWithFields::get_fields()
*/
public function set_priority( int $priority ): self {
public function set_priority( int $priority ): Field {
$this->meta['priority'] = $priority;
return $this;
......
......@@ -2,6 +2,8 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
class CheckboxField extends BasicField {
const VALUE_TRUE = 'yes';
const VALUE_FALSE = 'no';
......@@ -19,7 +21,7 @@ class CheckboxField extends BasicField {
return $this->meta['sublabel'];
}
public function set_sublabel( string $value ): self {
public function set_sublabel( string $value ): Field {
$this->meta['sublabel'] = $value;
return $this;
......
......@@ -2,6 +2,8 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
class Header extends NoValueField {
public function __construct() {
parent::__construct();
......@@ -16,7 +18,7 @@ class Header extends NoValueField {
return true;
}
public function set_header_size( int $value ): self {
public function set_header_size( int $value ): Field {
$this->meta['header_size'] = $value;
return $this;
......
......@@ -2,6 +2,8 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
class SelectField extends BasicField {
public function get_template_name(): string {
......@@ -9,13 +11,13 @@ class SelectField extends BasicField {
}
/** @param string[] $options */
public function set_options( array $options ): self {
public function set_options( array $options ): Field {
$this->meta['possible_values'] = $options;
return $this;
}
public function set_multiple(): self {
public function set_multiple(): Field {
$this->attributes['multiple'] = true;
return $this;
......
......@@ -2,6 +2,8 @@
namespace WPDesk\Forms\Field\Traits;
use WPDesk\Forms\Field;
/**
* Implementation of HTML attributes like id, name, action etc.
*
......@@ -29,13 +31,19 @@ trait HtmlAttributes {
);
}
public function set_attribute( string $name, string $value ): self {
/**
* @return \WPDesk\Forms\Field|\WPDesk\Forms\Form
*/
public function set_attribute( string $name, string $value ) {
$this->attributes[ $name ] = $value;
return $this;
}
public function unset_attribute( string $name ): self {
/**
* @return \WPDesk\Forms\Field|\WPDesk\Forms\Form
*/
public function unset_attribute( string $name ) {
unset( $this->attributes[ $name ] );
return $this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment