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

refactor: add consistency in typing and inline docs

parent d9cb7e31
No related branches found
No related tags found
2 merge requests!28release: 3.0.0,!19Add strong typing for 3.0 version
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
use WPDesk\Forms\Form\FormWithFields;
use WPDesk\Forms\Sanitizer\NoSanitize;
use WPDesk\Forms\Serializer;
use WPDesk\Forms\Serializer\NoSerialize;
......@@ -25,6 +26,7 @@ abstract class BasicField implements Field {
public function __construct() {
$this->meta['class'] = [];
$this->meta['priority'] = 10;
}
public function get_label() {
......@@ -299,12 +301,16 @@ abstract class BasicField implements Field {
return $this;
}
/** @return int */
public function get_priority() {
return $this->meta['priority'] ?? 10;
public function get_priority(): int {
return $this->meta['priority'];
}
public function set_priority( int $priority ) {
/**
* Fields are sorted by lowest priority value first, when getting FormWithFields
*
* @see FormWithFields::get_fields()
*/
public function set_priority( int $priority ): self {
$this->meta['priority'] = $priority;
return $this;
......
......@@ -21,10 +21,13 @@ class FormWithFieldsTest extends TestCase {
$this->form->add_fields(
[
( new InputTextField() )
->set_label('third'),
->set_label('fourth'),
( new SelectField() )
->set_label('second')
->set_priority(5),
( new SelectField() )
->set_label('third')
->set_priority(7),
( new InputNumberField() )
->set_label('first')
->set_priority(1)
......@@ -38,8 +41,11 @@ class FormWithFieldsTest extends TestCase {
( new SelectField() )
->set_label('second')
->set_priority(5),
( new InputTextField() )
( new SelectField() )
->set_label('third')
->set_priority(7),
( new InputTextField() )
->set_label('fourth')
];
self::assertEquals($expected, $this->form->get_fields());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment