Skip to content

Commit

Permalink
Remove static return type as it is only supported in PHP 8+.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Jul 25, 2024
1 parent 27c3a06 commit b1b07ef
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Validation/Abstract_Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct( array $initial_rules = array() ) {
*
* @throws InvalidArgumentException Thrown when a forbidden rule is passed.
*/
final public function with_rule( Validation_Rule $rule ): static {
final public function with_rule( Validation_Rule $rule ): Validation_Rule_Builder {
if ( ! $this->is_allowed_rule( $rule ) ) {
throw new InvalidArgumentException(
sprintf(
Expand Down
7 changes: 4 additions & 3 deletions src/Validation/Array_Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Types;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule_Builder;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\With_Type_Support;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Array_Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Item_Count_Range_Validation_Rule;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function __construct( array $initial_rules = array(), bool $strict = fals
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function with_items( Validation_Rule $item_validation_rule ): static {
public function with_items( Validation_Rule $item_validation_rule ): Validation_Rule_Builder {
return $this->with_rule( new Items_Validation_Rule( $item_validation_rule ) );
}

Expand All @@ -62,7 +63,7 @@ public function with_items( Validation_Rule $item_validation_rule ): static {
* @param int $max_count Optional. Maximum count allowed. Default 0 (no limit).
* @return static Builder instance for chaining.
*/
public function with_item_count_range( int $min_count = 0, int $max_count = 0 ): static {
public function with_item_count_range( int $min_count = 0, int $max_count = 0 ): Validation_Rule_Builder {
return $this->with_rule( new Item_Count_Range_Validation_Rule( $min_count, $max_count ) );
}

Expand All @@ -73,7 +74,7 @@ public function with_item_count_range( int $min_count = 0, int $max_count = 0 ):
*
* @return static Builder instance for chaining.
*/
public function with_unique_items(): static {
public function with_unique_items(): Validation_Rule_Builder {
return $this->with_rule( new Unique_Items_Validation_Rule() );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Contracts/Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Validation_Rule_Builder {
*
* @throws InvalidArgumentException Thrown when a forbidden rule is passed.
*/
public function with_rule( Validation_Rule $rule ): static;
public function with_rule( Validation_Rule $rule ): Validation_Rule_Builder;

/**
* Gets the combined validation rule consisting of all rules present in the builder.
Expand Down
9 changes: 5 additions & 4 deletions src/Validation/Float_Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Types;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule_Builder;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\With_Type_Support;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Datetime_Range_Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Enum_Validation_Rule;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct( array $initial_rules = array(), bool $strict = fals
* @param string $regexp Regular expression to match.
* @return static Builder instance for chaining.
*/
public function format_regexp( string $regexp ): static {
public function format_regexp( string $regexp ): Validation_Rule_Builder {
return $this->with_rule( new Regexp_Validation_Rule( $regexp ) );
}

Expand All @@ -61,7 +62,7 @@ public function format_regexp( string $regexp ): static {
* @param string $max_datetime Optional. Maximum date-time or date allowed. Default no limit.
* @return static Builder instance for chaining.
*/
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): static {
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): Validation_Rule_Builder {
return $this->with_rule( new Datetime_Range_Validation_Rule( $min_datetime, $max_datetime ) );
}

Expand All @@ -74,7 +75,7 @@ public function with_datetime_range( string $min_datetime, string $max_datetime
* @param int|float $max Optional. Maximum value allowed. Default no limit.
* @return static Builder instance for chaining.
*/
public function with_numeric_range( $min, $max = null ): static {
public function with_numeric_range( $min, $max = null ): Validation_Rule_Builder {
return $this->with_rule( new Numeric_Range_Validation_Rule( $min, $max ) );
}

Expand All @@ -89,7 +90,7 @@ public function with_numeric_range( $min, $max = null ): static {
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function with_enum( array $allowed_values, bool $strict = false ): static {
public function with_enum( array $allowed_values, bool $strict = false ): Validation_Rule_Builder {
return $this->with_rule( new Enum_Validation_Rule( $allowed_values, $strict ) );
}

Expand Down
9 changes: 5 additions & 4 deletions src/Validation/Integer_Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Types;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule_Builder;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\With_Type_Support;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Datetime_Range_Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Enum_Validation_Rule;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct( array $initial_rules = array(), bool $strict = fals
* @param string $regexp Regular expression to match.
* @return static Builder instance for chaining.
*/
public function format_regexp( string $regexp ): static {
public function format_regexp( string $regexp ): Validation_Rule_Builder {
return $this->with_rule( new Regexp_Validation_Rule( $regexp ) );
}

Expand All @@ -61,7 +62,7 @@ public function format_regexp( string $regexp ): static {
* @param string $max_datetime Optional. Maximum date-time or date allowed. Default no limit.
* @return static Builder instance for chaining.
*/
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): static {
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): Validation_Rule_Builder {
return $this->with_rule( new Datetime_Range_Validation_Rule( $min_datetime, $max_datetime ) );
}

Expand All @@ -74,7 +75,7 @@ public function with_datetime_range( string $min_datetime, string $max_datetime
* @param int|float $max Optional. Maximum value allowed. Default no limit.
* @return static Builder instance for chaining.
*/
public function with_numeric_range( $min, $max = null ): static {
public function with_numeric_range( $min, $max = null ): Validation_Rule_Builder {
return $this->with_rule( new Numeric_Range_Validation_Rule( $min, $max ) );
}

Expand All @@ -89,7 +90,7 @@ public function with_numeric_range( $min, $max = null ): static {
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function with_enum( array $allowed_values, bool $strict = false ): static {
public function with_enum( array $allowed_values, bool $strict = false ): Validation_Rule_Builder {
return $this->with_rule( new Enum_Validation_Rule( $allowed_values, $strict ) );
}

Expand Down
19 changes: 10 additions & 9 deletions src/Validation/String_Validation_Rule_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Types;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\Validation_Rule_Builder;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Contracts\With_Type_Support;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Date_Validation_Rule;
use Felix_Arntz\WP_OOP_Plugin_Lib\Validation\Rules\Datetime_Range_Validation_Rule;
Expand Down Expand Up @@ -52,7 +53,7 @@ public function __construct( array $initial_rules = array(), bool $strict = fals
*
* @return static Builder instance for chaining.
*/
public function format_date(): static {
public function format_date(): Validation_Rule_Builder {
return $this->with_rule( new Date_Validation_Rule() );
}

Expand All @@ -63,7 +64,7 @@ public function format_date(): static {
*
* @return static Builder instance for chaining.
*/
public function format_datetime(): static {
public function format_datetime(): Validation_Rule_Builder {
return $this->with_rule( new Datetime_Validation_Rule() );
}

Expand All @@ -74,7 +75,7 @@ public function format_datetime(): static {
*
* @return static Builder instance for chaining.
*/
public function format_email(): static {
public function format_email(): Validation_Rule_Builder {
return $this->with_rule( new Email_Validation_Rule() );
}

Expand All @@ -85,7 +86,7 @@ public function format_email(): static {
*
* @return static Builder instance for chaining.
*/
public function format_version(): static {
public function format_version(): Validation_Rule_Builder {
return $this->with_rule( new Version_Validation_Rule() );
}

Expand All @@ -96,7 +97,7 @@ public function format_version(): static {
*
* @return static Builder instance for chaining.
*/
public function format_hex_color(): static {
public function format_hex_color(): Validation_Rule_Builder {
return $this->with_rule( new Hex_Color_Validation_Rule() );
}

Expand All @@ -108,7 +109,7 @@ public function format_hex_color(): static {
* @param string $regexp Regular expression to match.
* @return static Builder instance for chaining.
*/
public function format_regexp( string $regexp ): static {
public function format_regexp( string $regexp ): Validation_Rule_Builder {
return $this->with_rule( new Regexp_Validation_Rule( $regexp ) );
}

Expand All @@ -119,7 +120,7 @@ public function format_regexp( string $regexp ): static {
*
* @return static Builder instance for chaining.
*/
public function format_url(): static {
public function format_url(): Validation_Rule_Builder {
return $this->with_rule( new URL_Validation_Rule() );
}

Expand All @@ -132,7 +133,7 @@ public function format_url(): static {
* @param string $max_datetime Optional. Maximum date-time or date allowed. Default no limit.
* @return static Builder instance for chaining.
*/
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): static {
public function with_datetime_range( string $min_datetime, string $max_datetime = null ): Validation_Rule_Builder {
return $this->with_rule( new Datetime_Range_Validation_Rule( $min_datetime, $max_datetime ) );
}

Expand All @@ -147,7 +148,7 @@ public function with_datetime_range( string $min_datetime, string $max_datetime
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function with_enum( array $allowed_values, bool $strict = false ): static {
public function with_enum( array $allowed_values, bool $strict = false ): Validation_Rule_Builder {
return $this->with_rule( new Enum_Validation_Rule( $allowed_values, $strict ) );
}

Expand Down

0 comments on commit b1b07ef

Please sign in to comment.