Passed
Push — master ( 64f340...ccb079 )
by Paul
08:17 queued 03:57
created
plugin/Database/SqlQueries.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -8,47 +8,47 @@  discard block
 block discarded – undo
8 8
 
9 9
 class SqlQueries
10 10
 {
11
-    protected $db;
12
-    protected $postType;
11
+	protected $db;
12
+	protected $postType;
13 13
 
14
-    public function __construct()
15
-    {
16
-        global $wpdb;
17
-        $this->db = $wpdb;
18
-        $this->postType = Application::POST_TYPE;
19
-    }
14
+	public function __construct()
15
+	{
16
+		global $wpdb;
17
+		$this->db = $wpdb;
18
+		$this->postType = Application::POST_TYPE;
19
+	}
20 20
 
21
-    /**
22
-     * @return bool
23
-     */
24
-    public function deletePostCountMetaKeys()
25
-    {
26
-        $this->db->query("
21
+	/**
22
+	 * @return bool
23
+	 */
24
+	public function deletePostCountMetaKeys()
25
+	{
26
+		$this->db->query("
27 27
             DELETE
28 28
             FROM {$this->db->postmeta}
29 29
             WHERE meta_key LIKE '_glsr_%'
30 30
         ");
31
-    }
31
+	}
32 32
 
33
-    /**
34
-     * @return bool
35
-     */
36
-    public function deleteTermCountMetaKeys()
37
-    {
38
-        $this->db->query("
33
+	/**
34
+	 * @return bool
35
+	 */
36
+	public function deleteTermCountMetaKeys()
37
+	{
38
+		$this->db->query("
39 39
             DELETE
40 40
             FROM {$this->db->termmeta}
41 41
             WHERE meta_key LIKE '_glsr_%'
42 42
         ");
43
-    }
43
+	}
44 44
 
45
-    /**
46
-     * @param string $metaReviewId
47
-     * @return int
48
-     */
49
-    public function getPostIdFromReviewId($metaReviewId)
50
-    {
51
-        $postId = $this->db->get_var("
45
+	/**
46
+	 * @param string $metaReviewId
47
+	 * @return int
48
+	 */
49
+	public function getPostIdFromReviewId($metaReviewId)
50
+	{
51
+		$postId = $this->db->get_var("
52 52
             SELECT p.ID
53 53
             FROM {$this->db->posts} AS p
54 54
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
             AND m.meta_key = '_review_id'
57 57
             AND m.meta_value = '{$metaReviewId}'
58 58
         ");
59
-        return intval($postId);
60
-    }
59
+		return intval($postId);
60
+	}
61 61
 
62
-    /**
63
-     * @param int $lastPostId
64
-     * @param int $limit
65
-     * @return array
66
-     */
67
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
68
-    {
69
-        return (array) $this->db->get_results("
62
+	/**
63
+	 * @param int $lastPostId
64
+	 * @param int $limit
65
+	 * @return array
66
+	 */
67
+	public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
68
+	{
69
+		return (array) $this->db->get_results("
70 70
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
71 71
             FROM {$this->db->posts} AS p
72 72
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
             ORDER By p.ID ASC
82 82
             LIMIT {$limit}
83 83
         ");
84
-    }
84
+	}
85 85
 
86
-    /**
87
-     * @todo remove this?
88
-     * @param string $metaKey
89
-     * @return array
90
-     */
91
-    public function getReviewCountsFor($metaKey)
92
-    {
93
-        $metaKey = Str::prefix('_', $metaKey);
94
-        return (array) $this->db->get_results("
86
+	/**
87
+	 * @todo remove this?
88
+	 * @param string $metaKey
89
+	 * @return array
90
+	 */
91
+	public function getReviewCountsFor($metaKey)
92
+	{
93
+		$metaKey = Str::prefix('_', $metaKey);
94
+		return (array) $this->db->get_results("
95 95
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
96 96
             FROM {$this->db->posts} AS p
97 97
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
             AND m.meta_key = '{$metaKey}'
100 100
             GROUP BY name
101 101
         ");
102
-    }
102
+	}
103 103
 
104
-    /**
105
-     * @todo remove this?
106
-     * @param string $reviewType
107
-     * @return array
108
-     */
109
-    public function getReviewIdsByType($reviewType)
110
-    {
111
-        $results = $this->db->get_col("
104
+	/**
105
+	 * @todo remove this?
106
+	 * @param string $reviewType
107
+	 * @return array
108
+	 */
109
+	public function getReviewIdsByType($reviewType)
110
+	{
111
+		$results = $this->db->get_col("
112 112
             SELECT DISTINCT m1.meta_value AS review_id
113 113
             FROM {$this->db->posts} AS p
114 114
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
             AND m2.meta_key = '_review_type'
119 119
             AND m2.meta_value = '{$reviewType}'
120 120
         ");
121
-        return array_keys(array_flip($results));
122
-    }
121
+		return array_keys(array_flip($results));
122
+	}
123 123
 
124
-    /**
125
-     * @param int $greaterThanId
126
-     * @param int $limit
127
-     * @return array
128
-     */
129
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
130
-    {
131
-        sort($postIds);
132
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
133
-        $postIds = implode(',', $postIds);
134
-        return (array) $this->db->get_results("
124
+	/**
125
+	 * @param int $greaterThanId
126
+	 * @param int $limit
127
+	 * @return array
128
+	 */
129
+	public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
130
+	{
131
+		sort($postIds);
132
+		$postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
133
+		$postIds = implode(',', $postIds);
134
+		return (array) $this->db->get_results("
135 135
             SELECT p.ID, m.meta_value AS rating
136 136
             FROM {$this->db->posts} AS p
137 137
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
             ORDER By p.ID ASC
145 145
             LIMIT {$limit}
146 146
         ");
147
-    }
147
+	}
148 148
 
149
-    /**
150
-     * @param string $key
151
-     * @param string $status
152
-     * @return array
153
-     */
154
-    public function getReviewsMeta($key, $status = 'publish')
155
-    {
156
-        $postStatusQuery = 'all' != $status && !empty($status)
157
-            ? "AND p.post_status = '{$status}'"
158
-            : '';
159
-        $key = Str::prefix('_', $key);
160
-        $values = $this->db->get_col("
149
+	/**
150
+	 * @param string $key
151
+	 * @param string $status
152
+	 * @return array
153
+	 */
154
+	public function getReviewsMeta($key, $status = 'publish')
155
+	{
156
+		$postStatusQuery = 'all' != $status && !empty($status)
157
+			? "AND p.post_status = '{$status}'"
158
+			: '';
159
+		$key = Str::prefix('_', $key);
160
+		$values = $this->db->get_col("
161 161
             SELECT DISTINCT m.meta_value
162 162
             FROM {$this->db->postmeta} m
163 163
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -168,42 +168,42 @@  discard block
 block discarded – undo
168 168
             GROUP BY p.ID -- remove duplicate meta_value entries
169 169
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
170 170
         ");
171
-        sort($values);
172
-        return $values;
173
-    }
171
+		sort($values);
172
+		return $values;
173
+	}
174 174
 
175
-    /**
176
-     * @param string $and
177
-     * @return string
178
-     */
179
-    protected function getAndForCounts(array $args, $and = '')
180
-    {
181
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
182
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
183
-        if (!empty($args['type'])) {
184
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
185
-        }
186
-        if ($postIds) {
187
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
188
-        }
189
-        if ($termIds) {
190
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
191
-        }
192
-        return apply_filters('site-reviews/query/and-for-counts', $and);
193
-    }
175
+	/**
176
+	 * @param string $and
177
+	 * @return string
178
+	 */
179
+	protected function getAndForCounts(array $args, $and = '')
180
+	{
181
+		$postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
182
+		$termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
183
+		if (!empty($args['type'])) {
184
+			$and.= "AND m2.meta_value = '{$args['type']}' ";
185
+		}
186
+		if ($postIds) {
187
+			$and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
188
+		}
189
+		if ($termIds) {
190
+			$and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
191
+		}
192
+		return apply_filters('site-reviews/query/and-for-counts', $and);
193
+	}
194 194
 
195
-    /**
196
-     * @param string $innerJoin
197
-     * @return string
198
-     */
199
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
200
-    {
201
-        if (!empty(Arr::get($args, 'post_ids'))) {
202
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
203
-        }
204
-        if (!empty(Arr::get($args, 'term_ids'))) {
205
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
206
-        }
207
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
208
-    }
195
+	/**
196
+	 * @param string $innerJoin
197
+	 * @return string
198
+	 */
199
+	protected function getInnerJoinForCounts(array $args, $innerJoin = '')
200
+	{
201
+		if (!empty(Arr::get($args, 'post_ids'))) {
202
+			$innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
203
+		}
204
+		if (!empty(Arr::get($args, 'term_ids'))) {
205
+			$innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
206
+		}
207
+		return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
208
+	}
209 209
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public function deletePostCountMetaKeys()
25 25
     {
26
-        $this->db->query("
26
+        $this->db->query( "
27 27
             DELETE
28 28
             FROM {$this->db->postmeta}
29 29
             WHERE meta_key LIKE '_glsr_%'
30
-        ");
30
+        " );
31 31
     }
32 32
 
33 33
     /**
@@ -35,28 +35,28 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function deleteTermCountMetaKeys()
37 37
     {
38
-        $this->db->query("
38
+        $this->db->query( "
39 39
             DELETE
40 40
             FROM {$this->db->termmeta}
41 41
             WHERE meta_key LIKE '_glsr_%'
42
-        ");
42
+        " );
43 43
     }
44 44
 
45 45
     /**
46 46
      * @param string $metaReviewId
47 47
      * @return int
48 48
      */
49
-    public function getPostIdFromReviewId($metaReviewId)
49
+    public function getPostIdFromReviewId( $metaReviewId )
50 50
     {
51
-        $postId = $this->db->get_var("
51
+        $postId = $this->db->get_var( "
52 52
             SELECT p.ID
53 53
             FROM {$this->db->posts} AS p
54 54
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
55 55
             WHERE p.post_type = '{$this->postType}'
56 56
             AND m.meta_key = '_review_id'
57 57
             AND m.meta_value = '{$metaReviewId}'
58
-        ");
59
-        return intval($postId);
58
+        " );
59
+        return intval( $postId );
60 60
     }
61 61
 
62 62
     /**
@@ -64,23 +64,23 @@  discard block
 block discarded – undo
64 64
      * @param int $limit
65 65
      * @return array
66 66
      */
67
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
67
+    public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 )
68 68
     {
69
-        return (array) $this->db->get_results("
69
+        return (array)$this->db->get_results( "
70 70
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
71 71
             FROM {$this->db->posts} AS p
72 72
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
73 73
             INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id
74
-            {$this->getInnerJoinForCounts($args)}
74
+            {$this->getInnerJoinForCounts( $args )}
75 75
             WHERE p.ID > {$lastPostId}
76 76
             AND p.post_status = 'publish'
77 77
             AND p.post_type = '{$this->postType}'
78 78
             AND m1.meta_key = '_rating'
79 79
             AND m2.meta_key = '_review_type'
80
-            {$this->getAndForCounts($args)}
80
+            {$this->getAndForCounts( $args )}
81 81
             ORDER By p.ID ASC
82 82
             LIMIT {$limit}
83
-        ");
83
+        " );
84 84
     }
85 85
 
86 86
     /**
@@ -88,17 +88,17 @@  discard block
 block discarded – undo
88 88
      * @param string $metaKey
89 89
      * @return array
90 90
      */
91
-    public function getReviewCountsFor($metaKey)
91
+    public function getReviewCountsFor( $metaKey )
92 92
     {
93
-        $metaKey = Str::prefix('_', $metaKey);
94
-        return (array) $this->db->get_results("
93
+        $metaKey = Str::prefix( '_', $metaKey );
94
+        return (array)$this->db->get_results( "
95 95
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
96 96
             FROM {$this->db->posts} AS p
97 97
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
98 98
             WHERE p.post_type = '{$this->postType}'
99 99
             AND m.meta_key = '{$metaKey}'
100 100
             GROUP BY name
101
-        ");
101
+        " );
102 102
     }
103 103
 
104 104
     /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      * @param string $reviewType
107 107
      * @return array
108 108
      */
109
-    public function getReviewIdsByType($reviewType)
109
+    public function getReviewIdsByType( $reviewType )
110 110
     {
111
-        $results = $this->db->get_col("
111
+        $results = $this->db->get_col( "
112 112
             SELECT DISTINCT m1.meta_value AS review_id
113 113
             FROM {$this->db->posts} AS p
114 114
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
             AND m1.meta_key = '_review_id'
118 118
             AND m2.meta_key = '_review_type'
119 119
             AND m2.meta_value = '{$reviewType}'
120
-        ");
121
-        return array_keys(array_flip($results));
120
+        " );
121
+        return array_keys( array_flip( $results ) );
122 122
     }
123 123
 
124 124
     /**
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
      * @param int $limit
127 127
      * @return array
128 128
      */
129
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
129
+    public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 )
130 130
     {
131
-        sort($postIds);
132
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
133
-        $postIds = implode(',', $postIds);
134
-        return (array) $this->db->get_results("
131
+        sort( $postIds );
132
+        $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit );
133
+        $postIds = implode( ',', $postIds );
134
+        return (array)$this->db->get_results( "
135 135
             SELECT p.ID, m.meta_value AS rating
136 136
             FROM {$this->db->posts} AS p
137 137
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             GROUP BY p.ID
144 144
             ORDER By p.ID ASC
145 145
             LIMIT {$limit}
146
-        ");
146
+        " );
147 147
     }
148 148
 
149 149
     /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
      * @param string $status
152 152
      * @return array
153 153
      */
154
-    public function getReviewsMeta($key, $status = 'publish')
154
+    public function getReviewsMeta( $key, $status = 'publish' )
155 155
     {
156 156
         $postStatusQuery = 'all' != $status && !empty($status)
157 157
             ? "AND p.post_status = '{$status}'"
158 158
             : '';
159
-        $key = Str::prefix('_', $key);
160
-        $values = $this->db->get_col("
159
+        $key = Str::prefix( '_', $key );
160
+        $values = $this->db->get_col( "
161 161
             SELECT DISTINCT m.meta_value
162 162
             FROM {$this->db->postmeta} m
163 163
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
             $postStatusQuery
168 168
             GROUP BY p.ID -- remove duplicate meta_value entries
169 169
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
170
-        ");
171
-        sort($values);
170
+        " );
171
+        sort( $values );
172 172
         return $values;
173 173
     }
174 174
 
@@ -176,34 +176,34 @@  discard block
 block discarded – undo
176 176
      * @param string $and
177 177
      * @return string
178 178
      */
179
-    protected function getAndForCounts(array $args, $and = '')
179
+    protected function getAndForCounts( array $args, $and = '' )
180 180
     {
181
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
182
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
183
-        if (!empty($args['type'])) {
184
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
181
+        $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) );
182
+        $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) );
183
+        if( !empty($args['type']) ) {
184
+            $and .= "AND m2.meta_value = '{$args['type']}' ";
185 185
         }
186
-        if ($postIds) {
187
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
186
+        if( $postIds ) {
187
+            $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
188 188
         }
189
-        if ($termIds) {
190
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
189
+        if( $termIds ) {
190
+            $and .= "AND tr.term_taxonomy_id IN ({$termIds}) ";
191 191
         }
192
-        return apply_filters('site-reviews/query/and-for-counts', $and);
192
+        return apply_filters( 'site-reviews/query/and-for-counts', $and );
193 193
     }
194 194
 
195 195
     /**
196 196
      * @param string $innerJoin
197 197
      * @return string
198 198
      */
199
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
199
+    protected function getInnerJoinForCounts( array $args, $innerJoin = '' )
200 200
     {
201
-        if (!empty(Arr::get($args, 'post_ids'))) {
202
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
201
+        if( !empty(Arr::get( $args, 'post_ids' )) ) {
202
+            $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
203 203
         }
204
-        if (!empty(Arr::get($args, 'term_ids'))) {
205
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
204
+        if( !empty(Arr::get( $args, 'term_ids' )) ) {
205
+            $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
206 206
         }
207
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
207
+        return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin );
208 208
     }
209 209
 }
Please login to merge, or discard this patch.
plugin/Database/TermCountsManager.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -9,93 +9,93 @@
 block discarded – undo
9 9
 
10 10
 class TermCountsManager
11 11
 {
12
-    /**
13
-     * @var CountsManager
14
-     */
15
-    protected $manager;
12
+	/**
13
+	 * @var CountsManager
14
+	 */
15
+	protected $manager;
16 16
 
17
-    public function __construct()
18
-    {
19
-        $this->manager = glsr(CountsManager::class);
20
-    }
17
+	public function __construct()
18
+	{
19
+		$this->manager = glsr(CountsManager::class);
20
+	}
21 21
 
22
-    /**
23
-     * @param int $termTaxonomyId
24
-     * @return array
25
-     */
26
-    public function build($termTaxonomyId)
27
-    {
28
-        return $this->manager->buildCounts([
29
-            'term_ids' => [$termTaxonomyId],
30
-        ]);
31
-    }
22
+	/**
23
+	 * @param int $termTaxonomyId
24
+	 * @return array
25
+	 */
26
+	public function build($termTaxonomyId)
27
+	{
28
+		return $this->manager->buildCounts([
29
+			'term_ids' => [$termTaxonomyId],
30
+		]);
31
+	}
32 32
 
33
-    /**
34
-     * @return void
35
-     */
36
-    public function decrease(Review $review)
37
-    {
38
-        foreach ($review->term_ids as $termId) {
39
-            if (empty($counts = $this->get($termId))) {
40
-                continue;
41
-            }
42
-            $this->update($termId,
43
-                $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
44
-            );
45
-        }
46
-    }
33
+	/**
34
+	 * @return void
35
+	 */
36
+	public function decrease(Review $review)
37
+	{
38
+		foreach ($review->term_ids as $termId) {
39
+			if (empty($counts = $this->get($termId))) {
40
+				continue;
41
+			}
42
+			$this->update($termId,
43
+				$this->manager->decreaseRating($counts, $review->review_type, $review->rating)
44
+			);
45
+		}
46
+	}
47 47
 
48
-    /**
49
-     * @param int $termId
50
-     * @return array
51
-     */
52
-    public function get($termId)
53
-    {
54
-        return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true));
55
-    }
48
+	/**
49
+	 * @param int $termId
50
+	 * @return array
51
+	 */
52
+	public function get($termId)
53
+	{
54
+		return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true));
55
+	}
56 56
 
57
-    /**
58
-     * @return void
59
-     */
60
-    public function increase(Review $review)
61
-    {
62
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
63
-        foreach ($terms as $term) {
64
-            $counts = $this->get($term['term_id']);
65
-            $counts = empty($counts)
66
-                ? $this->build($term['term_taxonomy_id'])
67
-                : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
68
-            $this->update($term['term_id'], $counts);
69
-        }
70
-    }
57
+	/**
58
+	 * @return void
59
+	 */
60
+	public function increase(Review $review)
61
+	{
62
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
63
+		foreach ($terms as $term) {
64
+			$counts = $this->get($term['term_id']);
65
+			$counts = empty($counts)
66
+				? $this->build($term['term_taxonomy_id'])
67
+				: $this->manager->increaseRating($counts, $review->review_type, $review->rating);
68
+			$this->update($term['term_id'], $counts);
69
+		}
70
+	}
71 71
 
72
-    /**
73
-     * @param int $termId
74
-     * @return void
75
-     */
76
-    public function update($termId, array $reviewCounts)
77
-    {
78
-        $term = get_term($termId, Application::TAXONOMY);
79
-        if (!isset($term->term_id)) {
80
-            return;
81
-        }
82
-        $ratingCounts = $this->manager->flatten($reviewCounts);
83
-        update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts);
84
-        update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
85
-        update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
86
-    }
72
+	/**
73
+	 * @param int $termId
74
+	 * @return void
75
+	 */
76
+	public function update($termId, array $reviewCounts)
77
+	{
78
+		$term = get_term($termId, Application::TAXONOMY);
79
+		if (!isset($term->term_id)) {
80
+			return;
81
+		}
82
+		$ratingCounts = $this->manager->flatten($reviewCounts);
83
+		update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts);
84
+		update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
85
+		update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function updateAll()
92
-    {
93
-        glsr(SqlQueries::class)->deleteTermCountMetaKeys();
94
-        $terms = glsr(Database::class)->getTerms([
95
-            'fields' => 'all',
96
-        ]);
97
-        foreach ($terms as $term) {
98
-            $this->update($term->term_id, $this->build($term->term_taxonomy_id));
99
-        }
100
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function updateAll()
92
+	{
93
+		glsr(SqlQueries::class)->deleteTermCountMetaKeys();
94
+		$terms = glsr(Database::class)->getTerms([
95
+			'fields' => 'all',
96
+		]);
97
+		foreach ($terms as $term) {
98
+			$this->update($term->term_id, $this->build($term->term_taxonomy_id));
99
+		}
100
+	}
101 101
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,31 +16,31 @@  discard block
 block discarded – undo
16 16
 
17 17
     public function __construct()
18 18
     {
19
-        $this->manager = glsr(CountsManager::class);
19
+        $this->manager = glsr( CountsManager::class );
20 20
     }
21 21
 
22 22
     /**
23 23
      * @param int $termTaxonomyId
24 24
      * @return array
25 25
      */
26
-    public function build($termTaxonomyId)
26
+    public function build( $termTaxonomyId )
27 27
     {
28
-        return $this->manager->buildCounts([
28
+        return $this->manager->buildCounts( [
29 29
             'term_ids' => [$termTaxonomyId],
30
-        ]);
30
+        ] );
31 31
     }
32 32
 
33 33
     /**
34 34
      * @return void
35 35
      */
36
-    public function decrease(Review $review)
36
+    public function decrease( Review $review )
37 37
     {
38
-        foreach ($review->term_ids as $termId) {
39
-            if (empty($counts = $this->get($termId))) {
38
+        foreach( $review->term_ids as $termId ) {
39
+            if( empty($counts = $this->get( $termId )) ) {
40 40
                 continue;
41 41
             }
42
-            $this->update($termId,
43
-                $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
42
+            $this->update( $termId,
43
+                $this->manager->decreaseRating( $counts, $review->review_type, $review->rating )
44 44
             );
45 45
         }
46 46
     }
@@ -49,23 +49,23 @@  discard block
 block discarded – undo
49 49
      * @param int $termId
50 50
      * @return array
51 51
      */
52
-    public function get($termId)
52
+    public function get( $termId )
53 53
     {
54
-        return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true));
54
+        return array_filter( (array)get_term_meta( $termId, CountsManager::META_COUNT, true ) );
55 55
     }
56 56
 
57 57
     /**
58 58
      * @return void
59 59
      */
60
-    public function increase(Review $review)
60
+    public function increase( Review $review )
61 61
     {
62
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
63
-        foreach ($terms as $term) {
64
-            $counts = $this->get($term['term_id']);
62
+        $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) );
63
+        foreach( $terms as $term ) {
64
+            $counts = $this->get( $term['term_id'] );
65 65
             $counts = empty($counts)
66
-                ? $this->build($term['term_taxonomy_id'])
67
-                : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
68
-            $this->update($term['term_id'], $counts);
66
+                ? $this->build( $term['term_taxonomy_id'] )
67
+                : $this->manager->increaseRating( $counts, $review->review_type, $review->rating );
68
+            $this->update( $term['term_id'], $counts );
69 69
         }
70 70
     }
71 71
 
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
      * @param int $termId
74 74
      * @return void
75 75
      */
76
-    public function update($termId, array $reviewCounts)
76
+    public function update( $termId, array $reviewCounts )
77 77
     {
78
-        $term = get_term($termId, Application::TAXONOMY);
79
-        if (!isset($term->term_id)) {
78
+        $term = get_term( $termId, Application::TAXONOMY );
79
+        if( !isset($term->term_id) ) {
80 80
             return;
81 81
         }
82
-        $ratingCounts = $this->manager->flatten($reviewCounts);
83
-        update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts);
84
-        update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
85
-        update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
82
+        $ratingCounts = $this->manager->flatten( $reviewCounts );
83
+        update_term_meta( $termId, CountsManager::META_COUNT, $reviewCounts );
84
+        update_term_meta( $termId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
85
+        update_term_meta( $termId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
86 86
     }
87 87
 
88 88
     /**
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function updateAll()
92 92
     {
93
-        glsr(SqlQueries::class)->deleteTermCountMetaKeys();
94
-        $terms = glsr(Database::class)->getTerms([
93
+        glsr( SqlQueries::class )->deleteTermCountMetaKeys();
94
+        $terms = glsr( Database::class )->getTerms( [
95 95
             'fields' => 'all',
96
-        ]);
97
-        foreach ($terms as $term) {
98
-            $this->update($term->term_id, $this->build($term->term_taxonomy_id));
96
+        ] );
97
+        foreach( $terms as $term ) {
98
+            $this->update( $term->term_id, $this->build( $term->term_taxonomy_id ) );
99 99
         }
100 100
     }
101 101
 }
Please login to merge, or discard this patch.
plugin/Database/PostCountsManager.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -7,85 +7,85 @@
 block discarded – undo
7 7
 
8 8
 class PostCountsManager
9 9
 {
10
-    /**
11
-     * @var CountsManager
12
-     */
13
-    protected $manager;
10
+	/**
11
+	 * @var CountsManager
12
+	 */
13
+	protected $manager;
14 14
 
15
-    public function __construct()
16
-    {
17
-        $this->manager = glsr(CountsManager::class);
18
-    }
15
+	public function __construct()
16
+	{
17
+		$this->manager = glsr(CountsManager::class);
18
+	}
19 19
 
20
-    /**
21
-     * @param int $postId
22
-     * @return array
23
-     */
24
-    public function build($postId)
25
-    {
26
-        return $this->manager->buildCounts([
27
-            'post_ids' => [$postId],
28
-        ]);
29
-    }
20
+	/**
21
+	 * @param int $postId
22
+	 * @return array
23
+	 */
24
+	public function build($postId)
25
+	{
26
+		return $this->manager->buildCounts([
27
+			'post_ids' => [$postId],
28
+		]);
29
+	}
30 30
 
31
-    /**
32
-     * @return void
33
-     */
34
-    public function decrease(Review $review)
35
-    {
36
-        if (empty($counts = $this->get($review->assigned_to))) {
37
-            return;
38
-        }
39
-        $this->update($review->assigned_to,
40
-            $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
41
-        );
42
-    }
31
+	/**
32
+	 * @return void
33
+	 */
34
+	public function decrease(Review $review)
35
+	{
36
+		if (empty($counts = $this->get($review->assigned_to))) {
37
+			return;
38
+		}
39
+		$this->update($review->assigned_to,
40
+			$this->manager->decreaseRating($counts, $review->review_type, $review->rating)
41
+		);
42
+	}
43 43
 
44
-    /**
45
-     * @param int $postId
46
-     * @return array
47
-     */
48
-    public function get($postId)
49
-    {
50
-        return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true));
51
-    }
44
+	/**
45
+	 * @param int $postId
46
+	 * @return array
47
+	 */
48
+	public function get($postId)
49
+	{
50
+		return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true));
51
+	}
52 52
 
53
-    /**
54
-     * @return void
55
-     */
56
-    public function increase(Review $review)
57
-    {
58
-        if (!(get_post($review->assigned_to) instanceof \WP_Post)) {
59
-            return;
60
-        }
61
-        $counts = $this->get($review->assigned_to);
62
-        $counts = empty($counts)
63
-            ? $this->build($review->assigned_to)
64
-            : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
65
-        $this->update($review->assigned_to, $counts);
66
-    }
53
+	/**
54
+	 * @return void
55
+	 */
56
+	public function increase(Review $review)
57
+	{
58
+		if (!(get_post($review->assigned_to) instanceof \WP_Post)) {
59
+			return;
60
+		}
61
+		$counts = $this->get($review->assigned_to);
62
+		$counts = empty($counts)
63
+			? $this->build($review->assigned_to)
64
+			: $this->manager->increaseRating($counts, $review->review_type, $review->rating);
65
+		$this->update($review->assigned_to, $counts);
66
+	}
67 67
 
68
-    /**
69
-     * @param int $postId
70
-     * @return void
71
-     */
72
-    public function update($postId, array $reviewCounts)
73
-    {
74
-        $ratingCounts = $this->manager->flatten($reviewCounts);
75
-        update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts);
76
-        update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
77
-        update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
78
-    }
68
+	/**
69
+	 * @param int $postId
70
+	 * @return void
71
+	 */
72
+	public function update($postId, array $reviewCounts)
73
+	{
74
+		$ratingCounts = $this->manager->flatten($reviewCounts);
75
+		update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts);
76
+		update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
77
+		update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
78
+	}
79 79
 
80
-    /**
81
-     * @return void
82
-     */
83
-    public function updateAll()
84
-    {
85
-        glsr(SqlQueries::class)->deletePostCountMetaKeys();
86
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
87
-        foreach ($postIds as $postId) {
88
-            $this->update($postId, $this->build($postId));
89
-        }
90
-    }
80
+	/**
81
+	 * @return void
82
+	 */
83
+	public function updateAll()
84
+	{
85
+		glsr(SqlQueries::class)->deletePostCountMetaKeys();
86
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
87
+		foreach ($postIds as $postId) {
88
+			$this->update($postId, $this->build($postId));
89
+		}
90
+	}
91 91
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 
15 15
     public function __construct()
16 16
     {
17
-        $this->manager = glsr(CountsManager::class);
17
+        $this->manager = glsr( CountsManager::class );
18 18
     }
19 19
 
20 20
     /**
21 21
      * @param int $postId
22 22
      * @return array
23 23
      */
24
-    public function build($postId)
24
+    public function build( $postId )
25 25
     {
26
-        return $this->manager->buildCounts([
26
+        return $this->manager->buildCounts( [
27 27
             'post_ids' => [$postId],
28
-        ]);
28
+        ] );
29 29
     }
30 30
 
31 31
     /**
32 32
      * @return void
33 33
      */
34
-    public function decrease(Review $review)
34
+    public function decrease( Review $review )
35 35
     {
36
-        if (empty($counts = $this->get($review->assigned_to))) {
36
+        if( empty($counts = $this->get( $review->assigned_to )) ) {
37 37
             return;
38 38
         }
39
-        $this->update($review->assigned_to,
40
-            $this->manager->decreaseRating($counts, $review->review_type, $review->rating)
39
+        $this->update( $review->assigned_to,
40
+            $this->manager->decreaseRating( $counts, $review->review_type, $review->rating )
41 41
         );
42 42
     }
43 43
 
@@ -45,36 +45,36 @@  discard block
 block discarded – undo
45 45
      * @param int $postId
46 46
      * @return array
47 47
      */
48
-    public function get($postId)
48
+    public function get( $postId )
49 49
     {
50
-        return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true));
50
+        return array_filter( (array)get_post_meta( $postId, CountsManager::META_COUNT, true ) );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @return void
55 55
      */
56
-    public function increase(Review $review)
56
+    public function increase( Review $review )
57 57
     {
58
-        if (!(get_post($review->assigned_to) instanceof \WP_Post)) {
58
+        if( !(get_post( $review->assigned_to ) instanceof \WP_Post) ) {
59 59
             return;
60 60
         }
61
-        $counts = $this->get($review->assigned_to);
61
+        $counts = $this->get( $review->assigned_to );
62 62
         $counts = empty($counts)
63
-            ? $this->build($review->assigned_to)
64
-            : $this->manager->increaseRating($counts, $review->review_type, $review->rating);
65
-        $this->update($review->assigned_to, $counts);
63
+            ? $this->build( $review->assigned_to )
64
+            : $this->manager->increaseRating( $counts, $review->review_type, $review->rating );
65
+        $this->update( $review->assigned_to, $counts );
66 66
     }
67 67
 
68 68
     /**
69 69
      * @param int $postId
70 70
      * @return void
71 71
      */
72
-    public function update($postId, array $reviewCounts)
72
+    public function update( $postId, array $reviewCounts )
73 73
     {
74
-        $ratingCounts = $this->manager->flatten($reviewCounts);
75
-        update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts);
76
-        update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
77
-        update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
74
+        $ratingCounts = $this->manager->flatten( $reviewCounts );
75
+        update_post_meta( $postId, CountsManager::META_COUNT, $reviewCounts );
76
+        update_post_meta( $postId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
77
+        update_post_meta( $postId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
78 78
     }
79 79
 
80 80
     /**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function updateAll()
84 84
     {
85
-        glsr(SqlQueries::class)->deletePostCountMetaKeys();
86
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
87
-        foreach ($postIds as $postId) {
88
-            $this->update($postId, $this->build($postId));
85
+        glsr( SqlQueries::class )->deletePostCountMetaKeys();
86
+        $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' );
87
+        foreach( $postIds as $postId ) {
88
+            $this->update( $postId, $this->build( $postId ) );
89 89
         }
90 90
     }
91 91
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/SiteReviewsFormShortcode.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@
 block discarded – undo
4 4
 
5 5
 class SiteReviewsFormShortcode extends Shortcode
6 6
 {
7
-    protected function hideOptions()
8
-    {
9
-        return [
10
-            'rating' => __('Hide the rating field', 'site-reviews'),
11
-            'title' => __('Hide the title field', 'site-reviews'),
12
-            'content' => __('Hide the review field', 'site-reviews'),
13
-            'name' => __('Hide the name field', 'site-reviews'),
14
-            'email' => __('Hide the email field', 'site-reviews'),
15
-            'terms' => __('Hide the terms field', 'site-reviews'),
16
-        ];
17
-    }
7
+	protected function hideOptions()
8
+	{
9
+		return [
10
+			'rating' => __('Hide the rating field', 'site-reviews'),
11
+			'title' => __('Hide the title field', 'site-reviews'),
12
+			'content' => __('Hide the review field', 'site-reviews'),
13
+			'name' => __('Hide the name field', 'site-reviews'),
14
+			'email' => __('Hide the email field', 'site-reviews'),
15
+			'terms' => __('Hide the terms field', 'site-reviews'),
16
+		];
17
+	}
18 18
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@
 block discarded – undo
7 7
     protected function hideOptions()
8 8
     {
9 9
         return [
10
-            'rating' => __('Hide the rating field', 'site-reviews'),
11
-            'title' => __('Hide the title field', 'site-reviews'),
12
-            'content' => __('Hide the review field', 'site-reviews'),
13
-            'name' => __('Hide the name field', 'site-reviews'),
14
-            'email' => __('Hide the email field', 'site-reviews'),
15
-            'terms' => __('Hide the terms field', 'site-reviews'),
10
+            'rating' => __( 'Hide the rating field', 'site-reviews' ),
11
+            'title' => __( 'Hide the title field', 'site-reviews' ),
12
+            'content' => __( 'Hide the review field', 'site-reviews' ),
13
+            'name' => __( 'Hide the name field', 'site-reviews' ),
14
+            'email' => __( 'Hide the email field', 'site-reviews' ),
15
+            'terms' => __( 'Hide the terms field', 'site-reviews' ),
16 16
         ];
17 17
     }
18 18
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/Shortcode.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -12,238 +12,238 @@
 block discarded – undo
12 12
 
13 13
 abstract class Shortcode implements ShortcodeContract
14 14
 {
15
-    /**
16
-     * @var string
17
-     */
18
-    protected $partialName;
19
-
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $shortcodeName;
24
-
25
-    public function __construct()
26
-    {
27
-        $this->partialName = $this->getShortcodePartialName();
28
-        $this->shortcodeName = $this->getShortcodeName();
29
-    }
30
-
31
-    /**
32
-     * @param string|array $atts
33
-     * @param string $type
34
-     * @return string
35
-     */
36
-    public function build($atts, array $args = [], $type = 'shortcode')
37
-    {
38
-        $args = $this->normalizeArgs($args, $type);
39
-        $atts = $this->normalizeAtts($atts, $type);
40
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
41
-        $title = !empty($atts['title'])
42
-            ? $args['before_title'].$atts['title'].$args['after_title']
43
-            : '';
44
-        $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
45
-        return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
46
-    }
47
-
48
-    /**
49
-     * @param string|array $atts
50
-     * @return string
51
-     */
52
-    public function buildShortcode($atts = [])
53
-    {
54
-        return $this->build($atts);
55
-    }
56
-
57
-    /**
58
-     * @return array
59
-     */
60
-    public function getDefaults($atts)
61
-    {
62
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
63
-    }
64
-
65
-    /**
66
-     * @return array
67
-     */
68
-    public function getHideOptions()
69
-    {
70
-        $options = $this->hideOptions();
71
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
72
-    }
73
-
74
-    /**
75
-     * @return string
76
-     */
77
-    public function getShortcodeClassName($replace = '', $search = 'Shortcode')
78
-    {
79
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
80
-    }
81
-
82
-    /**
83
-     * @return string
84
-     */
85
-    public function getShortcodeDefaultsClassName()
86
-    {
87
-        return Helper::buildClassName(
88
-            $this->getShortcodeClassName('Defaults'),
89
-            'Defaults'
90
-        );
91
-    }
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function getShortcodeName()
97
-    {
98
-        return Str::snakeCase($this->getShortcodeClassName());
99
-    }
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getShortcodePartialName()
105
-    {
106
-        return Str::dashCase($this->getShortcodeClassName());
107
-    }
108
-
109
-    /**
110
-     * @param array|string $args
111
-     * @param string $type
112
-     * @return array
113
-     */
114
-    public function normalizeArgs($args, $type = 'shortcode')
115
-    {
116
-        $args = wp_parse_args($args, [
117
-            'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
118
-            'after_widget' => '</div>',
119
-            'before_title' => '<h3 class="glsr-'.$type.'-title">',
120
-            'after_title' => '</h3>',
121
-        ]);
122
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
123
-    }
124
-
125
-    /**
126
-     * @param array|string $atts
127
-     * @param string $type
128
-     * @return array
129
-     */
130
-    public function normalizeAtts($atts, $type = 'shortcode')
131
-    {
132
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
133
-        $atts = $this->getDefaults($atts);
134
-        array_walk($atts, function (&$value, $key) {
135
-            $methodName = Helper::buildMethodName($key, 'normalize');
136
-            if (!method_exists($this, $methodName)) {
137
-                return;
138
-            }
139
-            $value = $this->$methodName($value);
140
-        });
141
-        $this->setId($atts);
142
-        return $atts;
143
-    }
144
-
145
-    /**
146
-     * @return array
147
-     */
148
-    abstract protected function hideOptions();
149
-
150
-    /**
151
-     * @param string $postId
152
-     * @return int|string
153
-     */
154
-    protected function normalizeAssignedTo($postId)
155
-    {
156
-        if ('parent_id' == $postId) {
157
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
158
-        } elseif ('post_id' == $postId) {
159
-            $postId = intval(get_the_ID());
160
-        }
161
-        return $postId;
162
-    }
163
-
164
-    /**
165
-     * @param string $postId
166
-     * @return int|string
167
-     */
168
-    protected function normalizeAssignTo($postId)
169
-    {
170
-        return $this->normalizeAssignedTo($postId);
171
-    }
172
-
173
-    /**
174
-     * @param string|array $hide
175
-     * @return array
176
-     */
177
-    protected function normalizeHide($hide)
178
-    {
179
-        if (is_string($hide)) {
180
-            $hide = explode(',', $hide);
181
-        }
182
-        $hideKeys = array_keys($this->getHideOptions());
183
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
184
-            return in_array($value, $hideKeys);
185
-        });
186
-    }
187
-
188
-    /**
189
-     * @param string $id
190
-     * @return string
191
-     */
192
-    protected function normalizeId($id)
193
-    {
194
-        return sanitize_title($id);
195
-    }
196
-
197
-    /**
198
-     * @param string $labels
199
-     * @return array
200
-     */
201
-    protected function normalizeLabels($labels)
202
-    {
203
-        $defaults = [
204
-            __('Excellent', 'site-reviews'),
205
-            __('Very good', 'site-reviews'),
206
-            __('Average', 'site-reviews'),
207
-            __('Poor', 'site-reviews'),
208
-            __('Terrible', 'site-reviews'),
209
-        ];
210
-        $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
211
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
212
-        $labels = array_map('trim', explode(',', $labels));
213
-        foreach ($defaults as $i => $label) {
214
-            if (empty($labels[$i])) {
215
-                continue;
216
-            }
217
-            $defaults[$i] = $labels[$i];
218
-        }
219
-        return array_combine(range($maxRating, 1), $defaults);
220
-    }
221
-
222
-    /**
223
-     * @param string $schema
224
-     * @return bool
225
-     */
226
-    protected function normalizeSchema($schema)
227
-    {
228
-        return wp_validate_boolean($schema);
229
-    }
230
-
231
-    /**
232
-     * @param string $text
233
-     * @return string
234
-     */
235
-    protected function normalizeText($text)
236
-    {
237
-        return trim($text);
238
-    }
239
-
240
-    /**
241
-     * @return void
242
-     */
243
-    protected function setId(array &$atts)
244
-    {
245
-        if (empty($atts['id'])) {
246
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
247
-        }
248
-    }
15
+	/**
16
+	 * @var string
17
+	 */
18
+	protected $partialName;
19
+
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $shortcodeName;
24
+
25
+	public function __construct()
26
+	{
27
+		$this->partialName = $this->getShortcodePartialName();
28
+		$this->shortcodeName = $this->getShortcodeName();
29
+	}
30
+
31
+	/**
32
+	 * @param string|array $atts
33
+	 * @param string $type
34
+	 * @return string
35
+	 */
36
+	public function build($atts, array $args = [], $type = 'shortcode')
37
+	{
38
+		$args = $this->normalizeArgs($args, $type);
39
+		$atts = $this->normalizeAtts($atts, $type);
40
+		$partial = glsr(Partial::class)->build($this->partialName, $atts);
41
+		$title = !empty($atts['title'])
42
+			? $args['before_title'].$atts['title'].$args['after_title']
43
+			: '';
44
+		$debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
45
+		return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
46
+	}
47
+
48
+	/**
49
+	 * @param string|array $atts
50
+	 * @return string
51
+	 */
52
+	public function buildShortcode($atts = [])
53
+	{
54
+		return $this->build($atts);
55
+	}
56
+
57
+	/**
58
+	 * @return array
59
+	 */
60
+	public function getDefaults($atts)
61
+	{
62
+		return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
63
+	}
64
+
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function getHideOptions()
69
+	{
70
+		$options = $this->hideOptions();
71
+		return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
72
+	}
73
+
74
+	/**
75
+	 * @return string
76
+	 */
77
+	public function getShortcodeClassName($replace = '', $search = 'Shortcode')
78
+	{
79
+		return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
80
+	}
81
+
82
+	/**
83
+	 * @return string
84
+	 */
85
+	public function getShortcodeDefaultsClassName()
86
+	{
87
+		return Helper::buildClassName(
88
+			$this->getShortcodeClassName('Defaults'),
89
+			'Defaults'
90
+		);
91
+	}
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function getShortcodeName()
97
+	{
98
+		return Str::snakeCase($this->getShortcodeClassName());
99
+	}
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getShortcodePartialName()
105
+	{
106
+		return Str::dashCase($this->getShortcodeClassName());
107
+	}
108
+
109
+	/**
110
+	 * @param array|string $args
111
+	 * @param string $type
112
+	 * @return array
113
+	 */
114
+	public function normalizeArgs($args, $type = 'shortcode')
115
+	{
116
+		$args = wp_parse_args($args, [
117
+			'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
118
+			'after_widget' => '</div>',
119
+			'before_title' => '<h3 class="glsr-'.$type.'-title">',
120
+			'after_title' => '</h3>',
121
+		]);
122
+		return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
123
+	}
124
+
125
+	/**
126
+	 * @param array|string $atts
127
+	 * @param string $type
128
+	 * @return array
129
+	 */
130
+	public function normalizeAtts($atts, $type = 'shortcode')
131
+	{
132
+		$atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
133
+		$atts = $this->getDefaults($atts);
134
+		array_walk($atts, function (&$value, $key) {
135
+			$methodName = Helper::buildMethodName($key, 'normalize');
136
+			if (!method_exists($this, $methodName)) {
137
+				return;
138
+			}
139
+			$value = $this->$methodName($value);
140
+		});
141
+		$this->setId($atts);
142
+		return $atts;
143
+	}
144
+
145
+	/**
146
+	 * @return array
147
+	 */
148
+	abstract protected function hideOptions();
149
+
150
+	/**
151
+	 * @param string $postId
152
+	 * @return int|string
153
+	 */
154
+	protected function normalizeAssignedTo($postId)
155
+	{
156
+		if ('parent_id' == $postId) {
157
+			$postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
158
+		} elseif ('post_id' == $postId) {
159
+			$postId = intval(get_the_ID());
160
+		}
161
+		return $postId;
162
+	}
163
+
164
+	/**
165
+	 * @param string $postId
166
+	 * @return int|string
167
+	 */
168
+	protected function normalizeAssignTo($postId)
169
+	{
170
+		return $this->normalizeAssignedTo($postId);
171
+	}
172
+
173
+	/**
174
+	 * @param string|array $hide
175
+	 * @return array
176
+	 */
177
+	protected function normalizeHide($hide)
178
+	{
179
+		if (is_string($hide)) {
180
+			$hide = explode(',', $hide);
181
+		}
182
+		$hideKeys = array_keys($this->getHideOptions());
183
+		return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
184
+			return in_array($value, $hideKeys);
185
+		});
186
+	}
187
+
188
+	/**
189
+	 * @param string $id
190
+	 * @return string
191
+	 */
192
+	protected function normalizeId($id)
193
+	{
194
+		return sanitize_title($id);
195
+	}
196
+
197
+	/**
198
+	 * @param string $labels
199
+	 * @return array
200
+	 */
201
+	protected function normalizeLabels($labels)
202
+	{
203
+		$defaults = [
204
+			__('Excellent', 'site-reviews'),
205
+			__('Very good', 'site-reviews'),
206
+			__('Average', 'site-reviews'),
207
+			__('Poor', 'site-reviews'),
208
+			__('Terrible', 'site-reviews'),
209
+		];
210
+		$maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
211
+		$defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
212
+		$labels = array_map('trim', explode(',', $labels));
213
+		foreach ($defaults as $i => $label) {
214
+			if (empty($labels[$i])) {
215
+				continue;
216
+			}
217
+			$defaults[$i] = $labels[$i];
218
+		}
219
+		return array_combine(range($maxRating, 1), $defaults);
220
+	}
221
+
222
+	/**
223
+	 * @param string $schema
224
+	 * @return bool
225
+	 */
226
+	protected function normalizeSchema($schema)
227
+	{
228
+		return wp_validate_boolean($schema);
229
+	}
230
+
231
+	/**
232
+	 * @param string $text
233
+	 * @return string
234
+	 */
235
+	protected function normalizeText($text)
236
+	{
237
+		return trim($text);
238
+	}
239
+
240
+	/**
241
+	 * @return void
242
+	 */
243
+	protected function setId(array &$atts)
244
+	{
245
+		if (empty($atts['id'])) {
246
+			$atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
247
+		}
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -33,15 +33,15 @@  discard block
 block discarded – undo
33 33
      * @param string $type
34 34
      * @return string
35 35
      */
36
-    public function build($atts, array $args = [], $type = 'shortcode')
36
+    public function build( $atts, array $args = [], $type = 'shortcode' )
37 37
     {
38
-        $args = $this->normalizeArgs($args, $type);
39
-        $atts = $this->normalizeAtts($atts, $type);
40
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
38
+        $args = $this->normalizeArgs( $args, $type );
39
+        $atts = $this->normalizeAtts( $atts, $type );
40
+        $partial = glsr( Partial::class )->build( $this->partialName, $atts );
41 41
         $title = !empty($atts['title'])
42 42
             ? $args['before_title'].$atts['title'].$args['after_title']
43 43
             : '';
44
-        $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
44
+        $debug = sprintf( '<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json'] );
45 45
         return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
46 46
     }
47 47
 
@@ -49,17 +49,17 @@  discard block
 block discarded – undo
49 49
      * @param string|array $atts
50 50
      * @return string
51 51
      */
52
-    public function buildShortcode($atts = [])
52
+    public function buildShortcode( $atts = [] )
53 53
     {
54
-        return $this->build($atts);
54
+        return $this->build( $atts );
55 55
     }
56 56
 
57 57
     /**
58 58
      * @return array
59 59
      */
60
-    public function getDefaults($atts)
60
+    public function getDefaults( $atts )
61 61
     {
62
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
62
+        return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) );
63 63
     }
64 64
 
65 65
     /**
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
     public function getHideOptions()
69 69
     {
70 70
         $options = $this->hideOptions();
71
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
71
+        return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName );
72 72
     }
73 73
 
74 74
     /**
75 75
      * @return string
76 76
      */
77
-    public function getShortcodeClassName($replace = '', $search = 'Shortcode')
77
+    public function getShortcodeClassName( $replace = '', $search = 'Shortcode' )
78 78
     {
79
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
79
+        return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() );
80 80
     }
81 81
 
82 82
     /**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     public function getShortcodeDefaultsClassName()
86 86
     {
87 87
         return Helper::buildClassName(
88
-            $this->getShortcodeClassName('Defaults'),
88
+            $this->getShortcodeClassName( 'Defaults' ),
89 89
             'Defaults'
90 90
         );
91 91
     }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     public function getShortcodeName()
97 97
     {
98
-        return Str::snakeCase($this->getShortcodeClassName());
98
+        return Str::snakeCase( $this->getShortcodeClassName() );
99 99
     }
100 100
 
101 101
     /**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function getShortcodePartialName()
105 105
     {
106
-        return Str::dashCase($this->getShortcodeClassName());
106
+        return Str::dashCase( $this->getShortcodeClassName() );
107 107
     }
108 108
 
109 109
     /**
@@ -111,15 +111,15 @@  discard block
 block discarded – undo
111 111
      * @param string $type
112 112
      * @return array
113 113
      */
114
-    public function normalizeArgs($args, $type = 'shortcode')
114
+    public function normalizeArgs( $args, $type = 'shortcode' )
115 115
     {
116
-        $args = wp_parse_args($args, [
116
+        $args = wp_parse_args( $args, [
117 117
             'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
118 118
             'after_widget' => '</div>',
119 119
             'before_title' => '<h3 class="glsr-'.$type.'-title">',
120 120
             'after_title' => '</h3>',
121
-        ]);
122
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
121
+        ] );
122
+        return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName );
123 123
     }
124 124
 
125 125
     /**
@@ -127,18 +127,18 @@  discard block
 block discarded – undo
127 127
      * @param string $type
128 128
      * @return array
129 129
      */
130
-    public function normalizeAtts($atts, $type = 'shortcode')
130
+    public function normalizeAtts( $atts, $type = 'shortcode' )
131 131
     {
132
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
133
-        $atts = $this->getDefaults($atts);
134
-        array_walk($atts, function (&$value, $key) {
135
-            $methodName = Helper::buildMethodName($key, 'normalize');
136
-            if (!method_exists($this, $methodName)) {
132
+        $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName );
133
+        $atts = $this->getDefaults( $atts );
134
+        array_walk( $atts, function( &$value, $key ) {
135
+            $methodName = Helper::buildMethodName( $key, 'normalize' );
136
+            if( !method_exists( $this, $methodName ) ) {
137 137
                 return;
138 138
             }
139
-            $value = $this->$methodName($value);
139
+            $value = $this->$methodName( $value );
140 140
         });
141
-        $this->setId($atts);
141
+        $this->setId( $atts );
142 142
         return $atts;
143 143
     }
144 144
 
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
      * @param string $postId
152 152
      * @return int|string
153 153
      */
154
-    protected function normalizeAssignedTo($postId)
154
+    protected function normalizeAssignedTo( $postId )
155 155
     {
156
-        if ('parent_id' == $postId) {
157
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
158
-        } elseif ('post_id' == $postId) {
159
-            $postId = intval(get_the_ID());
156
+        if( 'parent_id' == $postId ) {
157
+            $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) );
158
+        } elseif( 'post_id' == $postId ) {
159
+            $postId = intval( get_the_ID() );
160 160
         }
161 161
         return $postId;
162 162
     }
@@ -165,23 +165,23 @@  discard block
 block discarded – undo
165 165
      * @param string $postId
166 166
      * @return int|string
167 167
      */
168
-    protected function normalizeAssignTo($postId)
168
+    protected function normalizeAssignTo( $postId )
169 169
     {
170
-        return $this->normalizeAssignedTo($postId);
170
+        return $this->normalizeAssignedTo( $postId );
171 171
     }
172 172
 
173 173
     /**
174 174
      * @param string|array $hide
175 175
      * @return array
176 176
      */
177
-    protected function normalizeHide($hide)
177
+    protected function normalizeHide( $hide )
178 178
     {
179
-        if (is_string($hide)) {
180
-            $hide = explode(',', $hide);
179
+        if( is_string( $hide ) ) {
180
+            $hide = explode( ',', $hide );
181 181
         }
182
-        $hideKeys = array_keys($this->getHideOptions());
183
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
184
-            return in_array($value, $hideKeys);
182
+        $hideKeys = array_keys( $this->getHideOptions() );
183
+        return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) {
184
+            return in_array( $value, $hideKeys );
185 185
         });
186 186
     }
187 187
 
@@ -189,61 +189,61 @@  discard block
 block discarded – undo
189 189
      * @param string $id
190 190
      * @return string
191 191
      */
192
-    protected function normalizeId($id)
192
+    protected function normalizeId( $id )
193 193
     {
194
-        return sanitize_title($id);
194
+        return sanitize_title( $id );
195 195
     }
196 196
 
197 197
     /**
198 198
      * @param string $labels
199 199
      * @return array
200 200
      */
201
-    protected function normalizeLabels($labels)
201
+    protected function normalizeLabels( $labels )
202 202
     {
203 203
         $defaults = [
204
-            __('Excellent', 'site-reviews'),
205
-            __('Very good', 'site-reviews'),
206
-            __('Average', 'site-reviews'),
207
-            __('Poor', 'site-reviews'),
208
-            __('Terrible', 'site-reviews'),
204
+            __( 'Excellent', 'site-reviews' ),
205
+            __( 'Very good', 'site-reviews' ),
206
+            __( 'Average', 'site-reviews' ),
207
+            __( 'Poor', 'site-reviews' ),
208
+            __( 'Terrible', 'site-reviews' ),
209 209
         ];
210
-        $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
211
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
212
-        $labels = array_map('trim', explode(',', $labels));
213
-        foreach ($defaults as $i => $label) {
214
-            if (empty($labels[$i])) {
210
+        $maxRating = (int)glsr()->constant( 'MAX_RATING', Rating::class );
211
+        $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' );
212
+        $labels = array_map( 'trim', explode( ',', $labels ) );
213
+        foreach( $defaults as $i => $label ) {
214
+            if( empty($labels[$i]) ) {
215 215
                 continue;
216 216
             }
217 217
             $defaults[$i] = $labels[$i];
218 218
         }
219
-        return array_combine(range($maxRating, 1), $defaults);
219
+        return array_combine( range( $maxRating, 1 ), $defaults );
220 220
     }
221 221
 
222 222
     /**
223 223
      * @param string $schema
224 224
      * @return bool
225 225
      */
226
-    protected function normalizeSchema($schema)
226
+    protected function normalizeSchema( $schema )
227 227
     {
228
-        return wp_validate_boolean($schema);
228
+        return wp_validate_boolean( $schema );
229 229
     }
230 230
 
231 231
     /**
232 232
      * @param string $text
233 233
      * @return string
234 234
      */
235
-    protected function normalizeText($text)
235
+    protected function normalizeText( $text )
236 236
     {
237
-        return trim($text);
237
+        return trim( $text );
238 238
     }
239 239
 
240 240
     /**
241 241
      * @return void
242 242
      */
243
-    protected function setId(array &$atts)
243
+    protected function setId( array &$atts )
244 244
     {
245
-        if (empty($atts['id'])) {
246
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
245
+        if( empty($atts['id']) ) {
246
+            $atts['id'] = Application::PREFIX.substr( md5( serialize( $atts ) ), 0, 8 );
247 247
         }
248 248
     }
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsSummary.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -10,197 +10,197 @@
 block discarded – undo
10 10
 
11 11
 class SiteReviewsSummary
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $args;
17
-
18
-    /**
19
-     * @var float
20
-     */
21
-    protected $averageRating;
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $ratingCounts;
27
-
28
-    /**
29
-     * @return void|string
30
-     */
31
-    public function build(array $args = [])
32
-    {
33
-        $this->args = $args;
34
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
35
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
36
-            return;
37
-        }
38
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
-        $this->generateSchema();
40
-        return glsr(Template::class)->build('templates/reviews-summary', [
41
-            'context' => [
42
-                'assigned_to' => $this->args['assigned_to'],
43
-                'category' => $this->args['category'],
44
-                'class' => $this->getClass(),
45
-                'id' => $this->args['id'],
46
-                'percentages' => $this->buildPercentage(),
47
-                'rating' => $this->buildRating(),
48
-                'stars' => $this->buildStars(),
49
-                'text' => $this->buildText(),
50
-            ],
51
-        ]);
52
-    }
53
-
54
-    /**
55
-     * @return void|string
56
-     */
57
-    protected function buildPercentage()
58
-    {
59
-        if ($this->isHidden('bars')) {
60
-            return;
61
-        }
62
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
63
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
64
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
65
-            $background = $this->buildPercentageBackground($percentages[$level]);
66
-            $count = apply_filters('site-reviews/summary/counts',
67
-                $percentages[$level],
68
-                $this->ratingCounts[$level]
69
-            );
70
-            $percent = $this->buildPercentageCount($count);
71
-            $value = $label.$background.$percent;
72
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
73
-                'percent' => wp_strip_all_tags($count, true),
74
-                'rating' => $level,
75
-            ]);
76
-            return $carry.glsr(Builder::class)->div($value, [
77
-                'class' => 'glsr-bar',
78
-            ]);
79
-        });
80
-        return $this->wrap('percentage', $bars);
81
-    }
82
-
83
-    /**
84
-     * @param string $percent
85
-     * @return string
86
-     */
87
-    protected function buildPercentageBackground($percent)
88
-    {
89
-        $backgroundPercent = glsr(Builder::class)->span([
90
-            'class' => 'glsr-bar-background-percent',
91
-            'style' => 'width:'.$percent,
92
-        ]);
93
-        return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
94
-    }
95
-
96
-    /**
97
-     * @param string $count
98
-     * @return string
99
-     */
100
-    protected function buildPercentageCount($count)
101
-    {
102
-        return '<span class="glsr-bar-percent">'.$count.'</span>';
103
-    }
104
-
105
-    /**
106
-     * @param string $label
107
-     * @return string
108
-     */
109
-    protected function buildPercentageLabel($label)
110
-    {
111
-        return '<span class="glsr-bar-label">'.$label.'</span>';
112
-    }
113
-
114
-    /**
115
-     * @return void|string
116
-     */
117
-    protected function buildRating()
118
-    {
119
-        if ($this->isHidden('rating')) {
120
-            return;
121
-        }
122
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
-    }
124
-
125
-    /**
126
-     * @return void|string
127
-     */
128
-    protected function buildStars()
129
-    {
130
-        if ($this->isHidden('stars')) {
131
-            return;
132
-        }
133
-        $stars = glsr_star_rating($this->averageRating);
134
-        return $this->wrap('stars', $stars);
135
-    }
136
-
137
-    /**
138
-     * @return void|string
139
-     */
140
-    protected function buildText()
141
-    {
142
-        if ($this->isHidden('summary')) {
143
-            return;
144
-        }
145
-        $count = intval(array_sum($this->ratingCounts));
146
-        if (empty($this->args['text'])) {
147
-            // @todo document this change
148
-            $this->args['text'] = _nx(
149
-                '{rating} out of {max} stars (based on {num} review)',
150
-                '{rating} out of {max} stars (based on {num} reviews)',
151
-                $count,
152
-                'Do not translate {rating}, {max}, and {num}, they are template tags.',
153
-                'site-reviews'
154
-            );
155
-        }
156
-        $summary = str_replace(
157
-            ['{rating}', '{max}', '{num}'],
158
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
-            $this->args['text']
160
-        );
161
-        return $this->wrap('text', '<span>'.$summary.'</span>');
162
-    }
163
-
164
-    /**
165
-     * @return void
166
-     */
167
-    protected function generateSchema()
168
-    {
169
-        if (!wp_validate_boolean($this->args['schema'])) {
170
-            return;
171
-        }
172
-        glsr(Schema::class)->store(
173
-            glsr(Schema::class)->buildSummary($this->args)
174
-        );
175
-    }
176
-
177
-    /**
178
-     * @return string
179
-     */
180
-    protected function getClass()
181
-    {
182
-        return trim('glsr-summary glsr-default '.$this->args['class']);
183
-    }
184
-
185
-    /**
186
-     * @param string $key
187
-     * @return bool
188
-     */
189
-    protected function isHidden($key)
190
-    {
191
-        return in_array($key, $this->args['hide']);
192
-    }
193
-
194
-    /**
195
-     * @param string $key
196
-     * @param string $value
197
-     * @return string
198
-     */
199
-    protected function wrap($key, $value)
200
-    {
201
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
202
-        return glsr(Builder::class)->div($value, [
203
-            'class' => 'glsr-summary-'.$key,
204
-        ]);
205
-    }
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $args;
17
+
18
+	/**
19
+	 * @var float
20
+	 */
21
+	protected $averageRating;
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $ratingCounts;
27
+
28
+	/**
29
+	 * @return void|string
30
+	 */
31
+	public function build(array $args = [])
32
+	{
33
+		$this->args = $args;
34
+		$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
35
+		if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
36
+			return;
37
+		}
38
+		$this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
+		$this->generateSchema();
40
+		return glsr(Template::class)->build('templates/reviews-summary', [
41
+			'context' => [
42
+				'assigned_to' => $this->args['assigned_to'],
43
+				'category' => $this->args['category'],
44
+				'class' => $this->getClass(),
45
+				'id' => $this->args['id'],
46
+				'percentages' => $this->buildPercentage(),
47
+				'rating' => $this->buildRating(),
48
+				'stars' => $this->buildStars(),
49
+				'text' => $this->buildText(),
50
+			],
51
+		]);
52
+	}
53
+
54
+	/**
55
+	 * @return void|string
56
+	 */
57
+	protected function buildPercentage()
58
+	{
59
+		if ($this->isHidden('bars')) {
60
+			return;
61
+		}
62
+		$percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
63
+		$bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
64
+			$label = $this->buildPercentageLabel($this->args['labels'][$level]);
65
+			$background = $this->buildPercentageBackground($percentages[$level]);
66
+			$count = apply_filters('site-reviews/summary/counts',
67
+				$percentages[$level],
68
+				$this->ratingCounts[$level]
69
+			);
70
+			$percent = $this->buildPercentageCount($count);
71
+			$value = $label.$background.$percent;
72
+			$value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
73
+				'percent' => wp_strip_all_tags($count, true),
74
+				'rating' => $level,
75
+			]);
76
+			return $carry.glsr(Builder::class)->div($value, [
77
+				'class' => 'glsr-bar',
78
+			]);
79
+		});
80
+		return $this->wrap('percentage', $bars);
81
+	}
82
+
83
+	/**
84
+	 * @param string $percent
85
+	 * @return string
86
+	 */
87
+	protected function buildPercentageBackground($percent)
88
+	{
89
+		$backgroundPercent = glsr(Builder::class)->span([
90
+			'class' => 'glsr-bar-background-percent',
91
+			'style' => 'width:'.$percent,
92
+		]);
93
+		return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
94
+	}
95
+
96
+	/**
97
+	 * @param string $count
98
+	 * @return string
99
+	 */
100
+	protected function buildPercentageCount($count)
101
+	{
102
+		return '<span class="glsr-bar-percent">'.$count.'</span>';
103
+	}
104
+
105
+	/**
106
+	 * @param string $label
107
+	 * @return string
108
+	 */
109
+	protected function buildPercentageLabel($label)
110
+	{
111
+		return '<span class="glsr-bar-label">'.$label.'</span>';
112
+	}
113
+
114
+	/**
115
+	 * @return void|string
116
+	 */
117
+	protected function buildRating()
118
+	{
119
+		if ($this->isHidden('rating')) {
120
+			return;
121
+		}
122
+		return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
+	}
124
+
125
+	/**
126
+	 * @return void|string
127
+	 */
128
+	protected function buildStars()
129
+	{
130
+		if ($this->isHidden('stars')) {
131
+			return;
132
+		}
133
+		$stars = glsr_star_rating($this->averageRating);
134
+		return $this->wrap('stars', $stars);
135
+	}
136
+
137
+	/**
138
+	 * @return void|string
139
+	 */
140
+	protected function buildText()
141
+	{
142
+		if ($this->isHidden('summary')) {
143
+			return;
144
+		}
145
+		$count = intval(array_sum($this->ratingCounts));
146
+		if (empty($this->args['text'])) {
147
+			// @todo document this change
148
+			$this->args['text'] = _nx(
149
+				'{rating} out of {max} stars (based on {num} review)',
150
+				'{rating} out of {max} stars (based on {num} reviews)',
151
+				$count,
152
+				'Do not translate {rating}, {max}, and {num}, they are template tags.',
153
+				'site-reviews'
154
+			);
155
+		}
156
+		$summary = str_replace(
157
+			['{rating}', '{max}', '{num}'],
158
+			[$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
+			$this->args['text']
160
+		);
161
+		return $this->wrap('text', '<span>'.$summary.'</span>');
162
+	}
163
+
164
+	/**
165
+	 * @return void
166
+	 */
167
+	protected function generateSchema()
168
+	{
169
+		if (!wp_validate_boolean($this->args['schema'])) {
170
+			return;
171
+		}
172
+		glsr(Schema::class)->store(
173
+			glsr(Schema::class)->buildSummary($this->args)
174
+		);
175
+	}
176
+
177
+	/**
178
+	 * @return string
179
+	 */
180
+	protected function getClass()
181
+	{
182
+		return trim('glsr-summary glsr-default '.$this->args['class']);
183
+	}
184
+
185
+	/**
186
+	 * @param string $key
187
+	 * @return bool
188
+	 */
189
+	protected function isHidden($key)
190
+	{
191
+		return in_array($key, $this->args['hide']);
192
+	}
193
+
194
+	/**
195
+	 * @param string $key
196
+	 * @param string $value
197
+	 * @return string
198
+	 */
199
+	protected function wrap($key, $value)
200
+	{
201
+		$value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
202
+		return glsr(Builder::class)->div($value, [
203
+			'class' => 'glsr-summary-'.$key,
204
+		]);
205
+	}
206 206
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
     /**
29 29
      * @return void|string
30 30
      */
31
-    public function build(array $args = [])
31
+    public function build( array $args = [] )
32 32
     {
33 33
         $this->args = $args;
34
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
35
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
34
+        $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args );
35
+        if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) {
36 36
             return;
37 37
         }
38
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
38
+        $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts );
39 39
         $this->generateSchema();
40
-        return glsr(Template::class)->build('templates/reviews-summary', [
40
+        return glsr( Template::class )->build( 'templates/reviews-summary', [
41 41
             'context' => [
42 42
                 'assigned_to' => $this->args['assigned_to'],
43 43
                 'category' => $this->args['category'],
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
                 'stars' => $this->buildStars(),
49 49
                 'text' => $this->buildText(),
50 50
             ],
51
-        ]);
51
+        ] );
52 52
     }
53 53
 
54 54
     /**
@@ -56,40 +56,40 @@  discard block
 block discarded – undo
56 56
      */
57 57
     protected function buildPercentage()
58 58
     {
59
-        if ($this->isHidden('bars')) {
59
+        if( $this->isHidden( 'bars' ) ) {
60 60
             return;
61 61
         }
62
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
63
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
64
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
65
-            $background = $this->buildPercentageBackground($percentages[$level]);
66
-            $count = apply_filters('site-reviews/summary/counts',
62
+        $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) );
63
+        $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) {
64
+            $label = $this->buildPercentageLabel( $this->args['labels'][$level] );
65
+            $background = $this->buildPercentageBackground( $percentages[$level] );
66
+            $count = apply_filters( 'site-reviews/summary/counts',
67 67
                 $percentages[$level],
68 68
                 $this->ratingCounts[$level]
69 69
             );
70
-            $percent = $this->buildPercentageCount($count);
70
+            $percent = $this->buildPercentageCount( $count );
71 71
             $value = $label.$background.$percent;
72
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
73
-                'percent' => wp_strip_all_tags($count, true),
72
+            $value = apply_filters( 'site-reviews/summary/wrap/bar', $value, $this->args, [
73
+                'percent' => wp_strip_all_tags( $count, true ),
74 74
                 'rating' => $level,
75
-            ]);
76
-            return $carry.glsr(Builder::class)->div($value, [
75
+            ] );
76
+            return $carry.glsr( Builder::class )->div( $value, [
77 77
                 'class' => 'glsr-bar',
78
-            ]);
78
+            ] );
79 79
         });
80
-        return $this->wrap('percentage', $bars);
80
+        return $this->wrap( 'percentage', $bars );
81 81
     }
82 82
 
83 83
     /**
84 84
      * @param string $percent
85 85
      * @return string
86 86
      */
87
-    protected function buildPercentageBackground($percent)
87
+    protected function buildPercentageBackground( $percent )
88 88
     {
89
-        $backgroundPercent = glsr(Builder::class)->span([
89
+        $backgroundPercent = glsr( Builder::class )->span( [
90 90
             'class' => 'glsr-bar-background-percent',
91 91
             'style' => 'width:'.$percent,
92
-        ]);
92
+        ] );
93 93
         return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
94 94
     }
95 95
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param string $count
98 98
      * @return string
99 99
      */
100
-    protected function buildPercentageCount($count)
100
+    protected function buildPercentageCount( $count )
101 101
     {
102 102
         return '<span class="glsr-bar-percent">'.$count.'</span>';
103 103
     }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      * @param string $label
107 107
      * @return string
108 108
      */
109
-    protected function buildPercentageLabel($label)
109
+    protected function buildPercentageLabel( $label )
110 110
     {
111 111
         return '<span class="glsr-bar-label">'.$label.'</span>';
112 112
     }
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
      */
117 117
     protected function buildRating()
118 118
     {
119
-        if ($this->isHidden('rating')) {
119
+        if( $this->isHidden( 'rating' ) ) {
120 120
             return;
121 121
         }
122
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
122
+        return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' );
123 123
     }
124 124
 
125 125
     /**
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
      */
128 128
     protected function buildStars()
129 129
     {
130
-        if ($this->isHidden('stars')) {
130
+        if( $this->isHidden( 'stars' ) ) {
131 131
             return;
132 132
         }
133
-        $stars = glsr_star_rating($this->averageRating);
134
-        return $this->wrap('stars', $stars);
133
+        $stars = glsr_star_rating( $this->averageRating );
134
+        return $this->wrap( 'stars', $stars );
135 135
     }
136 136
 
137 137
     /**
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function buildText()
141 141
     {
142
-        if ($this->isHidden('summary')) {
142
+        if( $this->isHidden( 'summary' ) ) {
143 143
             return;
144 144
         }
145
-        $count = intval(array_sum($this->ratingCounts));
146
-        if (empty($this->args['text'])) {
145
+        $count = intval( array_sum( $this->ratingCounts ) );
146
+        if( empty($this->args['text']) ) {
147 147
             // @todo document this change
148 148
             $this->args['text'] = _nx(
149 149
                 '{rating} out of {max} stars (based on {num} review)',
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
         }
156 156
         $summary = str_replace(
157 157
             ['{rating}', '{max}', '{num}'],
158
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
158
+            [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count],
159 159
             $this->args['text']
160 160
         );
161
-        return $this->wrap('text', '<span>'.$summary.'</span>');
161
+        return $this->wrap( 'text', '<span>'.$summary.'</span>' );
162 162
     }
163 163
 
164 164
     /**
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
      */
167 167
     protected function generateSchema()
168 168
     {
169
-        if (!wp_validate_boolean($this->args['schema'])) {
169
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
170 170
             return;
171 171
         }
172
-        glsr(Schema::class)->store(
173
-            glsr(Schema::class)->buildSummary($this->args)
172
+        glsr( Schema::class )->store(
173
+            glsr( Schema::class )->buildSummary( $this->args )
174 174
         );
175 175
     }
176 176
 
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
      */
180 180
     protected function getClass()
181 181
     {
182
-        return trim('glsr-summary glsr-default '.$this->args['class']);
182
+        return trim( 'glsr-summary glsr-default '.$this->args['class'] );
183 183
     }
184 184
 
185 185
     /**
186 186
      * @param string $key
187 187
      * @return bool
188 188
      */
189
-    protected function isHidden($key)
189
+    protected function isHidden( $key )
190 190
     {
191
-        return in_array($key, $this->args['hide']);
191
+        return in_array( $key, $this->args['hide'] );
192 192
     }
193 193
 
194 194
     /**
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
      * @param string $value
197 197
      * @return string
198 198
      */
199
-    protected function wrap($key, $value)
199
+    protected function wrap( $key, $value )
200 200
     {
201
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
202
-        return glsr(Builder::class)->div($value, [
201
+        $value = apply_filters( 'site-reviews/summary/wrap/'.$key, $value, $this->args );
202
+        return glsr( Builder::class )->div( $value, [
203 203
             'class' => 'glsr-summary-'.$key,
204
-        ]);
204
+        ] );
205 205
     }
206 206
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Template.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@
 block discarded – undo
7 7
 
8 8
 class Template
9 9
 {
10
-    /**
11
-     * @param string $templatePath
12
-     * @return void|string
13
-     */
14
-    public function build($templatePath, array $data = [])
15
-    {
16
-        $data = $this->normalize($data);
17
-        $path = Str::removePrefix('templates/', $templatePath);
18
-        $template = glsr()->build($templatePath, $data);
19
-        $template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
20
-        $template = $this->interpolate($template, $data, $path);
21
-        $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
22
-        $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
23
-        return $template;
24
-    }
10
+	/**
11
+	 * @param string $templatePath
12
+	 * @return void|string
13
+	 */
14
+	public function build($templatePath, array $data = [])
15
+	{
16
+		$data = $this->normalize($data);
17
+		$path = Str::removePrefix('templates/', $templatePath);
18
+		$template = glsr()->build($templatePath, $data);
19
+		$template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
20
+		$template = $this->interpolate($template, $data, $path);
21
+		$template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
22
+		$template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
23
+		return $template;
24
+	}
25 25
 
26
-    /**
27
-     * Interpolate context values into template placeholders.
28
-     * @param string $template
29
-     * @param string $templatePath
30
-     * @return string
31
-     */
32
-    public function interpolate($template, array $data = [], $templatePath)
33
-    {
34
-        $context = $this->normalizeContext(Arr::get($data, 'context', []));
35
-        $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
36
-        return $this->interpolateContext($template, $context);
37
-    }
26
+	/**
27
+	 * Interpolate context values into template placeholders.
28
+	 * @param string $template
29
+	 * @param string $templatePath
30
+	 * @return string
31
+	 */
32
+	public function interpolate($template, array $data = [], $templatePath)
33
+	{
34
+		$context = $this->normalizeContext(Arr::get($data, 'context', []));
35
+		$context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
36
+		return $this->interpolateContext($template, $context);
37
+	}
38 38
 
39
-    /**
40
-     * Interpolate context values into template placeholders.
41
-     * @param string $text
42
-     * @return string
43
-     */
44
-    public function interpolateContext($text, array $context = [])
45
-    {
46
-        foreach ($context as $key => $value) {
47
-            $text = strtr(
48
-                $text,
49
-                array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
50
-            );
51
-        }
52
-        return trim($text);
53
-    }
39
+	/**
40
+	 * Interpolate context values into template placeholders.
41
+	 * @param string $text
42
+	 * @return string
43
+	 */
44
+	public function interpolateContext($text, array $context = [])
45
+	{
46
+		foreach ($context as $key => $value) {
47
+			$text = strtr(
48
+				$text,
49
+				array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
50
+			);
51
+		}
52
+		return trim($text);
53
+	}
54 54
 
55
-    /**
56
-     * @param string $templatePath
57
-     * @return void|string
58
-     */
59
-    public function render($templatePath, array $data = [])
60
-    {
61
-        echo $this->build($templatePath, $data);
62
-    }
55
+	/**
56
+	 * @param string $templatePath
57
+	 * @return void|string
58
+	 */
59
+	public function render($templatePath, array $data = [])
60
+	{
61
+		echo $this->build($templatePath, $data);
62
+	}
63 63
 
64
-    /**
65
-     * @return array
66
-     */
67
-    protected function normalize(array $data)
68
-    {
69
-        $arrayKeys = ['context', 'globals'];
70
-        $data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
71
-        foreach ($arrayKeys as $key) {
72
-            if (is_array($data[$key])) {
73
-                continue;
74
-            }
75
-            $data[$key] = [];
76
-        }
77
-        return $data;
78
-    }
64
+	/**
65
+	 * @return array
66
+	 */
67
+	protected function normalize(array $data)
68
+	{
69
+		$arrayKeys = ['context', 'globals'];
70
+		$data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
71
+		foreach ($arrayKeys as $key) {
72
+			if (is_array($data[$key])) {
73
+				continue;
74
+			}
75
+			$data[$key] = [];
76
+		}
77
+		return $data;
78
+	}
79 79
 
80
-    /**
81
-     * @return array
82
-     */
83
-    protected function normalizeContext(array $context)
84
-    {
85
-        $context = array_filter($context, function ($value) {
86
-            return !is_array($value) && !is_object($value);
87
-        });
88
-        return array_map(function ($value) {
89
-            return (string) $value;
90
-        }, $context);
91
-    }
80
+	/**
81
+	 * @return array
82
+	 */
83
+	protected function normalizeContext(array $context)
84
+	{
85
+		$context = array_filter($context, function ($value) {
86
+			return !is_array($value) && !is_object($value);
87
+		});
88
+		return array_map(function ($value) {
89
+			return (string) $value;
90
+		}, $context);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
      * @param string $templatePath
12 12
      * @return void|string
13 13
      */
14
-    public function build($templatePath, array $data = [])
14
+    public function build( $templatePath, array $data = [] )
15 15
     {
16
-        $data = $this->normalize($data);
17
-        $path = Str::removePrefix('templates/', $templatePath);
18
-        $template = glsr()->build($templatePath, $data);
19
-        $template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
20
-        $template = $this->interpolate($template, $data, $path);
21
-        $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
22
-        $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
16
+        $data = $this->normalize( $data );
17
+        $path = Str::removePrefix( 'templates/', $templatePath );
18
+        $template = glsr()->build( $templatePath, $data );
19
+        $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data );
20
+        $template = $this->interpolate( $template, $data, $path );
21
+        $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data );
22
+        $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data );
23 23
         return $template;
24 24
     }
25 25
 
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
      * @param string $templatePath
30 30
      * @return string
31 31
      */
32
-    public function interpolate($template, array $data = [], $templatePath)
32
+    public function interpolate( $template, array $data = [], $templatePath )
33 33
     {
34
-        $context = $this->normalizeContext(Arr::get($data, 'context', []));
35
-        $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
36
-        return $this->interpolateContext($template, $context);
34
+        $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) );
35
+        $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data );
36
+        return $this->interpolateContext( $template, $context );
37 37
     }
38 38
 
39 39
     /**
@@ -41,35 +41,35 @@  discard block
 block discarded – undo
41 41
      * @param string $text
42 42
      * @return string
43 43
      */
44
-    public function interpolateContext($text, array $context = [])
44
+    public function interpolateContext( $text, array $context = [] )
45 45
     {
46
-        foreach ($context as $key => $value) {
46
+        foreach( $context as $key => $value ) {
47 47
             $text = strtr(
48 48
                 $text,
49
-                array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
49
+                array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value )
50 50
             );
51 51
         }
52
-        return trim($text);
52
+        return trim( $text );
53 53
     }
54 54
 
55 55
     /**
56 56
      * @param string $templatePath
57 57
      * @return void|string
58 58
      */
59
-    public function render($templatePath, array $data = [])
59
+    public function render( $templatePath, array $data = [] )
60 60
     {
61
-        echo $this->build($templatePath, $data);
61
+        echo $this->build( $templatePath, $data );
62 62
     }
63 63
 
64 64
     /**
65 65
      * @return array
66 66
      */
67
-    protected function normalize(array $data)
67
+    protected function normalize( array $data )
68 68
     {
69 69
         $arrayKeys = ['context', 'globals'];
70
-        $data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
71
-        foreach ($arrayKeys as $key) {
72
-            if (is_array($data[$key])) {
70
+        $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) );
71
+        foreach( $arrayKeys as $key ) {
72
+            if( is_array( $data[$key] ) ) {
73 73
                 continue;
74 74
             }
75 75
             $data[$key] = [];
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
     /**
81 81
      * @return array
82 82
      */
83
-    protected function normalizeContext(array $context)
83
+    protected function normalizeContext( array $context )
84 84
     {
85
-        $context = array_filter($context, function ($value) {
86
-            return !is_array($value) && !is_object($value);
85
+        $context = array_filter( $context, function( $value ) {
86
+            return !is_array( $value ) && !is_object( $value );
87 87
         });
88
-        return array_map(function ($value) {
89
-            return (string) $value;
90
-        }, $context);
88
+        return array_map( function( $value ) {
89
+            return (string)$value;
90
+        }, $context );
91 91
     }
92 92
 }
Please login to merge, or discard this patch.
plugin/Helpers/Arr.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -4,215 +4,215 @@
 block discarded – undo
4 4
 
5 5
 class Arr
6 6
 {
7
-    /**
8
-     * @return bool
9
-     */
10
-    public static function compareArrays(array $arr1, array $arr2)
11
-    {
12
-        sort($arr1);
13
-        sort($arr2);
14
-        return $arr1 == $arr2;
15
-    }
16
-
17
-    /**
18
-     * @param mixed $array
19
-     * @return array
20
-     */
21
-    public static function consolidateArray($array)
22
-    {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
25
-            : [];
26
-    }
27
-
28
-    /**
29
-     * @return array
30
-     */
31
-    public static function convertDotNotationArray(array $array)
32
-    {
33
-        $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
36
-        }
37
-        return $results;
38
-    }
39
-
40
-    /**
41
-     * @param string $string
42
-     * @param mixed $callback
43
-     * @return array
44
-     */
45
-    public static function convertStringToArray($string, $callback = null)
46
-    {
47
-        $array = array_map('trim', explode(',', $string));
48
-        return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
51
-    }
52
-
53
-    /**
54
-     * @param bool $flattenValue
55
-     * @param string $prefix
56
-     * @return array
57
-     */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
-    {
60
-        $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
66
-                }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
-                continue;
70
-            }
71
-            $result[$newKey] = $value;
72
-        }
73
-        return $result;
74
-    }
75
-
76
-    /**
77
-     * Get a value from an array of values using a dot-notation path as reference.
78
-     * @param mixed $data
79
-     * @param string $path
80
-     * @param mixed $fallback
81
-     * @return mixed
82
-     */
83
-    public static function get($data, $path = '', $fallback = '')
84
-    {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
89
-                return $fallback;
90
-            }
91
-            $data = $data[$key];
92
-        }
93
-        return $data;
94
-    }
95
-
96
-    /**
97
-     * @param string $key
98
-     * @return array
99
-     */
100
-    public static function insertAfter($key, array $array, array $insert)
101
-    {
102
-        return static::insertInArray($array, $insert, $key, 'after');
103
-    }
104
-
105
-    /**
106
-     * @param string $key
107
-     * @return array
108
-     */
109
-    public static function insertBefore($key, array $array, array $insert)
110
-    {
111
-        return static::insertInArray($array, $insert, $key, 'before');
112
-    }
113
-
114
-    /**
115
-     * @param string $key
116
-     * @param string $position
117
-     * @return array
118
-     */
119
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
120
-    {
121
-        $keyPosition = intval(array_search($key, array_keys($array)));
122
-        if ('after' == $position) {
123
-            ++$keyPosition;
124
-        }
125
-        if (false !== $keyPosition) {
126
-            $result = array_slice($array, 0, $keyPosition);
127
-            $result = array_merge($result, $insert);
128
-            return array_merge($result, array_slice($array, $keyPosition));
129
-        }
130
-        return array_merge($array, $insert);
131
-    }
132
-
133
-    /**
134
-     * @param mixed $array
135
-     * @return bool
136
-     */
137
-    public static function isIndexedFlatArray($array)
138
-    {
139
-        if (!is_array($array) || array_filter($array, 'is_array')) {
140
-            return false;
141
-        }
142
-        return wp_is_numeric_array($array);
143
-    }
144
-
145
-    /**
146
-     * @param bool $prefixed
147
-     * @return array
148
-     */
149
-    public static function prefixArrayKeys(array $values, $prefixed = true)
150
-    {
151
-        $trim = '_';
152
-        $prefix = $prefixed
153
-            ? $trim
154
-            : '';
155
-        $prefixed = [];
156
-        foreach ($values as $key => $value) {
157
-            $key = trim($key);
158
-            if (0 === strpos($key, $trim)) {
159
-                $key = substr($key, strlen($trim));
160
-            }
161
-            $prefixed[$prefix.$key] = $value;
162
-        }
163
-        return $prefixed;
164
-    }
165
-
166
-    /**
167
-     * @return array
168
-     */
169
-    public static function removeEmptyArrayValues(array $array)
170
-    {
171
-        $result = [];
172
-        foreach ($array as $key => $value) {
173
-            if (!$value) {
174
-                continue;
175
-            }
176
-            $result[$key] = is_array($value)
177
-                ? static::removeEmptyArrayValues($value)
178
-                : $value;
179
-        }
180
-        return $result;
181
-    }
182
-
183
-
184
-    /**
185
-     * Set a value to an array of values using a dot-notation path as reference.
186
-     * @param string $path
187
-     * @param mixed $value
188
-     * @return array
189
-     */
190
-    public static function set(array $data, $path, $value)
191
-    {
192
-        $token = strtok($path, '.');
193
-        $ref = &$data;
194
-        while (false !== $token) {
195
-            $ref = static::consolidateArray($ref);
196
-            $ref = &$ref[$token];
197
-            $token = strtok('.');
198
-        }
199
-        $ref = $value;
200
-        return $data;
201
-    }
202
-
203
-    /**
204
-     * @return array
205
-     */
206
-    public static function unique(array $values)
207
-    {
208
-        return array_filter(array_unique($values));
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    public static function unprefixArrayKeys(array $values)
215
-    {
216
-        return static::prefixArrayKeys($values, false);
217
-    }
7
+	/**
8
+	 * @return bool
9
+	 */
10
+	public static function compareArrays(array $arr1, array $arr2)
11
+	{
12
+		sort($arr1);
13
+		sort($arr2);
14
+		return $arr1 == $arr2;
15
+	}
16
+
17
+	/**
18
+	 * @param mixed $array
19
+	 * @return array
20
+	 */
21
+	public static function consolidateArray($array)
22
+	{
23
+		return is_array($array) || is_object($array)
24
+			? (array) $array
25
+			: [];
26
+	}
27
+
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public static function convertDotNotationArray(array $array)
32
+	{
33
+		$results = [];
34
+		foreach ($array as $path => $value) {
35
+			$results = static::set($results, $path, $value);
36
+		}
37
+		return $results;
38
+	}
39
+
40
+	/**
41
+	 * @param string $string
42
+	 * @param mixed $callback
43
+	 * @return array
44
+	 */
45
+	public static function convertStringToArray($string, $callback = null)
46
+	{
47
+		$array = array_map('trim', explode(',', $string));
48
+		return $callback
49
+			? array_filter($array, $callback)
50
+			: array_filter($array);
51
+	}
52
+
53
+	/**
54
+	 * @param bool $flattenValue
55
+	 * @param string $prefix
56
+	 * @return array
57
+	 */
58
+	public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
+	{
60
+		$result = [];
61
+		foreach ($array as $key => $value) {
62
+			$newKey = ltrim($prefix.'.'.$key, '.');
63
+			if (static::isIndexedFlatArray($value)) {
64
+				if ($flattenValue) {
65
+					$value = '['.implode(', ', $value).']';
66
+				}
67
+			} elseif (is_array($value)) {
68
+				$result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
+				continue;
70
+			}
71
+			$result[$newKey] = $value;
72
+		}
73
+		return $result;
74
+	}
75
+
76
+	/**
77
+	 * Get a value from an array of values using a dot-notation path as reference.
78
+	 * @param mixed $data
79
+	 * @param string $path
80
+	 * @param mixed $fallback
81
+	 * @return mixed
82
+	 */
83
+	public static function get($data, $path = '', $fallback = '')
84
+	{
85
+		$data = static::consolidateArray($data);
86
+		$keys = explode('.', $path);
87
+		foreach ($keys as $key) {
88
+			if (!isset($data[$key])) {
89
+				return $fallback;
90
+			}
91
+			$data = $data[$key];
92
+		}
93
+		return $data;
94
+	}
95
+
96
+	/**
97
+	 * @param string $key
98
+	 * @return array
99
+	 */
100
+	public static function insertAfter($key, array $array, array $insert)
101
+	{
102
+		return static::insertInArray($array, $insert, $key, 'after');
103
+	}
104
+
105
+	/**
106
+	 * @param string $key
107
+	 * @return array
108
+	 */
109
+	public static function insertBefore($key, array $array, array $insert)
110
+	{
111
+		return static::insertInArray($array, $insert, $key, 'before');
112
+	}
113
+
114
+	/**
115
+	 * @param string $key
116
+	 * @param string $position
117
+	 * @return array
118
+	 */
119
+	public static function insertInArray(array $array, array $insert, $key, $position = 'before')
120
+	{
121
+		$keyPosition = intval(array_search($key, array_keys($array)));
122
+		if ('after' == $position) {
123
+			++$keyPosition;
124
+		}
125
+		if (false !== $keyPosition) {
126
+			$result = array_slice($array, 0, $keyPosition);
127
+			$result = array_merge($result, $insert);
128
+			return array_merge($result, array_slice($array, $keyPosition));
129
+		}
130
+		return array_merge($array, $insert);
131
+	}
132
+
133
+	/**
134
+	 * @param mixed $array
135
+	 * @return bool
136
+	 */
137
+	public static function isIndexedFlatArray($array)
138
+	{
139
+		if (!is_array($array) || array_filter($array, 'is_array')) {
140
+			return false;
141
+		}
142
+		return wp_is_numeric_array($array);
143
+	}
144
+
145
+	/**
146
+	 * @param bool $prefixed
147
+	 * @return array
148
+	 */
149
+	public static function prefixArrayKeys(array $values, $prefixed = true)
150
+	{
151
+		$trim = '_';
152
+		$prefix = $prefixed
153
+			? $trim
154
+			: '';
155
+		$prefixed = [];
156
+		foreach ($values as $key => $value) {
157
+			$key = trim($key);
158
+			if (0 === strpos($key, $trim)) {
159
+				$key = substr($key, strlen($trim));
160
+			}
161
+			$prefixed[$prefix.$key] = $value;
162
+		}
163
+		return $prefixed;
164
+	}
165
+
166
+	/**
167
+	 * @return array
168
+	 */
169
+	public static function removeEmptyArrayValues(array $array)
170
+	{
171
+		$result = [];
172
+		foreach ($array as $key => $value) {
173
+			if (!$value) {
174
+				continue;
175
+			}
176
+			$result[$key] = is_array($value)
177
+				? static::removeEmptyArrayValues($value)
178
+				: $value;
179
+		}
180
+		return $result;
181
+	}
182
+
183
+
184
+	/**
185
+	 * Set a value to an array of values using a dot-notation path as reference.
186
+	 * @param string $path
187
+	 * @param mixed $value
188
+	 * @return array
189
+	 */
190
+	public static function set(array $data, $path, $value)
191
+	{
192
+		$token = strtok($path, '.');
193
+		$ref = &$data;
194
+		while (false !== $token) {
195
+			$ref = static::consolidateArray($ref);
196
+			$ref = &$ref[$token];
197
+			$token = strtok('.');
198
+		}
199
+		$ref = $value;
200
+		return $data;
201
+	}
202
+
203
+	/**
204
+	 * @return array
205
+	 */
206
+	public static function unique(array $values)
207
+	{
208
+		return array_filter(array_unique($values));
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	public static function unprefixArrayKeys(array $values)
215
+	{
216
+		return static::prefixArrayKeys($values, false);
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
     /**
8 8
      * @return bool
9 9
      */
10
-    public static function compareArrays(array $arr1, array $arr2)
10
+    public static function compareArrays( array $arr1, array $arr2 )
11 11
     {
12
-        sort($arr1);
13
-        sort($arr2);
12
+        sort( $arr1 );
13
+        sort( $arr2 );
14 14
         return $arr1 == $arr2;
15 15
     }
16 16
 
@@ -18,21 +18,21 @@  discard block
 block discarded – undo
18 18
      * @param mixed $array
19 19
      * @return array
20 20
      */
21
-    public static function consolidateArray($array)
21
+    public static function consolidateArray( $array )
22 22
     {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
23
+        return is_array( $array ) || is_object( $array )
24
+            ? (array)$array
25 25
             : [];
26 26
     }
27 27
 
28 28
     /**
29 29
      * @return array
30 30
      */
31
-    public static function convertDotNotationArray(array $array)
31
+    public static function convertDotNotationArray( array $array )
32 32
     {
33 33
         $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
34
+        foreach( $array as $path => $value ) {
35
+            $results = static::set( $results, $path, $value );
36 36
         }
37 37
         return $results;
38 38
     }
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      * @param mixed $callback
43 43
      * @return array
44 44
      */
45
-    public static function convertStringToArray($string, $callback = null)
45
+    public static function convertStringToArray( $string, $callback = null )
46 46
     {
47
-        $array = array_map('trim', explode(',', $string));
47
+        $array = array_map( 'trim', explode( ',', $string ) );
48 48
         return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
49
+            ? array_filter( $array, $callback )
50
+            : array_filter( $array );
51 51
     }
52 52
 
53 53
     /**
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
      * @param string $prefix
56 56
      * @return array
57 57
      */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
58
+    public static function flattenArray( array $array, $flattenValue = false, $prefix = '' )
59 59
     {
60 60
         $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
61
+        foreach( $array as $key => $value ) {
62
+            $newKey = ltrim( $prefix.'.'.$key, '.' );
63
+            if( static::isIndexedFlatArray( $value ) ) {
64
+                if( $flattenValue ) {
65
+                    $value = '['.implode( ', ', $value ).']';
66 66
                 }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
67
+            } elseif( is_array( $value ) ) {
68
+                $result = array_merge( $result, static::flattenArray( $value, $flattenValue, $newKey ) );
69 69
                 continue;
70 70
             }
71 71
             $result[$newKey] = $value;
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
      * @param mixed $fallback
81 81
      * @return mixed
82 82
      */
83
-    public static function get($data, $path = '', $fallback = '')
83
+    public static function get( $data, $path = '', $fallback = '' )
84 84
     {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
85
+        $data = static::consolidateArray( $data );
86
+        $keys = explode( '.', $path );
87
+        foreach( $keys as $key ) {
88
+            if( !isset($data[$key]) ) {
89 89
                 return $fallback;
90 90
             }
91 91
             $data = $data[$key];
@@ -97,18 +97,18 @@  discard block
 block discarded – undo
97 97
      * @param string $key
98 98
      * @return array
99 99
      */
100
-    public static function insertAfter($key, array $array, array $insert)
100
+    public static function insertAfter( $key, array $array, array $insert )
101 101
     {
102
-        return static::insertInArray($array, $insert, $key, 'after');
102
+        return static::insertInArray( $array, $insert, $key, 'after' );
103 103
     }
104 104
 
105 105
     /**
106 106
      * @param string $key
107 107
      * @return array
108 108
      */
109
-    public static function insertBefore($key, array $array, array $insert)
109
+    public static function insertBefore( $key, array $array, array $insert )
110 110
     {
111
-        return static::insertInArray($array, $insert, $key, 'before');
111
+        return static::insertInArray( $array, $insert, $key, 'before' );
112 112
     }
113 113
 
114 114
     /**
@@ -116,47 +116,47 @@  discard block
 block discarded – undo
116 116
      * @param string $position
117 117
      * @return array
118 118
      */
119
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
119
+    public static function insertInArray( array $array, array $insert, $key, $position = 'before' )
120 120
     {
121
-        $keyPosition = intval(array_search($key, array_keys($array)));
122
-        if ('after' == $position) {
121
+        $keyPosition = intval( array_search( $key, array_keys( $array ) ) );
122
+        if( 'after' == $position ) {
123 123
             ++$keyPosition;
124 124
         }
125
-        if (false !== $keyPosition) {
126
-            $result = array_slice($array, 0, $keyPosition);
127
-            $result = array_merge($result, $insert);
128
-            return array_merge($result, array_slice($array, $keyPosition));
125
+        if( false !== $keyPosition ) {
126
+            $result = array_slice( $array, 0, $keyPosition );
127
+            $result = array_merge( $result, $insert );
128
+            return array_merge( $result, array_slice( $array, $keyPosition ) );
129 129
         }
130
-        return array_merge($array, $insert);
130
+        return array_merge( $array, $insert );
131 131
     }
132 132
 
133 133
     /**
134 134
      * @param mixed $array
135 135
      * @return bool
136 136
      */
137
-    public static function isIndexedFlatArray($array)
137
+    public static function isIndexedFlatArray( $array )
138 138
     {
139
-        if (!is_array($array) || array_filter($array, 'is_array')) {
139
+        if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) {
140 140
             return false;
141 141
         }
142
-        return wp_is_numeric_array($array);
142
+        return wp_is_numeric_array( $array );
143 143
     }
144 144
 
145 145
     /**
146 146
      * @param bool $prefixed
147 147
      * @return array
148 148
      */
149
-    public static function prefixArrayKeys(array $values, $prefixed = true)
149
+    public static function prefixArrayKeys( array $values, $prefixed = true )
150 150
     {
151 151
         $trim = '_';
152 152
         $prefix = $prefixed
153 153
             ? $trim
154 154
             : '';
155 155
         $prefixed = [];
156
-        foreach ($values as $key => $value) {
157
-            $key = trim($key);
158
-            if (0 === strpos($key, $trim)) {
159
-                $key = substr($key, strlen($trim));
156
+        foreach( $values as $key => $value ) {
157
+            $key = trim( $key );
158
+            if( 0 === strpos( $key, $trim ) ) {
159
+                $key = substr( $key, strlen( $trim ) );
160 160
             }
161 161
             $prefixed[$prefix.$key] = $value;
162 162
         }
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return array
168 168
      */
169
-    public static function removeEmptyArrayValues(array $array)
169
+    public static function removeEmptyArrayValues( array $array )
170 170
     {
171 171
         $result = [];
172
-        foreach ($array as $key => $value) {
173
-            if (!$value) {
172
+        foreach( $array as $key => $value ) {
173
+            if( !$value ) {
174 174
                 continue;
175 175
             }
176
-            $result[$key] = is_array($value)
177
-                ? static::removeEmptyArrayValues($value)
176
+            $result[$key] = is_array( $value )
177
+                ? static::removeEmptyArrayValues( $value )
178 178
                 : $value;
179 179
         }
180 180
         return $result;
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
      * @param mixed $value
188 188
      * @return array
189 189
      */
190
-    public static function set(array $data, $path, $value)
190
+    public static function set( array $data, $path, $value )
191 191
     {
192
-        $token = strtok($path, '.');
192
+        $token = strtok( $path, '.' );
193 193
         $ref = &$data;
194
-        while (false !== $token) {
195
-            $ref = static::consolidateArray($ref);
194
+        while( false !== $token ) {
195
+            $ref = static::consolidateArray( $ref );
196 196
             $ref = &$ref[$token];
197
-            $token = strtok('.');
197
+            $token = strtok( '.' );
198 198
         }
199 199
         $ref = $value;
200 200
         return $data;
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
     /**
204 204
      * @return array
205 205
      */
206
-    public static function unique(array $values)
206
+    public static function unique( array $values )
207 207
     {
208
-        return array_filter(array_unique($values));
208
+        return array_filter( array_unique( $values ) );
209 209
     }
210 210
 
211 211
     /**
212 212
      * @return array
213 213
      */
214
-    public static function unprefixArrayKeys(array $values)
214
+    public static function unprefixArrayKeys( array $values )
215 215
     {
216
-        return static::prefixArrayKeys($values, false);
216
+        return static::prefixArrayKeys( $values, false );
217 217
     }
218 218
 }
Please login to merge, or discard this patch.
views/pages/tools/general.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,42 +1,42 @@  discard block
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3
-<?php if (glsr()->hasPermission('settings')) : ?>
3
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
4 4
 <div class="glsr-card card">
5 5
     <h3>Export Settings</h3>
6 6
     <p>Export the Site Reviews settings for this site to a <code>*.json</code> file. This allows you to easily import the plugin settings into another site.</p>
7
-    <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url('export.php'); ?>">Export</a> tool.</p>
7
+    <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url( 'export.php' ); ?>">Export</a> tool.</p>
8 8
     <form method="post">
9 9
         <input type="hidden" name="{{ id }}[_action]" value="export-settings">
10
-        <?php wp_nonce_field('export-settings'); ?>
11
-        <?php submit_button(__('Export Settings', 'site-reviews'), 'secondary'); ?>
10
+        <?php wp_nonce_field( 'export-settings' ); ?>
11
+        <?php submit_button( __( 'Export Settings', 'site-reviews' ), 'secondary' ); ?>
12 12
     </form>
13 13
 </div>
14 14
 <?php endif; ?>
15 15
 
16
-<?php if (glsr()->hasPermission('settings')) : ?>
16
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
17 17
 <div class="glsr-card card">
18 18
     <h3>Import Settings</h3>
19 19
     <p>Import the Site Reviews settings from a <code>*.json</code> file. This file can be obtained by exporting the settings on another site using the export tool below.</p>
20
-    <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url('import.php'); ?>">Import</a> tool.</p>
20
+    <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url( 'import.php' ); ?>">Import</a> tool.</p>
21 21
     <form method="post" enctype="multipart/form-data">
22 22
         <input type="file" name="import-file">
23 23
         <input type="hidden" name="{{ id }}[_action]" value="import-settings">
24
-        <?php wp_nonce_field('import-settings'); ?>
25
-        <?php submit_button(__('Import Settings', 'site-reviews'), 'secondary'); ?>
24
+        <?php wp_nonce_field( 'import-settings' ); ?>
25
+        <?php submit_button( __( 'Import Settings', 'site-reviews' ), 'secondary' ); ?>
26 26
     </form>
27 27
 </div>
28 28
 <?php endif; ?>
29 29
 
30
-<?php if (glsr()->hasPermission('settings')) : ?>
30
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
31 31
 <div class="glsr-card card">
32 32
     <h3>Migrate Plugin</h3>
33 33
     <p>Run this tool if your reviews stopped working correctly after upgrading the plugin to the latest version (i.e. read-only reviews, zero-star ratings, missing role capabilities, etc.).</p>
34 34
     <form method="post">
35 35
         <input type="hidden" name="{{ id }}[_action]" value="migrate-reviews">
36
-        <?php wp_nonce_field('migrate-reviews'); ?>
36
+        <?php wp_nonce_field( 'migrate-reviews' ); ?>
37 37
         <p class="submit">
38 38
             <button type="submit" class="glsr-button button" name="migrate-reviews" id="migrate-reviews">
39
-                <span data-loading="<?= __('Migrating Reviews, please wait...', 'site-reviews'); ?>"><?= __('Run Migration', 'site-reviews'); ?></span>
39
+                <span data-loading="<?= __( 'Migrating Reviews, please wait...', 'site-reviews' ); ?>"><?= __( 'Run Migration', 'site-reviews' ); ?></span>
40 40
             </button>
41 41
         </p>
42 42
     </form>
@@ -49,26 +49,26 @@  discard block
 block discarded – undo
49 49
     <p>If you suspect that the rating counts are incorrect (perhaps you have cloned a page that had reviews assigned to it, or edited/deleted reviews directly from your database), you can recalculate them here.</p>
50 50
     <form method="post">
51 51
         <input type="hidden" name="{{ id }}[_action]" value="count-reviews">
52
-        <?php wp_nonce_field('count-reviews'); ?>
52
+        <?php wp_nonce_field( 'count-reviews' ); ?>
53 53
         <p class="submit">
54 54
             <button type="submit" class="glsr-button button" name="count-reviews" id="count-reviews">
55
-                <span data-loading="<?= __('Recalculating Counts, please wait...', 'site-reviews'); ?>"><?= __('Recalculate Counts', 'site-reviews'); ?></span>
55
+                <span data-loading="<?= __( 'Recalculating Counts, please wait...', 'site-reviews' ); ?>"><?= __( 'Recalculate Counts', 'site-reviews' ); ?></span>
56 56
             </button>
57 57
         </p>
58 58
     </form>
59 59
 </div>
60 60
 
61
-<?php if (glsr()->hasPermission('settings')) : ?>
61
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
62 62
 <div class="glsr-card card">
63 63
     <h3>Reset Permissions</h3>
64 64
     <p>Site Reviews provides custom post_type capabilities that mirror the capabilities of your posts by default. For example, if a user role has permission to edit others posts, then that role will also have permission to edit other users reviews.</p>
65 65
     <p>If you have changed the capabilities of your user roles and you suspect that Site Reviews is not working correctly due to your changes, you may use this tool to reset the Site Reviews capabilities for your user roles.</p>
66 66
     <form method="post">
67 67
         <input type="hidden" name="{{ id }}[_action]" value="reset-permissions">
68
-        <?php wp_nonce_field('reset-permissions'); ?>
68
+        <?php wp_nonce_field( 'reset-permissions' ); ?>
69 69
         <p class="submit">
70 70
             <button type="submit" class="glsr-button button" name="reset-permissions" id="reset-permissions">
71
-                <span data-loading="<?= __('Resetting Permissions, please wait...', 'site-reviews'); ?>"><?= __('Reset Permissions', 'site-reviews'); ?></span>
71
+                <span data-loading="<?= __( 'Resetting Permissions, please wait...', 'site-reviews' ); ?>"><?= __( 'Reset Permissions', 'site-reviews' ); ?></span>
72 72
             </button>
73 73
         </p>
74 74
     </form>
Please login to merge, or discard this patch.