Completed
Branch EDTR/date-actions-menu (96ea0e)
by
unknown
47:38 queued 39:05
created
domain/services/graphql/connection_resolvers/AbstractConnectionResolver.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -17,131 +17,131 @@
 block discarded – undo
17 17
 abstract class AbstractConnectionResolver extends WPGraphQLConnectionResolver
18 18
 {
19 19
 
20
-    /**
21
-     * Set limit the highest value of first and last, with a (filterable) max of 100
22
-     *
23
-     * @return array
24
-     */
25
-    protected function getLimit()
26
-    {
27
-        $first = ! empty($this->args['first']) ? absint($this->args['first']) : null;
28
-        $last  = ! empty($this->args['last']) ? absint($this->args['last']) : null;
20
+	/**
21
+	 * Set limit the highest value of first and last, with a (filterable) max of 100
22
+	 *
23
+	 * @return array
24
+	 */
25
+	protected function getLimit()
26
+	{
27
+		$first = ! empty($this->args['first']) ? absint($this->args['first']) : null;
28
+		$last  = ! empty($this->args['last']) ? absint($this->args['last']) : null;
29 29
 
30
-        $limit = min(
31
-            max($first, $last, 100),
32
-            $this->query_amount
33
-        );
34
-        $limit++;
35
-        return $limit;
36
-    }
30
+		$limit = min(
31
+			max($first, $last, 100),
32
+			$this->query_amount
33
+		);
34
+		$limit++;
35
+		return $limit;
36
+	}
37 37
 
38
-    /**
39
-     * Determine whether or not the the offset is valid, i.e the entity corresponding to the
40
-     * offset exists. Offset is equivalent to entity ID. So this function is equivalent to
41
-     * checking if the entity with the given ID exists.
42
-     *
43
-     * @access public
44
-     *
45
-     * @param int $offset The ID of the node used for the cursor offset
46
-     *
47
-     * @return bool
48
-     */
49
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
50
-    public function is_valid_offset($offset)
51
-    {
52
-        $entity = $this->get_query()->get_one_by_ID($offset);
38
+	/**
39
+	 * Determine whether or not the the offset is valid, i.e the entity corresponding to the
40
+	 * offset exists. Offset is equivalent to entity ID. So this function is equivalent to
41
+	 * checking if the entity with the given ID exists.
42
+	 *
43
+	 * @access public
44
+	 *
45
+	 * @param int $offset The ID of the node used for the cursor offset
46
+	 *
47
+	 * @return bool
48
+	 */
49
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
50
+	public function is_valid_offset($offset)
51
+	{
52
+		$entity = $this->get_query()->get_one_by_ID($offset);
53 53
         
54
-        return $entity instanceof EE_Base_Class;
55
-    }
54
+		return $entity instanceof EE_Base_Class;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
60
-     * friendly keys.
61
-     *
62
-     * @param array  $query_args
63
-     * @param array  $where_params
64
-     * @param string $primary_key
65
-     * @return array
66
-     */
67
-    protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key)
68
-    {
69
-        // ID of the current offset
70
-        $offset = $this->get_offset();
71
-        /**
72
-         * Map the orderby inputArgs to the WP_Query
73
-         */
74
-        if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) {
75
-            $query_args['order_by'] = [];
76
-            foreach ($this->args['where']['orderby'] as $orderby_input) {
77
-                $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order'];
78
-            }
79
-        } elseif ($offset) {
80
-            $compare                      = $this->args['last'] ? '<' : '>';
81
-            $where_params[ $primary_key ] = [ $compare, $offset ];
82
-        }
83
-        return [ $query_args, $where_params ];
84
-    }
58
+	/**
59
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
60
+	 * friendly keys.
61
+	 *
62
+	 * @param array  $query_args
63
+	 * @param array  $where_params
64
+	 * @param string $primary_key
65
+	 * @return array
66
+	 */
67
+	protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key)
68
+	{
69
+		// ID of the current offset
70
+		$offset = $this->get_offset();
71
+		/**
72
+		 * Map the orderby inputArgs to the WP_Query
73
+		 */
74
+		if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) {
75
+			$query_args['order_by'] = [];
76
+			foreach ($this->args['where']['orderby'] as $orderby_input) {
77
+				$query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order'];
78
+			}
79
+		} elseif ($offset) {
80
+			$compare                      = $this->args['last'] ? '<' : '>';
81
+			$where_params[ $primary_key ] = [ $compare, $offset ];
82
+		}
83
+		return [ $query_args, $where_params ];
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
89
-     * friendly keys.
90
-     *
91
-     * @param array $where_args
92
-     * @param array $arg_mapping
93
-     * @param array $id_fields   The fields to convert from global IDs to DB IDs.
94
-     * @return array
95
-     */
96
-    protected function sanitizeWhereArgsForInputFields(
97
-        array $where_args,
98
-        array $arg_mapping,
99
-        array $id_fields
100
-    ) {
101
-        $query_args = [];
87
+	/**
88
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
89
+	 * friendly keys.
90
+	 *
91
+	 * @param array $where_args
92
+	 * @param array $arg_mapping
93
+	 * @param array $id_fields   The fields to convert from global IDs to DB IDs.
94
+	 * @return array
95
+	 */
96
+	protected function sanitizeWhereArgsForInputFields(
97
+		array $where_args,
98
+		array $arg_mapping,
99
+		array $id_fields
100
+	) {
101
+		$query_args = [];
102 102
 
103
-        foreach ($where_args as $arg => $value) {
104
-            if (! array_key_exists($arg, $arg_mapping)) {
105
-                continue;
106
-            }
103
+		foreach ($where_args as $arg => $value) {
104
+			if (! array_key_exists($arg, $arg_mapping)) {
105
+				continue;
106
+			}
107 107
 
108
-            if (is_array($value) && ! empty($value)) {
109
-                $value = array_map(
110
-                    static function ($value) {
111
-                        if (is_string($value)) {
112
-                            $value = sanitize_text_field($value);
113
-                        }
114
-                        return $value;
115
-                    },
116
-                    $value
117
-                );
118
-            } elseif (is_string($value)) {
119
-                $value = sanitize_text_field($value);
120
-            }
121
-            $query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true)
122
-                ? $this->convertGlobalId($value)
123
-                : $value;
124
-        }
108
+			if (is_array($value) && ! empty($value)) {
109
+				$value = array_map(
110
+					static function ($value) {
111
+						if (is_string($value)) {
112
+							$value = sanitize_text_field($value);
113
+						}
114
+						return $value;
115
+					},
116
+					$value
117
+				);
118
+			} elseif (is_string($value)) {
119
+				$value = sanitize_text_field($value);
120
+			}
121
+			$query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true)
122
+				? $this->convertGlobalId($value)
123
+				: $value;
124
+		}
125 125
 
