@@ -22,37 +22,37 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @paramm Gardening_Kg_Store $store |
24 | 24 | */ |
25 | - public function __construct( Store $store, Api_Service $api_service ) { |
|
25 | + public function __construct(Store $store, Api_Service $api_service) { |
|
26 | 26 | $this->store = $store; |
27 | 27 | $this->api_service = $api_service; |
28 | 28 | } |
29 | 29 | |
30 | 30 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
31 | - public function run( $last_id ) { |
|
31 | + public function run($last_id) { |
|
32 | 32 | $batch_size = 100; |
33 | - $items = (array) $this->store->list_items( $last_id, $batch_size ); |
|
33 | + $items = (array) $this->store->list_items($last_id, $batch_size); |
|
34 | 34 | |
35 | - foreach ( $items as $item ) { |
|
36 | - $this->process( $item ); |
|
35 | + foreach ($items as $item) { |
|
36 | + $this->process($item); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // Count the processed items. |
40 | - $count_items = count( $items ); |
|
40 | + $count_items = count($items); |
|
41 | 41 | |
42 | 42 | // We're done, since the number of items is less than the requested qty. |
43 | - if ( $count_items < $batch_size ) { |
|
44 | - return array( $count_items, null ); |
|
43 | + if ($count_items < $batch_size) { |
|
44 | + return array($count_items, null); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | // Get the last ID. |
48 | - $last_id = end( $items ); |
|
48 | + $last_id = end($items); |
|
49 | 49 | |
50 | 50 | // Finally return the count. |
51 | - return array( $count_items, $last_id ); |
|
51 | + return array($count_items, $last_id); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
55 | - private function process( $item ) { |
|
55 | + private function process($item) { |
|
56 | 56 | global $wpdb; |
57 | 57 | |
58 | 58 | // Get the entity data for non lifted abouts. |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | ); |
66 | 66 | |
67 | 67 | // Exit if not found. |
68 | - if ( ! isset( $id ) ) { |
|
68 | + if ( ! isset($id)) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // Lift. |
73 | - $term = get_term( $item ); |
|
73 | + $term = get_term($item); |
|
74 | 74 | |
75 | 75 | // Skip if this post must not be processed, e.g. it's not the right post_type, it's not `publish`, ... |
76 | - if ( ! $this->should_process( $term ) ) { |
|
76 | + if ( ! $this->should_process($term)) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - $title = wp_strip_all_tags( $term->name ); |
|
80 | + $title = wp_strip_all_tags($term->name); |
|
81 | 81 | |
82 | 82 | $response = $this->api_service->request( |
83 | 83 | 'POST', |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | ); |
91 | 91 | |
92 | 92 | $response_body = $response->get_body(); |
93 | - $lines = explode( "\n", $response_body ); |
|
94 | - $fields = explode( "\t", $lines[0] ); |
|
95 | - $jsonld = isset( $fields[1] ) ? trim( $fields[1] ) : ''; |
|
93 | + $lines = explode("\n", $response_body); |
|
94 | + $fields = explode("\t", $lines[0]); |
|
95 | + $jsonld = isset($fields[1]) ? trim($fields[1]) : ''; |
|
96 | 96 | // No results. |
97 | - if ( empty( $jsonld ) ) { |
|
97 | + if (empty($jsonld)) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - private function should_process( $term ) { |
|
111 | + private function should_process($term) { |
|
112 | 112 | |
113 | - return is_a( $term, 'WP_Term' ) && |
|
113 | + return is_a($term, 'WP_Term') && |
|
114 | 114 | in_array( |
115 | 115 | $term->taxonomy, |
116 | 116 | array( |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function get_total() { |
132 | 132 | global $wpdb; |
133 | 133 | |
134 | - return intval( $wpdb->get_var( "SELECT COUNT(1) FROM $wpdb->posts WHERE post_status = 'publish'" ) ); |
|
134 | + return intval($wpdb->get_var("SELECT COUNT(1) FROM $wpdb->posts WHERE post_status = 'publish'")); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @throws \Exception Throws Exception if the parameters arent of right type. |
24 | 24 | */ |
25 | - public function __construct( $params, $sort ) { |
|
25 | + public function __construct($params, $sort) { |
|
26 | 26 | |
27 | - Assertions::is_array( $params ); |
|
28 | - Assertions::is_a( $sort, Match_Sort::class ); |
|
27 | + Assertions::is_array($params); |
|
28 | + Assertions::is_a($sort, Match_Sort::class); |
|
29 | 29 | |
30 | 30 | $this->params = $params; |
31 | 31 | $this->sort = $sort; |
@@ -58,41 +58,41 @@ discard block |
||
58 | 58 | |
59 | 59 | // If there is no position set, the condition doesnt need to be applied |
60 | 60 | // This is necessary in case of `last` and `first` attribute. |
61 | - if ( empty( $this->params['position'] ) ) { |
|
61 | + if (empty($this->params['position'])) { |
|
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $tmp_sql = " AND {$this->sort->get_field_name()} "; |
66 | - $is_included = ( $this->params['element'] !== 'EXCLUDED' ); |
|
67 | - $is_ascending = ( $this->params['direction'] !== 'DESCENDING' ); |
|
66 | + $is_included = ($this->params['element'] !== 'EXCLUDED'); |
|
67 | + $is_ascending = ($this->params['direction'] !== 'DESCENDING'); |
|
68 | 68 | $is_sorted_ascending = $this->sort->is_ascending(); |
69 | - switch ( array( $is_ascending, $is_sorted_ascending ) ) { |
|
70 | - case array( true, true ): // Forward & Ascending Order |
|
71 | - case array( false, false ): // Backward & Descending Order |
|
69 | + switch (array($is_ascending, $is_sorted_ascending)) { |
|
70 | + case array(true, true): // Forward & Ascending Order |
|
71 | + case array(false, false): // Backward & Descending Order |
|
72 | 72 | $tmp_sql .= ' >'; |
73 | 73 | break; |
74 | - case array( true, false ): // Forward & Ascending Order |
|
75 | - case array( false, true ): // Backward & Descending Order |
|
74 | + case array(true, false): // Forward & Ascending Order |
|
75 | + case array(false, true): // Backward & Descending Order |
|
76 | 76 | $tmp_sql .= ' <'; |
77 | 77 | break; |
78 | 78 | } |
79 | - if ( $is_included ) { |
|
79 | + if ($is_included) { |
|
80 | 80 | $tmp_sql .= '='; |
81 | 81 | } |
82 | 82 | $tmp_sql .= ' %s'; |
83 | 83 | |
84 | 84 | // `$tmp_sql` is built dynamically in this function |
85 | 85 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
86 | - $this->sql .= $wpdb->prepare( $tmp_sql, $this->params['position'] ); |
|
86 | + $this->sql .= $wpdb->prepare($tmp_sql, $this->params['position']); |
|
87 | 87 | return $this; |
88 | 88 | } |
89 | 89 | |
90 | 90 | protected function has_match() { |
91 | 91 | $value = $this->params['has_match']; |
92 | 92 | |
93 | - if ( true === $value ) { |
|
93 | + if (true === $value) { |
|
94 | 94 | $this->sql .= ' AND e.about_jsonld IS NOT NULL '; |
95 | - } elseif ( false === $value ) { |
|
95 | + } elseif (false === $value) { |
|
96 | 96 | $this->sql .= ' AND e.about_jsonld IS NULL '; |
97 | 97 | } |
98 | 98 | |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | protected function limit() { |
103 | 103 | $limit = $this->params['limit']; |
104 | 104 | global $wpdb; |
105 | - $this->sql .= $wpdb->prepare( ' LIMIT %d', $limit ); |
|
105 | + $this->sql .= $wpdb->prepare(' LIMIT %d', $limit); |
|
106 | 106 | return $this; |
107 | 107 | } |
108 | 108 | |
109 | 109 | protected function order_by() { |
110 | 110 | $direction = $this->params['direction']; |
111 | - $this->sql .= $this->sort->get_orderby_clause( $direction ); |
|
111 | + $this->sql .= $this->sort->get_orderby_clause($direction); |
|
112 | 112 | return $this; |
113 | 113 | } |
114 | 114 |