Skip to content

Commit

Permalink
Fix PHPstan and get in line with new usage of add_option
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Sep 6, 2024
1 parent 9a420c1 commit 14fa0e6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 46 deletions.
109 changes: 67 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ parameters:
excludePaths:
- vendor
- tests
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- identifier: missingType.generics
11 changes: 8 additions & 3 deletions src/class-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function update_option_autoload( $request ) {
$option_name = $request['option_name'];
$autoload = $request['autoload'];
$option_value = get_option( $option_name );

Check failure on line 171 in src/class-rest.php

View workflow job for this annotation

GitHub Actions / Check code style

Whitespace found at end of line
if ( ! in_array( $autoload, [ 'yes', 'on', 'no', 'off','auto', 'auto-on', 'auto-off' ], true ) ) {
return new \WP_Error( 'invalid_autoload_value', 'Invalid autoload value', [ 'status' => 400 ] );
}
Expand All @@ -178,7 +178,12 @@ public function update_option_autoload( $request ) {
}

delete_option( $option_name );
$succeeded = add_option( $option_name, $option_value, '', $autoload );
$autoload_values = \wp_autoload_values_to_autoload();
$bool_autoload = false;
if ( in_array( $autoload, $autoload_values, true ) ) {
$bool_autoload = true;
}
$succeeded = add_option( $option_name, $option_value, '', $bool_autoload );

if ( ! $succeeded ) {
return new \WP_Error( 'update_failed', 'Updating the option failed', [ 'status' => 400 ] );
Expand Down Expand Up @@ -210,7 +215,7 @@ public function delete_option( $request ) {
*/
public function create_option_false( $request ) {
$option_name = $request['option_name'];
if ( add_option( $option_name, false, '', 'no' ) ) {
if ( add_option( $option_name, false, '', false ) ) {
return new \WP_REST_Response( [ 'success' => true ], 200 );
}
return new \WP_Error( 'option_not_created', 'Option could not be created', [ 'status' => 400 ] );
Expand Down

0 comments on commit 14fa0e6

Please sign in to comment.