126
-        /**
127
-         * Return the Query Args
128
-         */
129
-        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
130
-    }
126
+		/**
127
+		 * Return the Query Args
128
+		 */
129
+		return ! empty($query_args) && is_array($query_args) ? $query_args : [];
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * Converts global ID to DB ID.
135
-     *
136
-     * @param string|string[] $ID
137
-     * @return mixed
138
-     */
139
-    protected function convertGlobalId($ID)
140
-    {
141
-        if (is_array($ID)) {
142
-            return array_map([ $this, 'convertGlobalId' ], $ID);
143
-        }
144
-        $parts = Relay::fromGlobalId($ID);
145
-        return ! empty($parts['id']) ? $parts['id'] : null;
146
-    }
133
+	/**
134
+	 * Converts global ID to DB ID.
135
+	 *
136
+	 * @param string|string[] $ID
137
+	 * @return mixed
138
+	 */
139
+	protected function convertGlobalId($ID)
140
+	{
141
+		if (is_array($ID)) {
142
+			return array_map([ $this, 'convertGlobalId' ], $ID);
143
+		}
144
+		$parts = Relay::fromGlobalId($ID);
145
+		return ! empty($parts['id']) ? $parts['id'] : null;
146
+	}
147 147
 }
Please login to merge, or discard this patch.