Skip to content

Commit

Permalink
chore: Linter and PHPStan compliance met
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 7, 2024
1 parent 22331ee commit bb0eadf
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 129 deletions.
4 changes: 2 additions & 2 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public static function inject_type_resolver( $type, $value ) {
* Resolves GraphQL type for provided product model.
*
* @param \WPGraphQL\WooCommerce\Model\Product $value Product model.
*
*
* @throws \GraphQL\Error\UserError Invalid product type requested.
*
* @return mixed
Expand Down Expand Up @@ -420,7 +420,7 @@ public static function resolve_product_type( $value ) {
* Resolves GraphQL type for provided product variation model.
*
* @param \WPGraphQL\WooCommerce\Model\Product $value Product model.
*
*
* @throws \GraphQL\Error\UserError Invalid product type requested.
*
* @return mixed
Expand Down
4 changes: 2 additions & 2 deletions includes/class-jwt-auth-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function get_auth_class() {
* Get the auth token for a user.
*
* @param \WP_User $user The user object.
*
*
* @throws \GraphQL\Error\UserError If the token cannot be retrieved.
*
* @return string|null
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function get_auth_token( \WP_User $user ) {
* Get the refresh token for a user.
*
* @param \WP_User $user The user object.
*
*
* @throws \GraphQL\Error\UserError If the token cannot be retrieved.
*
* @return string|null
Expand Down
4 changes: 2 additions & 2 deletions includes/connection/class-customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $
* has been added to the UserConnectionResolver
*
* @param array $connection Resolved connection.
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $resolver Resolver class.
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $resolver Resolver class.
*
* @return array
*/
public static function upgrade_models( $connection, $resolver ) {
if ( 'customers' === $resolver->get_info()->fieldName ) {
if ( 'customers' === $resolver->get_info()->fieldName ) { // @phpstan-ignore-line
$nodes = [];
$edges = [];
foreach ( $connection['nodes'] as $node ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/connection/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static function get_connection_fields(): array {

/**
* Returns array of where args.
*
*
* @param array $extra_args Extra connection args.
*
* @return array
Expand Down Expand Up @@ -379,7 +379,7 @@ public static function get_connection_args( $extra_args = [] ): array {
'type' => 'Int',
'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'wp-graphql-woocommerce' ),
],
'attributes' => [
'attributes' => [
'type' => 'ProductAttributeQueryInput',
'description' => __( 'Limit result set to products with selected global attribute queries.', 'wp-graphql-woocommerce' ),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function get_ids() {

/**
* Returns meta keys to be used for connection ordering.
*
*
* @param bool $is_numeric Return numeric meta keys. Defaults to "true".
*
* @return array
Expand Down
92 changes: 28 additions & 64 deletions includes/data/connection/class-product-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Product_Connection_Resolver extends AbstractConnectionResolver {
*
* @var Filterer
*/
private $filterer;

private $filterer; // @phpstan-ignore-line

/**
* Refund_Connection_Resolver constructor.
Expand All @@ -53,7 +52,7 @@ public function __construct( $source, $args, $context, $info ) {
// @codingStandardsIgnoreLine.
$this->post_type = ['product'];

$this->filterer = wc_get_container()->get( Filterer::class );
$this->filterer = wc_get_container()->get( Filterer::class ); // @phpstan-ignore-line

/**
* Call the parent construct to setup class data
Expand Down Expand Up @@ -100,7 +99,6 @@ public function get_query_args() {
*/
$query_args['post_type'] = $this->post_type;


/**
* Set the wc_query to product_query
*/
Expand Down Expand Up @@ -162,7 +160,7 @@ public function get_query_args() {
* Don't order search results by title (causes funky issues with cursors)
*/
$query_args['search_orderby_title'] = false;
$query_args = array_merge( $query_args, \WC()->query->get_catalog_ordering_args( 'relevance', isset( $last ) ? 'ASC' : 'DESC' ) );
$query_args = array_merge( $query_args, \WC()->query->get_catalog_ordering_args( 'relevance', isset( $last ) ? 'ASC' : 'DESC' ) );
}

/**
Expand All @@ -171,42 +169,13 @@ public function get_query_args() {
* @var \WP_Post_Type
*/
$post_type_obj = get_post_type_object( 'product' );

if ( empty( $this->args['where']['visibility'] ) && ! current_user_can( $post_type_obj->cap->read_private_posts ) ) {
if ( empty( $query_args['tax_query'] ) ) {
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
$query_args['tax_query'] = [];
}

// /**
// * Filters the default catalog visibility tax query for non-adminstrator requests.
// *
// * @param array $default_visibility Default catalog visibility tax query.
// * @param array $query_args The args that will be passed to the WP_Query.
// * @param mixed $source The source that's passed down the GraphQL queries.
// * @param array $args The inputArgs on the field.
// * @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree.
// * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree.
// */
// $catalog_visibility = apply_filters(
// 'graphql_product_connection_catalog_visibility',
// [
// 'taxonomy' => 'product_visibility',
// 'field' => 'slug',
// 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ],
// 'operator' => 'NOT IN',
// ],
// $query_args,
// $this->source,
// $this->args,
// $this->context,
// $this->info
// );

// if ( ! empty( $catalog_visibility ) ) {
// $query_args['tax_query'][] = $catalog_visibility;
// }

if ( 1 < count( $query_args['tax_query'] ) ) {
$query_args['tax_query']['relation'] = 'AND';
}
Expand Down Expand Up @@ -236,15 +205,13 @@ public function get_query_args() {

/**
* {@inheritDoc}
*
* @return \WC_Query
*/
public function get_query() {

// Run query and add product query filters.
$wp_query = new \WP_Query();
$wp_query = new \WP_Query();
$wp_query->query_vars = wp_parse_args( $this->query_args );
add_filter( 'posts_clauses', array( $this, 'product_query_post_clauses' ), 10, 2 );
add_filter( 'posts_clauses', [ $this, 'product_query_post_clauses' ], 10, 2 );

return $wp_query;
}
Expand All @@ -263,16 +230,16 @@ public function product_query_post_clauses( $args, $wp_query ) {
}

$args = $this->price_filter_post_clauses( $args, $wp_query );
$args = $this->filterer->filter_by_attribute_post_clauses( $args, $wp_query, [] );
$args = $this->filterer->filter_by_attribute_post_clauses( $args, $wp_query, [] ); // @phpstan-ignore-line

return $args;
}

/**
* Custom query used to filter products by price.
*
* @param array $args Query args.
* @param WP_Query $wp_query WP_Query object.
* @param array $args SQL clauses $args Query args.
* @param \WP_Query $wp_query WP_Query object.
*
* @return array
*/
Expand All @@ -292,16 +259,16 @@ public function price_filter_post_clauses( $args, $wp_query ) {
* Kicks in when prices excluding tax are displayed including tax.
*/
if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {
$tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.
$tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$tax_rates = \WC_Tax::get_rates( $tax_class );

if ( $tax_rates ) {
$current_min_price -= \WC_Tax::get_tax_total( \WC_Tax::calc_inclusive_tax( $current_min_price, $tax_rates ) );
$current_max_price -= \WC_Tax::get_tax_total( \WC_Tax::calc_inclusive_tax( $current_max_price, $tax_rates ) );
}
}
$args['join'] .= ! strstr( $args['join'], 'wc_product_meta_lookup' )

$args['join'] .= ! strstr( $args['join'], 'wc_product_meta_lookup' )
? " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON $wpdb->posts.ID = wc_product_meta_lookup.product_id "
: '';
$args['where'] .= $wpdb->prepare(
Expand All @@ -317,7 +284,7 @@ public function price_filter_post_clauses( $args, $wp_query ) {
*/
public function get_ids_from_query() {
$ids = $this->query->get_posts();
remove_filter( 'posts_clauses', array( $this, 'product_query_post_clauses' ), 10, 2 );
remove_filter( 'posts_clauses', [ $this, 'product_query_post_clauses' ], 10 );

// If we're going backwards, we need to reverse the array.
if ( ! empty( $this->args['last'] ) ) {
Expand All @@ -331,7 +298,7 @@ public function get_ids_from_query() {
* Returns meta keys to be used for connection ordering.
*
* @param bool $is_numeric Return numeric meta keys. Defaults to "true".
*
*
* @return array
*/
public function ordering_meta( $is_numeric = true ) {
Expand Down Expand Up @@ -384,12 +351,11 @@ public function sanitize_input_fields( array $where_args ) {
$default_order = isset( $this->args['last'] ) ? 'ASC' : 'DESC';
$orderby_input = current( $where_args['orderby'] );

$orderby = $orderby_input['field'];
$order = ! empty( $orderby_input['order'] ) ? $orderby_input['order'] : $default_order;
$query_args = array_merge( $query_args, \WC()->query->get_catalog_ordering_args( $orderby, $order ) );
$orderby = $orderby_input['field'];
$order = ! empty( $orderby_input['order'] ) ? $orderby_input['order'] : $default_order;
$query_args = array_merge( $query_args, \WC()->query->get_catalog_ordering_args( $orderby, $order ) );
}


if ( isset( $where_args['includeVariations'] ) && $where_args['includeVariations'] ) {
$query_args['post_type'] = [ 'product', 'product_variation' ];
}
Expand Down Expand Up @@ -527,9 +493,9 @@ public function sanitize_input_fields( array $where_args ) {
}

$operator = isset( $attribute['operator'] ) ? $attribute['operator'] : 'IN';

if ( ! empty( $attribute['terms'] ) ) {
foreach( $attribute['terms'] as $term ) {
foreach ( $attribute['terms'] as $term ) {
$att_queries[] = [
'taxonomy' => $attribute['taxonomy'],
'field' => 'slug',
Expand All @@ -540,7 +506,7 @@ public function sanitize_input_fields( array $where_args ) {
}

if ( ! empty( $attribute['ids'] ) ) {
foreach( $attribute['ids'] as $id ) {
foreach ( $attribute['ids'] as $id ) {
$att_queries[] = [
'taxonomy' => $attribute['taxonomy'],
'field' => 'term_id',
Expand All @@ -552,16 +518,16 @@ public function sanitize_input_fields( array $where_args ) {
}

if ( 1 < count( $att_queries ) ) {
$relation = ! empty( $where_args['attributes']['relation'] ) ? $where_args['attributes']['relation'] : 'AND';
$relation = ! empty( $where_args['attributes']['relation'] ) ? $where_args['attributes']['relation'] : 'AND';
if ( 'NOT_IN' === $relation ) {
graphql_debug( __( 'The "NOT_IN" relation is not supported for attributes. Please use "IN" or "AND" instead.', 'wp-graphql-woocommerce' ) );
$relation = 'IN';
}

$tax_query[] = [
'relation' => $relation,
...$att_queries,
];
$tax_query[] = array_merge(
[ 'relation' => $relation ],
$att_queries
);
} else {
$tax_query = array_merge( $tax_query, $att_queries );
}
Expand Down Expand Up @@ -654,7 +620,7 @@ public function sanitize_input_fields( array $where_args ) {
'terms' => $rating_terms,
];
}

// Process "taxonomyFilter".
$tax_filter_query = [];
if ( ! empty( $where_args['taxonomyFilter'] ) ) {
Expand Down Expand Up @@ -750,8 +716,6 @@ public function sanitize_input_fields( array $where_args ) {
$query_args[ $on_sale_key ] = $on_sale_ids;
}



/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -810,9 +774,9 @@ public function is_valid_offset( $offset ) {

/**
* Adds meta query to the query args.
*
*
* @param array $value Meta query.
*
*
* @return \WPGraphQL\WooCommerce\Data\Connection\Product_Connection_Resolver
*/
public function add_meta_query( $value ) {
Expand Down
6 changes: 3 additions & 3 deletions includes/data/loader/class-wc-cpt-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WC_CPT_Loader extends AbstractDataLoader {
* @param boolean $fatal Throw if no model found.
*
* @throws \GraphQL\Error\UserError - throws if no corresponding Model is registered to the post-type.
*
*
* @return \WPGraphQL\Model\Model|null
*/
public static function resolve_model( $post_type, $id, $fatal = true ) {
Expand All @@ -52,7 +52,7 @@ public static function resolve_model( $post_type, $id, $fatal = true ) {
/**
* If a model is registered to the post-type, we can return an instance of that model
* with the post ID passed in.
*
*
* @var \WPGraphQL\Model\Model
*/
return new $model( $id );
Expand Down Expand Up @@ -153,7 +153,7 @@ static function ( $split, \WP_Query $query ) {

/**
* {@inheritDoc}
*
*
* @return \WPGraphQL\Model\Model|null
*/
protected function get_model( $entry, $key ) {
Expand Down
1 change: 0 additions & 1 deletion includes/mutation/class-review-delete-restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Relay;
use WPGraphQL\AppContext;
use WPGraphQL\Data\DataSource;

/**
* Class Review_Delete_Restore
Expand Down
16 changes: 8 additions & 8 deletions includes/type/input/class-product-attribute-query-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public static function register() {
[
'description' => __( 'Product filter', 'wp-graphql-woocommerce' ),
'fields' => [
'queries' => [
'type' => [ 'list_of' => 'ProductAttributeFilterInput' ],
'description' => __( 'Limit result set to products with selected global attributes.', 'wp-graphql-woocommerce' ),
],
'relation' => [
'type' => 'AttributeOperatorEnum',
'description' => __( 'The logical relationship between attributes when filtering across multiple at once.', 'wp-graphql-woocommerce' ),
],
'queries' => [
'type' => [ 'list_of' => 'ProductAttributeFilterInput' ],
'description' => __( 'Limit result set to products with selected global attributes.', 'wp-graphql-woocommerce' ),
],
'relation' => [
'type' => 'AttributeOperatorEnum',
'description' => __( 'The logical relationship between attributes when filtering across multiple at once.', 'wp-graphql-woocommerce' ),
],
],
]
);
Expand Down
2 changes: 1 addition & 1 deletion includes/type/interface/class-downloadable-product.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Defines the "DownloadableProduct" interface.
*
*
* @package WPGraphQL\WooCommerce\Type\WPInterface
* @since 0.17.0
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/type/interface/class-inventoried-product.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Defines the "InventoriedProduct" interface.
*
*
* @package WPGraphQL\WooCommerce\Type\WPInterface
* @since 0.17.0
*/
Expand Down
Loading

0 comments on commit bb0eadf

Please sign in to comment.