Skip to content

Commit

Permalink
Phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark committed Aug 18, 2024
1 parent f76a670 commit 013ea67
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 53 deletions.
71 changes: 30 additions & 41 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1749,12 +1749,8 @@ public function save_pod( $params, $sanitized = false, $db = true ) {
$pod = null;
}

if ( $fail_on_load ) {
if ( is_wp_error( $pod ) ) {
return $pod;
} elseif ( empty( $pod ) ) {
return pods_error( __( 'Pod not found', 'pods' ), $this );
}
if ( $fail_on_load && ! $pod instanceof Pod ) {
return pods_error( __( 'Pod not found', 'pods' ), $this );
}
}
}
Expand Down Expand Up @@ -3285,7 +3281,7 @@ public function save_field( $params, $table_operation = true, $sanitized = false
if ( $load_params ) {
$field_obj = $this->load_field( $load_params );

if ( $fail_on_load && ( empty( $field_obj ) || is_wp_error( $field_obj ) ) ) {
if ( $fail_on_load && ! $field_obj instanceof Field ) {
return $field_obj;
}
}
Expand Down Expand Up @@ -4830,11 +4826,12 @@ public function save_pod_item( $params ) {
*
* Use for globally setting field change tracking.
*
* @param bool
* @param bool $track_changed_fields Whether to track changed fields or not.
* @param object $params The parameters passed to save_pod_item.
*
* @since 2.3.19
*/
$track_changed_fields = apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (boolean) $params->track_changed_fields, $params );
$track_changed_fields = (bool) apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (bool) $params->track_changed_fields, $params );

$changed_fields = array();

Expand Down Expand Up @@ -5083,10 +5080,10 @@ public function save_pod_item( $params ) {
*
* @since 3.0
*
* @param bool $is_visible Whether the field is visible from conditional logic.
* @param Field $field The field object.
* @param array $field_values The field values referenced.
* @param object $params The save_pod_item parameters.
* @param bool $is_visible Whether the field is visible from conditional logic.
* @param Field|Value_Field $field The field object.
* @param array $field_values The field values referenced.
* @param object $params The save_pod_item parameters.
*/
$is_visible = (bool) apply_filters(
'pods_api_save_pod_item_conditional_logic_field_is_visible',
Expand Down Expand Up @@ -6192,17 +6189,17 @@ public static function handle_changed_fields( $pod, $id, $mode = 'set' ) {
return [];
}

$changed_pods_cache = pods_static_cache_get( 'changed_pods_cache', __CLASS__ ) ?: [];
$old_fields_cache = pods_static_cache_get( 'old_fields_cache', __CLASS__ ) ?: [];
$changed_fields_cache = pods_static_cache_get( 'changed_fields_cache', __CLASS__ ) ?: [];
$changed_pods_cache = (array) ( pods_static_cache_get( 'changed_pods_cache', __CLASS__ ) ?: [] );
$old_fields_cache = (array) ( pods_static_cache_get( 'old_fields_cache', __CLASS__ ) ?: [] );
$changed_fields_cache = (array) ( pods_static_cache_get( 'changed_fields_cache', __CLASS__ ) ?: [] );

$cache_key = $pod . '|' . $id;

$export_params = array(
'depth' => 1,
);

if ( in_array( $mode, array( 'set', 'reset' ), true ) ) {
if ( in_array( $mode, [ 'set', 'reset' ], true ) ) {
if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
unset( $changed_fields_cache[ $cache_key ] );
}
Expand Down Expand Up @@ -9785,7 +9782,7 @@ public function lookup_related_items( $field_id, $pod_id, $ids, $field = null, $

$related = get_comments( $comment_args );

if ( ! is_wp_error( $related ) ) {
if ( $related ) {
$related_ids = $related;
}
} elseif (
Expand Down Expand Up @@ -10456,13 +10453,13 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null
/**
* Allow filtering the table information for an object.
*
* @param array $info The table information.
* @param string $object_type The object type.
* @param string $object The object name.
* @param string $name The pod name.
* @param array|Pod $pod The pod config (if found).
* @param array|Field $field The field config (if found).
* @param self $obj The PodsAPI object.
* @param array $info The table information.
* @param string $object_type The object type.
* @param string $object The object name.
* @param string|null $name The pod name.
* @param array|Pod|null $pod The pod config (if found).
* @param array|Field|null $field The field config (if found).
* @param self $obj The PodsAPI object.
*/
return apply_filters( 'pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this );
} else {
Expand Down Expand Up @@ -10570,13 +10567,13 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null
*
* Use to change "default" post status from publish to any other status or statuses.
*
* @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
* @param string $post_type Post type of current object.
* @param array $info Array of information about the object.
* @param string $object Type of object.
* @param string $name Name of pod to load.
* @param array $pod Array with Pod information. Result of PodsAPI::load_pod().
* @param array $field Array with field information.
* @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
* @param string $post_type Post type of current object.
* @param array $info Array of information about the object.
* @param string $object Type of object.
* @param string|null $name Name of pod to load.
* @param array|Pod|null $pod The pod config (if found).
* @param array|Field|null $field The field config (if found).
*
* @since unknown
*/
Expand Down Expand Up @@ -10993,10 +10990,6 @@ public function import( $import_data, $numeric_mode = false, $format = null ) {
*/
global $wpdb;

if ( null === $format && null !== $this->format ) {
$format = $this->format;
}

if ( 'csv' === $format && ! is_array( $import_data ) ) {
$data = pods_migrate( 'sv', ',' )->parse( $import_data );

Expand All @@ -11016,8 +11009,6 @@ public function import( $import_data, $numeric_mode = false, $format = null ) {

if ( ! empty( $this->pod_data ) ) {
$pod = $this->pod_data;
} elseif ( ! empty( $this->pod ) ) {
$pod = $this->load_pod( [ 'name' => $this->pod ], false );
}

if ( false === $pod ) {
Expand Down Expand Up @@ -11183,8 +11174,6 @@ public function export( $pod = null, $params = null ) {
if ( empty( $pod ) ) {
if ( ! empty( $this->pod_data ) ) {
$pod = $this->pod_data;
} elseif ( ! empty( $this->pod ) ) {
$pod = $this->load_pod( [ 'name' => $this->pod ], false );
}
}

Expand Down Expand Up @@ -11683,7 +11672,7 @@ public function get_pods_object_from_wp_post( $post ) {
$post = get_post( $post );
}

if ( ! $post || is_wp_error( $post ) ) {
if ( ! $post instanceof WP_Post ) {
return false;
}

Expand Down
8 changes: 6 additions & 2 deletions classes/PodsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ public function select( $params ) {
}
}//end if

if ( is_object( $results ) ) {
$results = get_object_vars( $results );
}

/**
* Filter results of Pods Query
*
Expand All @@ -766,7 +770,7 @@ public function select( $params ) {
*
* @since unknown
*/
$results = apply_filters( 'pods_data_select', $results, $params, $instance );
$results = (array) apply_filters( 'pods_data_select', $results, $params, $instance );

Check failure on line 773 in classes/PodsData.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.2)

@param array $params does not accept actual type of parameter: object.

Check failure on line 773 in classes/PodsData.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.3)

@param array $params does not accept actual type of parameter: object.

// Clean up data we don't want to work with.
if (
Expand Down Expand Up @@ -806,7 +810,7 @@ public function select( $params ) {
* Filters whether the total_found should be calculated right away or not.
*
* @param boolean $auto_calculate_total_found Whether to auto calculate total_found.
* @param array $params Select parameters.
* @param object $params Select parameters.
* @param PodsData $instance The current PodsData instance.
*
* @since 2.7.11
Expand Down
2 changes: 1 addition & 1 deletion classes/PodsRESTHandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static function get_handler( $object, $field_name, $request, $object_type
* @param array $field_data The field data
* @param object|Pods $pod The Pods object for Pod relationship is from.
* @param int $id Current item ID
* @param object|WP_REST_Request Current request object.
* @param object|WP_REST_Request $request Current request object.
*/
$output_type = apply_filters( 'pods_rest_api_output_type_for_relationship_response', $output_type, $field_name, $field_data, $pod, $id, $request );

Expand Down
13 changes: 10 additions & 3 deletions classes/PodsUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class PodsUI {
*/
public $id = 0;

/**
* The inserted item ID.
*
* @var int
*/
public $insert_id = 0;

/**
* The prefix used for all URL parameters used by PodsUI.
*
Expand Down Expand Up @@ -2401,7 +2408,7 @@ public function get_params( $params = null, $action = null ) {
*
* @param array $find_params Parameters used with Pods::find()
* @param string $action Current action
* @param PodsUI $this PodsUI instance
* @param PodsUI $obj PodsUI instance
*
* @since 2.6.8
*/
Expand Down Expand Up @@ -2637,9 +2644,9 @@ public function manage( $reorder = false ) {
* @since 2.6.8
*
* @param array $custom_container_classes List of custom classes to use.
* @param PodsUI $this PodsUI instance.
* @param PodsUI $obj PodsUI instance.
*/
$custom_container_classes = apply_filters( 'pods_ui_manage_custom_container_classes', array() );
$custom_container_classes = apply_filters( 'pods_ui_manage_custom_container_classes', array(), $obj );

Check failure on line 2649 in classes/PodsUI.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.2)

Undefined variable: $obj

Check failure on line 2649 in classes/PodsUI.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.3)

Undefined variable: $obj

if ( is_admin() ) {
array_unshift( $custom_container_classes, 'wrap' );
Expand Down
5 changes: 3 additions & 2 deletions includes/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function pods_user_can_access_object( array $args, ?int $user_id, string $access
// Check if the user exists.
$user = get_userdata( $user_id );

if ( ! $user || is_wp_error( $user ) ) {
if ( ! $user instanceof WP_User ) {
// If the user does not exist and it was not anonymous, do not allow access to an invalid user.
if ( 0 < $user_id ) {
return false;
Expand Down Expand Up @@ -767,7 +767,8 @@ function pods_is_type_public( array $args, string $context = 'shortcode' ): bool
'pods_is_type_public',
$is_public,
$info,
$context
$context,
$pod

Check failure on line 771 in includes/access.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.2)

Undefined variable: $pod

Check failure on line 771 in includes/access.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan (8.3)

Undefined variable: $pod
);
}

Expand Down
6 changes: 3 additions & 3 deletions includes/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ function pods_is_user_admin( int $user_id, $capabilities = null ): bool {
// Check if the user exists.
$user = get_userdata( $user_id );

if ( ! $user || is_wp_error( $user ) ) {
if ( ! $user instanceof WP_User ) {
return false;
}

Expand Down Expand Up @@ -4055,7 +4055,7 @@ function pods_meta_hook_list( $object_type = 'post', $object = null ) {
* @param string $object_type The object type.
* @param string|null $object The object name.
*/
return (array) apply_filters( 'pods_meta_hook_list', $hooks, $object_type );
return (array) apply_filters( 'pods_meta_hook_list', $hooks, $object_type, $object );
}

/**
Expand Down Expand Up @@ -4977,7 +4977,7 @@ function pods_is_types_only( $check_constant_only = false, $content_type = null
* @param bool $is_types_only Whether Pods is being used for content types only.
* @param null|string $content_type The content type context we are in.
*/
return (bool) apply_filters( 'pods_is_types_only', $is_types_only );
return (bool) apply_filters( 'pods_is_types_only', $is_types_only, $content_type );
}

/**
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ parameters:
- ui/front
- init.php
- vendor/vendor-prefixed
excludePaths:
- src/Integrations
- tests
2 changes: 1 addition & 1 deletion tests/codeception/wpunit/Pods/PodsRESTHandlersTest.php

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

0 comments on commit 013ea67

Please sign in to comment.