Test Failed
Push — tmp ( 15f615...89cc97 )
by Paul
10:31 queued 04:40
created
plugin/Modules/Rating.php 2 patches
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -4,215 +4,215 @@
 block discarded – undo
4 4
 
5 5
 class Rating
6 6
 {
7
-    /**
8
-     * The more sure we are of the confidence interval (the higher the confidence level), the less
9
-     * precise the estimation will be as the margin for error will be higher.
10
-     * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
-     * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
-     * @see https://www.youtube.com/watch?v=grodoLzThy4
13
-     * @see https://en.wikipedia.org/wiki/Standard_score
14
-     * @var array
15
-     */
16
-    const CONFIDENCE_LEVEL_Z_SCORES = [
17
-        50 => 0.67449,
18
-        70 => 1.04,
19
-        75 => 1.15035,
20
-        80 => 1.282,
21
-        85 => 1.44,
22
-        90 => 1.64485,
23
-        92 => 1.75,
24
-        95 => 1.95996,
25
-        96 => 2.05,
26
-        97 => 2.17009,
27
-        98 => 2.326,
28
-        99 => 2.57583,
29
-        '99.5' => 2.81,
30
-        '99.8' => 3.08,
31
-        '99.9' => 3.29053,
32
-    ];
7
+	/**
8
+	 * The more sure we are of the confidence interval (the higher the confidence level), the less
9
+	 * precise the estimation will be as the margin for error will be higher.
10
+	 * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf
11
+	 * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html
12
+	 * @see https://www.youtube.com/watch?v=grodoLzThy4
13
+	 * @see https://en.wikipedia.org/wiki/Standard_score
14
+	 * @var array
15
+	 */
16
+	const CONFIDENCE_LEVEL_Z_SCORES = [
17
+		50 => 0.67449,
18
+		70 => 1.04,
19
+		75 => 1.15035,
20
+		80 => 1.282,
21
+		85 => 1.44,
22
+		90 => 1.64485,
23
+		92 => 1.75,
24
+		95 => 1.95996,
25
+		96 => 2.05,
26
+		97 => 2.17009,
27
+		98 => 2.326,
28
+		99 => 2.57583,
29
+		'99.5' => 2.81,
30
+		'99.8' => 3.08,
31
+		'99.9' => 3.29053,
32
+	];
33 33
 
34
-    /**
35
-     * @var int
36
-     */
37
-    const MAX_RATING = 5;
34
+	/**
35
+	 * @var int
36
+	 */
37
+	const MAX_RATING = 5;
38 38
 
39
-    /**
40
-     * @var int
41
-     */
42
-    const MIN_RATING = 1;
39
+	/**
40
+	 * @var int
41
+	 */
42
+	const MIN_RATING = 1;
43 43
 
44
-    /**
45
-     * @param int $roundBy
46
-     * @return float
47
-     */
48
-    public function average(array $ratingCounts, $roundBy = 1)
49
-    {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->totalSum($ratingCounts) / $average;
53
-        }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return glsr()->filterFloat('rating/average', $roundedAverage, $ratingCounts, $average);
56
-    }
44
+	/**
45
+	 * @param int $roundBy
46
+	 * @return float
47
+	 */
48
+	public function average(array $ratingCounts, $roundBy = 1)
49
+	{
50
+		$average = array_sum($ratingCounts);
51
+		if ($average > 0) {
52
+			$average = $this->totalSum($ratingCounts) / $average;
53
+		}
54
+		$roundedAverage = round($average, intval($roundBy));
55
+		return glsr()->filterFloat('rating/average', $roundedAverage, $ratingCounts, $average);
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function emptyArray()
62
-    {
63
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', __CLASS__)), 0);
64
-    }
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function emptyArray()
62
+	{
63
+		return array_fill_keys(range(0, glsr()->constant('MAX_RATING', __CLASS__)), 0);
64
+	}
65 65
 
66
-    /**
67
-     * Get the lower bound for up/down ratings
68
-     * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
69
-     * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
70
-     * @see https://news.ycombinator.com/item?id=10481507
71
-     * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
72
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
73
-     * @param int $confidencePercentage
74
-     * @return int|float
75
-     */
76
-    public function lowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
77
-    {
78
-        $numRatings = array_sum($upDownCounts);
79
-        if ($numRatings < 1) {
80
-            return 0;
81
-        }
82
-        $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
83
-        $phat = 1 * $upDownCounts[1] / $numRatings;
84
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
85
-    }
66
+	/**
67
+	 * Get the lower bound for up/down ratings
68
+	 * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1].
69
+	 * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
70
+	 * @see https://news.ycombinator.com/item?id=10481507
71
+	 * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments
72
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
73
+	 * @param int $confidencePercentage
74
+	 * @return int|float
75
+	 */
76
+	public function lowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
77
+	{
78
+		$numRatings = array_sum($upDownCounts);
79
+		if ($numRatings < 1) {
80
+			return 0;
81
+		}
82
+		$z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
83
+		$phat = 1 * $upDownCounts[1] / $numRatings;
84
+		return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
85
+	}
86 86
 
87
-    /**
88
-     * @return int|float
89
-     */
90
-    public function overallPercentage(array $ratingCounts)
91
-    {
92
-        return round($this->average($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
93
-    }
87
+	/**
88
+	 * @return int|float
89
+	 */
90
+	public function overallPercentage(array $ratingCounts)
91
+	{
92
+		return round($this->average($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
93
+	}
94 94
 
95
-    /**
96
-     * @return array
97
-     */
98
-    public function percentages(array $ratingCounts)
99
-    {
100
-        $total = array_sum($ratingCounts);
101
-        foreach ($ratingCounts as $index => $count) {
102
-            if (empty($count)) {
103
-                continue;
104
-            }
105
-            $ratingCounts[$index] = $count / $total * 100;
106
-        }
107
-        return $this->roundedPercentages($ratingCounts);
108
-    }
95
+	/**
96
+	 * @return array
97
+	 */
98
+	public function percentages(array $ratingCounts)
99
+	{
100
+		$total = array_sum($ratingCounts);
101
+		foreach ($ratingCounts as $index => $count) {
102
+			if (empty($count)) {
103
+				continue;
104
+			}
105
+			$ratingCounts[$index] = $count / $total * 100;
106
+		}
107
+		return $this->roundedPercentages($ratingCounts);
108
+	}
109 109
 
110
-    /**
111
-     * @return float
112
-     */
113
-    public function ranking(array $ratingCounts)
114
-    {
115
-        return glsr()->filterFloat('rating/ranking',
116
-            $this->rankingUsingImdb($ratingCounts),
117
-            $ratingCounts,
118
-            $this
119
-        );
120
-    }
110
+	/**
111
+	 * @return float
112
+	 */
113
+	public function ranking(array $ratingCounts)
114
+	{
115
+		return glsr()->filterFloat('rating/ranking',
116
+			$this->rankingUsingImdb($ratingCounts),
117
+			$ratingCounts,
118
+			$this
119
+		);
120
+	}
121 121
 
122
-    /**
123
-     * Get the bayesian ranking for an array of reviews
124
-     * This formula is the same one used by IMDB to rank their top 250 films.
125
-     * @see https://www.xkcd.com/937/
126
-     * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
127
-     * @see http://fulmicoton.com/posts/bayesian_rating/
128
-     * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
129
-     * @param int $confidencePercentage
130
-     * @return int|float
131
-     */
132
-    public function rankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
133
-    {
134
-        $avgRating = $this->average($ratingCounts);
135
-        // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
136
-        // This could also be the average score of all items instead of a fixed value.
137
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
138
-        // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
139
-        $bayesMinimal = 10; // confidence
140
-        $numOfReviews = array_sum($ratingCounts);
141
-        return $avgRating > 0
142
-            ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
143
-            : 0;
144
-    }
122
+	/**
123
+	 * Get the bayesian ranking for an array of reviews
124
+	 * This formula is the same one used by IMDB to rank their top 250 films.
125
+	 * @see https://www.xkcd.com/937/
126
+	 * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means
127
+	 * @see http://fulmicoton.com/posts/bayesian_rating/
128
+	 * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va
129
+	 * @param int $confidencePercentage
130
+	 * @return int|float
131
+	 */
132
+	public function rankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
133
+	{
134
+		$avgRating = $this->average($ratingCounts);
135
+		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
136
+		// This could also be the average score of all items instead of a fixed value.
137
+		$bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
138
+		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
139
+		$bayesMinimal = 10; // confidence
140
+		$numOfReviews = array_sum($ratingCounts);
141
+		return $avgRating > 0
142
+			? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
143
+			: 0;
144
+	}
145 145
 
146
-    /**
147
-     * The quality of a 5 star rating depends not only on the average number of stars but also on
148
-     * the number of reviews. This method calculates the bayesian ranking of a page by its number
149
-     * of reviews and their rating.
150
-     * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
151
-     * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
152
-     * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
153
-     * @param int $confidencePercentage
154
-     * @return float
155
-     */
156
-    public function rankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
157
-    {
158
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
159
-        $weight = $this->weight($ratingCounts, $ratingCountsSum);
160
-        $weightPow2 = $this->weight($ratingCounts, $ratingCountsSum, true);
161
-        $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
162
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
163
-    }
146
+	/**
147
+	 * The quality of a 5 star rating depends not only on the average number of stars but also on
148
+	 * the number of reviews. This method calculates the bayesian ranking of a page by its number
149
+	 * of reviews and their rating.
150
+	 * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html
151
+	 * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268
152
+	 * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html
153
+	 * @param int $confidencePercentage
154
+	 * @return float
155
+	 */
156
+	public function rankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
157
+	{
158
+		$ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
159
+		$weight = $this->weight($ratingCounts, $ratingCountsSum);
160
+		$weightPow2 = $this->weight($ratingCounts, $ratingCountsSum, true);
161
+		$zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
162
+		return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
163
+	}
164 164
 
165
-    /**
166
-     * @param int $target
167
-     * @return array
168
-     */
169
-    protected function roundedPercentages(array $percentages, $totalPercent = 100)
170
-    {
171
-        array_walk($percentages, function (&$percent, $index) {
172
-            $percent = [
173
-                'index' => $index,
174
-                'percent' => floor($percent),
175
-                'remainder' => fmod($percent, 1),
176
-            ];
177
-        });
178
-        $indexes = wp_list_pluck($percentages, 'index');
179
-        $remainders = wp_list_pluck($percentages, 'remainder');
180
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
181
-        $i = 0;
182
-        if (array_sum(wp_list_pluck($percentages, 'percent')) > 0) {
183
-            while (array_sum(wp_list_pluck($percentages, 'percent')) < $totalPercent) {
184
-                ++$percentages[$i]['percent'];
185
-                ++$i;
186
-            }
187
-        }
188
-        array_multisort($indexes, SORT_DESC, $percentages);
189
-        return array_combine($indexes, wp_list_pluck($percentages, 'percent'));
190
-    }
165
+	/**
166
+	 * @param int $target
167
+	 * @return array
168
+	 */
169
+	protected function roundedPercentages(array $percentages, $totalPercent = 100)
170
+	{
171
+		array_walk($percentages, function (&$percent, $index) {
172
+			$percent = [
173
+				'index' => $index,
174
+				'percent' => floor($percent),
175
+				'remainder' => fmod($percent, 1),
176
+			];
177
+		});
178
+		$indexes = wp_list_pluck($percentages, 'index');
179
+		$remainders = wp_list_pluck($percentages, 'remainder');
180
+		array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
181
+		$i = 0;
182
+		if (array_sum(wp_list_pluck($percentages, 'percent')) > 0) {
183
+			while (array_sum(wp_list_pluck($percentages, 'percent')) < $totalPercent) {
184
+				++$percentages[$i]['percent'];
185
+				++$i;
186
+			}
187
+		}
188
+		array_multisort($indexes, SORT_DESC, $percentages);
189
+		return array_combine($indexes, wp_list_pluck($percentages, 'percent'));
190
+	}
191 191
 
192
-    /**
193
-     * @return int
194
-     */
195
-    protected function totalSum(array $ratingCounts)
196
-    {
197
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
198
-            return $carry + ($index * $ratingCounts[$index]);
199
-        });
200
-    }
192
+	/**
193
+	 * @return int
194
+	 */
195
+	protected function totalSum(array $ratingCounts)
196
+	{
197
+		return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
198
+			return $carry + ($index * $ratingCounts[$index]);
199
+		});
200
+	}
201 201
 
202
-    /**
203
-     * @param int|float $ratingCountsSum
204
-     * @param bool $powerOf2
205
-     * @return float
206
-     */
207
-    protected function weight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
208
-    {
209
-        return array_reduce(array_keys($ratingCounts),
210
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
211
-                $ratingLevel = $powerOf2
212
-                    ? pow($rating, 2)
213
-                    : $rating;
214
-                return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
215
-            }
216
-        );
217
-    }
202
+	/**
203
+	 * @param int|float $ratingCountsSum
204
+	 * @param bool $powerOf2
205
+	 * @return float
206
+	 */
207
+	protected function weight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
208
+	{
209
+		return array_reduce(array_keys($ratingCounts),
210
+			function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
211
+				$ratingLevel = $powerOf2
212
+					? pow($rating, 2)
213
+					: $rating;
214
+				return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
215
+			}
216
+		);
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
      * @param int $roundBy
46 46
      * @return float
47 47
      */
48
-    public function average(array $ratingCounts, $roundBy = 1)
48
+    public function average( array $ratingCounts, $roundBy = 1 )
49 49
     {
50
-        $average = array_sum($ratingCounts);
51
-        if ($average > 0) {
52
-            $average = $this->totalSum($ratingCounts) / $average;
50
+        $average = array_sum( $ratingCounts );
51
+        if( $average > 0 ) {
52
+            $average = $this->totalSum( $ratingCounts ) / $average;
53 53
         }
54
-        $roundedAverage = round($average, intval($roundBy));
55
-        return glsr()->filterFloat('rating/average', $roundedAverage, $ratingCounts, $average);
54
+        $roundedAverage = round( $average, intval( $roundBy ) );
55
+        return glsr()->filterFloat( 'rating/average', $roundedAverage, $ratingCounts, $average );
56 56
     }
57 57
 
58 58
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function emptyArray()
62 62
     {
63
-        return array_fill_keys(range(0, glsr()->constant('MAX_RATING', __CLASS__)), 0);
63
+        return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', __CLASS__ ) ), 0 );
64 64
     }
65 65
 
66 66
     /**
@@ -73,47 +73,47 @@  discard block
 block discarded – undo
73 73
      * @param int $confidencePercentage
74 74
      * @return int|float
75 75
      */
76
-    public function lowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95)
76
+    public function lowerBound( array $upDownCounts = [0, 0], $confidencePercentage = 95 )
77 77
     {
78
-        $numRatings = array_sum($upDownCounts);
79
-        if ($numRatings < 1) {
78
+        $numRatings = array_sum( $upDownCounts );
79
+        if( $numRatings < 1 ) {
80 80
             return 0;
81 81
         }
82 82
         $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
83 83
         $phat = 1 * $upDownCounts[1] / $numRatings;
84
-        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings);
84
+        return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings);
85 85
     }
86 86
 
87 87
     /**
88 88
      * @return int|float
89 89
      */
90
-    public function overallPercentage(array $ratingCounts)
90
+    public function overallPercentage( array $ratingCounts )
91 91
     {
92
-        return round($this->average($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2);
92
+        return round( $this->average( $ratingCounts ) * 100 / glsr()->constant( 'MAX_RATING', __CLASS__ ), 2 );
93 93
     }
94 94
 
95 95
     /**
96 96
      * @return array
97 97
      */
98
-    public function percentages(array $ratingCounts)
98
+    public function percentages( array $ratingCounts )
99 99
     {
100
-        $total = array_sum($ratingCounts);
101
-        foreach ($ratingCounts as $index => $count) {
102
-            if (empty($count)) {
100
+        $total = array_sum( $ratingCounts );
101
+        foreach( $ratingCounts as $index => $count ) {
102
+            if( empty($count) ) {
103 103
                 continue;
104 104
             }
105 105
             $ratingCounts[$index] = $count / $total * 100;
106 106
         }
107
-        return $this->roundedPercentages($ratingCounts);
107
+        return $this->roundedPercentages( $ratingCounts );
108 108
     }
109 109
 
110 110
     /**
111 111
      * @return float
112 112
      */
113
-    public function ranking(array $ratingCounts)
113
+    public function ranking( array $ratingCounts )
114 114
     {
115
-        return glsr()->filterFloat('rating/ranking',
116
-            $this->rankingUsingImdb($ratingCounts),
115
+        return glsr()->filterFloat( 'rating/ranking',
116
+            $this->rankingUsingImdb( $ratingCounts ),
117 117
             $ratingCounts,
118 118
             $this
119 119
         );
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
      * @param int $confidencePercentage
130 130
      * @return int|float
131 131
      */
132
-    public function rankingUsingImdb(array $ratingCounts, $confidencePercentage = 70)
132
+    public function rankingUsingImdb( array $ratingCounts, $confidencePercentage = 70 )
133 133
     {
134
-        $avgRating = $this->average($ratingCounts);
134
+        $avgRating = $this->average( $ratingCounts );
135 135
         // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
136 136
         // This could also be the average score of all items instead of a fixed value.
137
-        $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5
137
+        $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING', __CLASS__ ); // prior, 70% = 3.5
138 138
         // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
139 139
         $bayesMinimal = 10; // confidence
140
-        $numOfReviews = array_sum($ratingCounts);
140
+        $numOfReviews = array_sum( $ratingCounts );
141 141
         return $avgRating > 0
142 142
             ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews)
143 143
             : 0;
@@ -153,48 +153,48 @@  discard block
 block discarded – undo
153 153
      * @param int $confidencePercentage
154 154
      * @return float
155 155
      */
156
-    public function rankingUsingZScores(array $ratingCounts, $confidencePercentage = 90)
156
+    public function rankingUsingZScores( array $ratingCounts, $confidencePercentage = 90 )
157 157
     {
158
-        $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__);
159
-        $weight = $this->weight($ratingCounts, $ratingCountsSum);
160
-        $weightPow2 = $this->weight($ratingCounts, $ratingCountsSum, true);
158
+        $ratingCountsSum = array_sum( $ratingCounts ) + glsr()->constant( 'MAX_RATING', __CLASS__ );
159
+        $weight = $this->weight( $ratingCounts, $ratingCountsSum );
160
+        $weightPow2 = $this->weight( $ratingCounts, $ratingCountsSum, true );
161 161
         $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage];
162
-        return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1));
162
+        return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) );
163 163
     }
164 164
 
165 165
     /**
166 166
      * @param int $target
167 167
      * @return array
168 168
      */
169
-    protected function roundedPercentages(array $percentages, $totalPercent = 100)
169
+    protected function roundedPercentages( array $percentages, $totalPercent = 100 )
170 170
     {
171
-        array_walk($percentages, function (&$percent, $index) {
171
+        array_walk( $percentages, function( &$percent, $index ) {
172 172
             $percent = [
173 173
                 'index' => $index,
174
-                'percent' => floor($percent),
175
-                'remainder' => fmod($percent, 1),
174
+                'percent' => floor( $percent ),
175
+                'remainder' => fmod( $percent, 1 ),
176 176
             ];
177 177
         });
178
-        $indexes = wp_list_pluck($percentages, 'index');
179
-        $remainders = wp_list_pluck($percentages, 'remainder');
180
-        array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages);
178
+        $indexes = wp_list_pluck( $percentages, 'index' );
179
+        $remainders = wp_list_pluck( $percentages, 'remainder' );
180
+        array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages );
181 181
         $i = 0;
182
-        if (array_sum(wp_list_pluck($percentages, 'percent')) > 0) {
183
-            while (array_sum(wp_list_pluck($percentages, 'percent')) < $totalPercent) {
182
+        if( array_sum( wp_list_pluck( $percentages, 'percent' ) ) > 0 ) {
183
+            while( array_sum( wp_list_pluck( $percentages, 'percent' ) ) < $totalPercent ) {
184 184
                 ++$percentages[$i]['percent'];
185 185
                 ++$i;
186 186
             }
187 187
         }
188
-        array_multisort($indexes, SORT_DESC, $percentages);
189
-        return array_combine($indexes, wp_list_pluck($percentages, 'percent'));
188
+        array_multisort( $indexes, SORT_DESC, $percentages );
189
+        return array_combine( $indexes, wp_list_pluck( $percentages, 'percent' ) );
190 190
     }
191 191
 
192 192
     /**
193 193
      * @return int
194 194
      */
195
-    protected function totalSum(array $ratingCounts)
195
+    protected function totalSum( array $ratingCounts )
196 196
     {
197
-        return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) {
197
+        return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use ($ratingCounts) {
198 198
             return $carry + ($index * $ratingCounts[$index]);
199 199
         });
200 200
     }
@@ -204,12 +204,12 @@  discard block
 block discarded – undo
204 204
      * @param bool $powerOf2
205 205
      * @return float
206 206
      */
207
-    protected function weight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false)
207
+    protected function weight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false )
208 208
     {
209
-        return array_reduce(array_keys($ratingCounts),
210
-            function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
209
+        return array_reduce( array_keys( $ratingCounts ),
210
+            function( $count, $rating ) use ($ratingCounts, $ratingCountsSum, $powerOf2) {
211 211
                 $ratingLevel = $powerOf2
212
-                    ? pow($rating, 2)
212
+                    ? pow( $rating, 2 )
213 213
                     : $rating;
214 214
                 return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum;
215 215
             }
Please login to merge, or discard this patch.
plugin/Tinymce/TinymceGenerator.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -8,325 +8,325 @@
 block discarded – undo
8 8
 
9 9
 abstract class TinymceGenerator
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    public $properties;
11
+	/**
12
+	 * @var array
13
+	 */
14
+	public $properties;
15 15
 
16
-    /**
17
-     * @var string
18
-     */
19
-    public $tag;
16
+	/**
17
+	 * @var string
18
+	 */
19
+	public $tag;
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $errors = [];
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $errors = [];
25 25
 
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $required = [];
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $required = [];
30 30
 
31
-    /**
32
-     * @return array
33
-     */
34
-    abstract public function fields();
31
+	/**
32
+	 * @return array
33
+	 */
34
+	abstract public function fields();
35 35
 
36
-    /**
37
-     * @param string $tag
38
-     * @return static
39
-     */
40
-    public function register($tag, array $args)
41
-    {
42
-        $this->tag = $tag;
43
-        $this->properties = wp_parse_args($args, [
44
-            'btn_close' => _x('Close', 'admin-text', 'site-reviews'),
45
-            'btn_okay' => _x('Insert Shortcode', 'admin-text', 'site-reviews'),
46
-            'errors' => $this->errors,
47
-            'fields' => $this->getFields(),
48
-            'label' => '['.$tag.']',
49
-            'required' => $this->required,
50
-            'title' => _x('Shortcode', 'admin-text', 'site-reviews'),
51
-        ]);
52
-        return $this;
53
-    }
36
+	/**
37
+	 * @param string $tag
38
+	 * @return static
39
+	 */
40
+	public function register($tag, array $args)
41
+	{
42
+		$this->tag = $tag;
43
+		$this->properties = wp_parse_args($args, [
44
+			'btn_close' => _x('Close', 'admin-text', 'site-reviews'),
45
+			'btn_okay' => _x('Insert Shortcode', 'admin-text', 'site-reviews'),
46
+			'errors' => $this->errors,
47
+			'fields' => $this->getFields(),
48
+			'label' => '['.$tag.']',
49
+			'required' => $this->required,
50
+			'title' => _x('Shortcode', 'admin-text', 'site-reviews'),
51
+		]);
52
+		return $this;
53
+	}
54 54
 
55
-    /**
56
-     * @return array
57
-     */
58
-    protected function generateFields(array $fields)
59
-    {
60
-        $generatedFields = array_map(function ($field) {
61
-            if (empty($field)) {
62
-                return;
63
-            }
64
-            $field = $this->normalize($field);
65
-            if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) {
66
-                return;
67
-            }
68
-            return $this->$method($field);
69
-        }, $fields);
70
-        return array_values(array_filter($generatedFields));
71
-    }
55
+	/**
56
+	 * @return array
57
+	 */
58
+	protected function generateFields(array $fields)
59
+	{
60
+		$generatedFields = array_map(function ($field) {
61
+			if (empty($field)) {
62
+				return;
63
+			}
64
+			$field = $this->normalize($field);
65
+			if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) {
66
+				return;
67
+			}
68
+			return $this->$method($field);
69
+		}, $fields);
70
+		return array_values(array_filter($generatedFields));
71
+	}
72 72
 
73
-    /**
74
-     * @param string $tooltip
75
-     * @return array
76
-     */
77
-    protected function getCategories($tooltip = '')
78
-    {
79
-        $terms = glsr(Database::class)->getTerms();
80
-        if (empty($terms)) {
81
-            return [];
82
-        }
83
-        return [
84
-            'label' => _x('Category', 'admin-text', 'site-reviews'),
85
-            'name' => 'category',
86
-            'options' => $terms,
87
-            'tooltip' => $tooltip,
88
-            'type' => 'listbox',
89
-        ];
90
-    }
73
+	/**
74
+	 * @param string $tooltip
75
+	 * @return array
76
+	 */
77
+	protected function getCategories($tooltip = '')
78
+	{
79
+		$terms = glsr(Database::class)->getTerms();
80
+		if (empty($terms)) {
81
+			return [];
82
+		}
83
+		return [
84
+			'label' => _x('Category', 'admin-text', 'site-reviews'),
85
+			'name' => 'category',
86
+			'options' => $terms,
87
+			'tooltip' => $tooltip,
88
+			'type' => 'listbox',
89
+		];
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    protected function getFields()
96
-    {
97
-        $fields = $this->generateFields($this->fields());
98
-        if (!empty($this->errors)) {
99
-            $errors = [];
100
-            foreach ($this->required as $name => $alert) {
101
-                if (false === array_search($name, wp_list_pluck($fields, 'name'))) {
102
-                    $errors[] = $this->errors[$name];
103
-                }
104
-            }
105
-            $this->errors = $errors;
106
-        }
107
-        return empty($this->errors)
108
-            ? $fields
109
-            : $this->errors;
110
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	protected function getFields()
96
+	{
97
+		$fields = $this->generateFields($this->fields());
98
+		if (!empty($this->errors)) {
99
+			$errors = [];
100
+			foreach ($this->required as $name => $alert) {
101
+				if (false === array_search($name, wp_list_pluck($fields, 'name'))) {
102
+					$errors[] = $this->errors[$name];
103
+				}
104
+			}
105
+			$this->errors = $errors;
106
+		}
107
+		return empty($this->errors)
108
+			? $fields
109
+			: $this->errors;
110
+	}
111 111
 
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function getHideOptions()
116
-    {
117
-        $reflection = new \ReflectionClass($this);
118
-        $shortname = str_replace('Tinymce', 'Shortcode', $reflection->getShortName());
119
-        $classname = Helper::buildClassName($shortname, 'Shortcodes');
120
-        $hideOptions = glsr($classname)->getHideOptions();
121
-        $options = [];
122
-        foreach ($hideOptions as $name => $tooltip) {
123
-            $options[] = [
124
-                'name' => 'hide_'.$name,
125
-                'text' => $name,
126
-                'tooltip' => $tooltip,
127
-                'type' => 'checkbox',
128
-            ];
129
-        }
130
-        return $options;
131
-    }
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function getHideOptions()
116
+	{
117
+		$reflection = new \ReflectionClass($this);
118
+		$shortname = str_replace('Tinymce', 'Shortcode', $reflection->getShortName());
119
+		$classname = Helper::buildClassName($shortname, 'Shortcodes');
120
+		$hideOptions = glsr($classname)->getHideOptions();
121
+		$options = [];
122
+		foreach ($hideOptions as $name => $tooltip) {
123
+			$options[] = [
124
+				'name' => 'hide_'.$name,
125
+				'text' => $name,
126
+				'tooltip' => $tooltip,
127
+				'type' => 'checkbox',
128
+			];
129
+		}
130
+		return $options;
131
+	}
132 132
 
133
-    /**
134
-     * @param string $tooltip
135
-     * @return array
136
-     */
137
-    protected function getTypes($tooltip = '')
138
-    {
139
-        if (count(glsr()->reviewTypes) < 2) {
140
-            return [];
141
-        }
142
-        return [
143
-            'label' => _x('Type', 'admin-text', 'site-reviews'),
144
-            'name' => 'type',
145
-            'options' => glsr()->reviewTypes,
146
-            'tooltip' => $tooltip,
147
-            'type' => 'listbox',
148
-        ];
149
-    }
133
+	/**
134
+	 * @param string $tooltip
135
+	 * @return array
136
+	 */
137
+	protected function getTypes($tooltip = '')
138
+	{
139
+		if (count(glsr()->reviewTypes) < 2) {
140
+			return [];
141
+		}
142
+		return [
143
+			'label' => _x('Type', 'admin-text', 'site-reviews'),
144
+			'name' => 'type',
145
+			'options' => glsr()->reviewTypes,
146
+			'tooltip' => $tooltip,
147
+			'type' => 'listbox',
148
+		];
149
+	}
150 150
 
151
-    /**
152
-     * @return array
153
-     */
154
-    protected function normalize(array $field)
155
-    {
156
-        return wp_parse_args($field, [
157
-            'items' => [],
158
-            'type' => '',
159
-        ]);
160
-    }
151
+	/**
152
+	 * @return array
153
+	 */
154
+	protected function normalize(array $field)
155
+	{
156
+		return wp_parse_args($field, [
157
+			'items' => [],
158
+			'type' => '',
159
+		]);
160
+	}
161 161
 
162
-    /**
163
-     * @return void|array
164
-     */
165
-    protected function normalizeCheckbox(array $field)
166
-    {
167
-        return $this->normalizeField($field, [
168
-            'checked' => false,
169
-            'label' => '',
170
-            'minHeight' => '',
171
-            'minWidth' => '',
172
-            'name' => false,
173
-            'text' => '',
174
-            'tooltip' => '',
175
-            'type' => '',
176
-            'value' => '',
177
-        ]);
178
-    }
162
+	/**
163
+	 * @return void|array
164
+	 */
165
+	protected function normalizeCheckbox(array $field)
166
+	{
167
+		return $this->normalizeField($field, [
168
+			'checked' => false,
169
+			'label' => '',
170
+			'minHeight' => '',
171
+			'minWidth' => '',
172
+			'name' => false,
173
+			'text' => '',
174
+			'tooltip' => '',
175
+			'type' => '',
176
+			'value' => '',
177
+		]);
178
+	}
179 179
 
180
-    /**
181
-     * @return void|array
182
-     */
183
-    protected function normalizeContainer(array $field)
184
-    {
185
-        if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) {
186
-            return;
187
-        }
188
-        $field['items'] = $this->generateFields($field['items']);
189
-        return $field;
190
-    }
180
+	/**
181
+	 * @return void|array
182
+	 */
183
+	protected function normalizeContainer(array $field)
184
+	{
185
+		if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) {
186
+			return;
187
+		}
188
+		$field['items'] = $this->generateFields($field['items']);
189
+		return $field;
190
+	}
191 191
 
192
-    /**
193
-     * @return void|array
194
-     */
195
-    protected function normalizeField(array $field, array $defaults)
196
-    {
197
-        if ($this->validate($field)) {
198
-            return array_filter(shortcode_atts($defaults, $field), function ($value) {
199
-                return '' !== $value;
200
-            });
201
-        }
202
-    }
192
+	/**
193
+	 * @return void|array
194
+	 */
195
+	protected function normalizeField(array $field, array $defaults)
196
+	{
197
+		if ($this->validate($field)) {
198
+			return array_filter(shortcode_atts($defaults, $field), function ($value) {
199
+				return '' !== $value;
200
+			});
201
+		}
202
+	}
203 203
 
204
-    /**
205
-     * @return void|array
206
-     */
207
-    protected function normalizeListbox(array $field)
208
-    {
209
-        $listbox = $this->normalizeField($field, [
210
-            'label' => '',
211
-            'minWidth' => '',
212
-            'name' => false,
213
-            'options' => [],
214
-            'placeholder' => esc_attr_x('- Select -', 'admin-text', 'site-reviews'),
215
-            'tooltip' => '',
216
-            'type' => '',
217
-            'value' => '',
218
-        ]);
219
-        if (!is_array($listbox)) {
220
-            return;
221
-        }
222
-        if (!array_key_exists('', $listbox['options'])) {
223
-            $listbox['options'] = Arr::prepend($listbox['options'], $listbox['placeholder'], '');
224
-        }
225
-        foreach ($listbox['options'] as $value => $text) {
226
-            $listbox['values'][] = [
227
-                'text' => $text,
228
-                'value' => $value,
229
-            ];
230
-        }
231
-        return $listbox;
232
-    }
204
+	/**
205
+	 * @return void|array
206
+	 */
207
+	protected function normalizeListbox(array $field)
208
+	{
209
+		$listbox = $this->normalizeField($field, [
210
+			'label' => '',
211
+			'minWidth' => '',
212
+			'name' => false,
213
+			'options' => [],
214
+			'placeholder' => esc_attr_x('- Select -', 'admin-text', 'site-reviews'),
215
+			'tooltip' => '',
216
+			'type' => '',
217
+			'value' => '',
218
+		]);
219
+		if (!is_array($listbox)) {
220
+			return;
221
+		}
222
+		if (!array_key_exists('', $listbox['options'])) {
223
+			$listbox['options'] = Arr::prepend($listbox['options'], $listbox['placeholder'], '');
224
+		}
225
+		foreach ($listbox['options'] as $value => $text) {
226
+			$listbox['values'][] = [
227
+				'text' => $text,
228
+				'value' => $value,
229
+			];
230
+		}
231
+		return $listbox;
232
+	}
233 233
 
234
-    /**
235
-     * @return void|array
236
-     */
237
-    protected function normalizePost(array $field)
238
-    {
239
-        if (!is_array($field['query_args'])) {
240
-            $field['query_args'] = [];
241
-        }
242
-        $posts = get_posts(wp_parse_args($field['query_args'], [
243
-            'order' => 'ASC',
244
-            'orderby' => 'title',
245
-            'post_type' => 'post',
246
-            'posts_per_page' => 30,
247
-        ]));
248
-        if (!empty($posts)) {
249
-            $options = [];
250
-            foreach ($posts as $post) {
251
-                $options[$post->ID] = esc_html($post->post_title);
252
-            }
253
-            $field['options'] = $options;
254
-            $field['type'] = 'listbox';
255
-            return $this->normalizeListbox($field);
256
-        }
257
-        $this->validate($field);
258
-    }
234
+	/**
235
+	 * @return void|array
236
+	 */
237
+	protected function normalizePost(array $field)
238
+	{
239
+		if (!is_array($field['query_args'])) {
240
+			$field['query_args'] = [];
241
+		}
242
+		$posts = get_posts(wp_parse_args($field['query_args'], [
243
+			'order' => 'ASC',
244
+			'orderby' => 'title',
245
+			'post_type' => 'post',
246
+			'posts_per_page' => 30,
247
+		]));
248
+		if (!empty($posts)) {
249
+			$options = [];
250
+			foreach ($posts as $post) {
251
+				$options[$post->ID] = esc_html($post->post_title);
252
+			}
253
+			$field['options'] = $options;
254
+			$field['type'] = 'listbox';
255
+			return $this->normalizeListbox($field);
256
+		}
257
+		$this->validate($field);
258
+	}
259 259
 
260
-    /**
261
-     * @return void|array
262
-     */
263
-    protected function normalizeTextbox(array $field)
264
-    {
265
-        return $this->normalizeField($field, [
266
-            'hidden' => false,
267
-            'label' => '',
268
-            'maxLength' => '',
269
-            'minHeight' => '',
270
-            'minWidth' => '',
271
-            'multiline' => false,
272
-            'name' => false,
273
-            'size' => '',
274
-            'text' => '',
275
-            'tooltip' => '',
276
-            'type' => '',
277
-            'value' => '',
278
-        ]);
279
-    }
260
+	/**
261
+	 * @return void|array
262
+	 */
263
+	protected function normalizeTextbox(array $field)
264
+	{
265
+		return $this->normalizeField($field, [
266
+			'hidden' => false,
267
+			'label' => '',
268
+			'maxLength' => '',
269
+			'minHeight' => '',
270
+			'minWidth' => '',
271
+			'multiline' => false,
272
+			'name' => false,
273
+			'size' => '',
274
+			'text' => '',
275
+			'tooltip' => '',
276
+			'type' => '',
277
+			'value' => '',
278
+		]);
279
+	}
280 280
 
281
-    /**
282
-     * @return bool
283
-     */
284
-    protected function validate(array $field)
285
-    {
286
-        $args = shortcode_atts([
287
-            'label' => '',
288
-            'name' => false,
289
-            'required' => false,
290
-        ], $field);
291
-        if (!$args['name']) {
292
-            return false;
293
-        }
294
-        return $this->validateErrors($args) && $this->validateRequired($args);
295
-    }
281
+	/**
282
+	 * @return bool
283
+	 */
284
+	protected function validate(array $field)
285
+	{
286
+		$args = shortcode_atts([
287
+			'label' => '',
288
+			'name' => false,
289
+			'required' => false,
290
+		], $field);
291
+		if (!$args['name']) {
292
+			return false;
293
+		}
294
+		return $this->validateErrors($args) && $this->validateRequired($args);
295
+	}
296 296
 
297
-    /**
298
-     * @return bool
299
-     */
300
-    protected function validateErrors(array $args)
301
-    {
302
-        if (!isset($args['required']['error'])) {
303
-            return true;
304
-        }
305
-        $this->errors[$args['name']] = $this->normalizeContainer([
306
-            'html' => $args['required']['error'],
307
-            'type' => 'container',
308
-        ]);
309
-        return false;
310
-    }
297
+	/**
298
+	 * @return bool
299
+	 */
300
+	protected function validateErrors(array $args)
301
+	{
302
+		if (!isset($args['required']['error'])) {
303
+			return true;
304
+		}
305
+		$this->errors[$args['name']] = $this->normalizeContainer([
306
+			'html' => $args['required']['error'],
307
+			'type' => 'container',
308
+		]);
309
+		return false;
310
+	}
311 311
 
312
-    /**
313
-     * @return bool
314
-     */
315
-    protected function validateRequired(array $args)
316
-    {
317
-        if (false == $args['required']) {
318
-            return true;
319
-        }
320
-        $alert = _x('Some of the shortcode options are required.', 'admin-text', 'site-reviews');
321
-        if (isset($args['required']['alert'])) {
322
-            $alert = $args['required']['alert'];
323
-        } elseif (!empty($args['label'])) {
324
-            $alert = sprintf(
325
-                _x('The "%s" option is required.', 'the option label (admin-text)', 'site-reviews'),
326
-                str_replace(':', '', $args['label'])
327
-            );
328
-        }
329
-        $this->required[$args['name']] = $alert;
330
-        return false;
331
-    }
312
+	/**
313
+	 * @return bool
314
+	 */
315
+	protected function validateRequired(array $args)
316
+	{
317
+		if (false == $args['required']) {
318
+			return true;
319
+		}
320
+		$alert = _x('Some of the shortcode options are required.', 'admin-text', 'site-reviews');
321
+		if (isset($args['required']['alert'])) {
322
+			$alert = $args['required']['alert'];
323
+		} elseif (!empty($args['label'])) {
324
+			$alert = sprintf(
325
+				_x('The "%s" option is required.', 'the option label (admin-text)', 'site-reviews'),
326
+				str_replace(':', '', $args['label'])
327
+			);
328
+		}
329
+		$this->required[$args['name']] = $alert;
330
+		return false;
331
+	}
332 332
 }
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -37,51 +37,51 @@  discard block
 block discarded – undo
37 37
      * @param string $tag
38 38
      * @return static
39 39
      */
40
-    public function register($tag, array $args)
40
+    public function register( $tag, array $args )
41 41
     {
42 42
         $this->tag = $tag;
43
-        $this->properties = wp_parse_args($args, [
44
-            'btn_close' => _x('Close', 'admin-text', 'site-reviews'),
45
-            'btn_okay' => _x('Insert Shortcode', 'admin-text', 'site-reviews'),
43
+        $this->properties = wp_parse_args( $args, [
44
+            'btn_close' => _x( 'Close', 'admin-text', 'site-reviews' ),
45
+            'btn_okay' => _x( 'Insert Shortcode', 'admin-text', 'site-reviews' ),
46 46
             'errors' => $this->errors,
47 47
             'fields' => $this->getFields(),
48 48
             'label' => '['.$tag.']',
49 49
             'required' => $this->required,
50
-            'title' => _x('Shortcode', 'admin-text', 'site-reviews'),
51
-        ]);
50
+            'title' => _x( 'Shortcode', 'admin-text', 'site-reviews' ),
51
+        ] );
52 52
         return $this;
53 53
     }
54 54
 
55 55
     /**
56 56
      * @return array
57 57
      */
58
-    protected function generateFields(array $fields)
58
+    protected function generateFields( array $fields )
59 59
     {
60
-        $generatedFields = array_map(function ($field) {
61
-            if (empty($field)) {
60
+        $generatedFields = array_map( function( $field ) {
61
+            if( empty($field) ) {
62 62
                 return;
63 63
             }
64
-            $field = $this->normalize($field);
65
-            if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) {
64
+            $field = $this->normalize( $field );
65
+            if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ) ) ) {
66 66
                 return;
67 67
             }
68
-            return $this->$method($field);
69
-        }, $fields);
70
-        return array_values(array_filter($generatedFields));
68
+            return $this->$method( $field );
69
+        }, $fields );
70
+        return array_values( array_filter( $generatedFields ) );
71 71
     }
72 72
 
73 73
     /**
74 74
      * @param string $tooltip
75 75
      * @return array
76 76
      */
77
-    protected function getCategories($tooltip = '')
77
+    protected function getCategories( $tooltip = '' )
78 78
     {
79
-        $terms = glsr(Database::class)->getTerms();
80
-        if (empty($terms)) {
79
+        $terms = glsr( Database::class )->getTerms();
80
+        if( empty($terms) ) {
81 81
             return [];
82 82
         }
83 83
         return [
84
-            'label' => _x('Category', 'admin-text', 'site-reviews'),
84
+            'label' => _x( 'Category', 'admin-text', 'site-reviews' ),
85 85
             'name' => 'category',
86 86
             'options' => $terms,
87 87
             'tooltip' => $tooltip,
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
      */
95 95
     protected function getFields()
96 96
     {
97
-        $fields = $this->generateFields($this->fields());
98
-        if (!empty($this->errors)) {
97
+        $fields = $this->generateFields( $this->fields() );
98
+        if( !empty($this->errors) ) {
99 99
             $errors = [];
100
-            foreach ($this->required as $name => $alert) {
101
-                if (false === array_search($name, wp_list_pluck($fields, 'name'))) {
100
+            foreach( $this->required as $name => $alert ) {
101
+                if( false === array_search( $name, wp_list_pluck( $fields, 'name' ) ) ) {
102 102
                     $errors[] = $this->errors[$name];
103 103
                 }
104 104
             }
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
      */
115 115
     protected function getHideOptions()
116 116
     {
117
-        $reflection = new \ReflectionClass($this);
118
-        $shortname = str_replace('Tinymce', 'Shortcode', $reflection->getShortName());
119
-        $classname = Helper::buildClassName($shortname, 'Shortcodes');
120
-        $hideOptions = glsr($classname)->getHideOptions();
117
+        $reflection = new \ReflectionClass( $this );
118
+        $shortname = str_replace( 'Tinymce', 'Shortcode', $reflection->getShortName() );
119
+        $classname = Helper::buildClassName( $shortname, 'Shortcodes' );
120
+        $hideOptions = glsr( $classname )->getHideOptions();
121 121
         $options = [];
122
-        foreach ($hideOptions as $name => $tooltip) {
122
+        foreach( $hideOptions as $name => $tooltip ) {
123 123
             $options[] = [
124 124
                 'name' => 'hide_'.$name,
125 125
                 'text' => $name,
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
      * @param string $tooltip
135 135
      * @return array
136 136
      */
137
-    protected function getTypes($tooltip = '')
137
+    protected function getTypes( $tooltip = '' )
138 138
     {
139
-        if (count(glsr()->reviewTypes) < 2) {
139
+        if( count( glsr()->reviewTypes ) < 2 ) {
140 140
             return [];
141 141
         }
142 142
         return [
143
-            'label' => _x('Type', 'admin-text', 'site-reviews'),
143
+            'label' => _x( 'Type', 'admin-text', 'site-reviews' ),
144 144
             'name' => 'type',
145 145
             'options' => glsr()->reviewTypes,
146 146
             'tooltip' => $tooltip,
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
     /**
152 152
      * @return array
153 153
      */
154
-    protected function normalize(array $field)
154
+    protected function normalize( array $field )
155 155
     {
156
-        return wp_parse_args($field, [
156
+        return wp_parse_args( $field, [
157 157
             'items' => [],
158 158
             'type' => '',
159
-        ]);
159
+        ] );
160 160
     }
161 161
 
162 162
     /**
163 163
      * @return void|array
164 164
      */
165
-    protected function normalizeCheckbox(array $field)
165
+    protected function normalizeCheckbox( array $field )
166 166
     {
167
-        return $this->normalizeField($field, [
167
+        return $this->normalizeField( $field, [
168 168
             'checked' => false,
169 169
             'label' => '',
170 170
             'minHeight' => '',
@@ -174,28 +174,28 @@  discard block
 block discarded – undo
174 174
             'tooltip' => '',
175 175
             'type' => '',
176 176
             'value' => '',
177
-        ]);
177
+        ] );
178 178
     }
179 179
 
180 180
     /**
181 181
      * @return void|array
182 182
      */
183
-    protected function normalizeContainer(array $field)
183
+    protected function normalizeContainer( array $field )
184 184
     {
185
-        if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) {
185
+        if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ) ) {
186 186
             return;
187 187
         }
188
-        $field['items'] = $this->generateFields($field['items']);
188
+        $field['items'] = $this->generateFields( $field['items'] );
189 189
         return $field;
190 190
     }
191 191
 
192 192
     /**
193 193
      * @return void|array
194 194
      */
195
-    protected function normalizeField(array $field, array $defaults)
195
+    protected function normalizeField( array $field, array $defaults )
196 196
     {
197
-        if ($this->validate($field)) {
198
-            return array_filter(shortcode_atts($defaults, $field), function ($value) {
197
+        if( $this->validate( $field ) ) {
198
+            return array_filter( shortcode_atts( $defaults, $field ), function( $value ) {
199 199
                 return '' !== $value;
200 200
             });
201 201
         }
@@ -204,25 +204,25 @@  discard block
 block discarded – undo
204 204
     /**
205 205
      * @return void|array
206 206
      */
207
-    protected function normalizeListbox(array $field)
207
+    protected function normalizeListbox( array $field )
208 208
     {
209
-        $listbox = $this->normalizeField($field, [
209
+        $listbox = $this->normalizeField( $field, [
210 210
             'label' => '',
211 211
             'minWidth' => '',
212 212
             'name' => false,
213 213
             'options' => [],
214
-            'placeholder' => esc_attr_x('- Select -', 'admin-text', 'site-reviews'),
214
+            'placeholder' => esc_attr_x( '- Select -', 'admin-text', 'site-reviews' ),
215 215
             'tooltip' => '',
216 216
             'type' => '',
217 217
             'value' => '',
218
-        ]);
219
-        if (!is_array($listbox)) {
218
+        ] );
219
+        if( !is_array( $listbox ) ) {
220 220
             return;
221 221
         }
222
-        if (!array_key_exists('', $listbox['options'])) {
223
-            $listbox['options'] = Arr::prepend($listbox['options'], $listbox['placeholder'], '');
222
+        if( !array_key_exists( '', $listbox['options'] ) ) {
223
+            $listbox['options'] = Arr::prepend( $listbox['options'], $listbox['placeholder'], '' );
224 224
         }
225
-        foreach ($listbox['options'] as $value => $text) {
225
+        foreach( $listbox['options'] as $value => $text ) {
226 226
             $listbox['values'][] = [
227 227
                 'text' => $text,
228 228
                 'value' => $value,
@@ -234,35 +234,35 @@  discard block
 block discarded – undo
234 234
     /**
235 235
      * @return void|array
236 236
      */
237
-    protected function normalizePost(array $field)
237
+    protected function normalizePost( array $field )
238 238
     {
239
-        if (!is_array($field['query_args'])) {
239
+        if( !is_array( $field['query_args'] ) ) {
240 240
             $field['query_args'] = [];
241 241
         }
242
-        $posts = get_posts(wp_parse_args($field['query_args'], [
242
+        $posts = get_posts( wp_parse_args( $field['query_args'], [
243 243
             'order' => 'ASC',
244 244
             'orderby' => 'title',
245 245
             'post_type' => 'post',
246 246
             'posts_per_page' => 30,
247
-        ]));
248
-        if (!empty($posts)) {
247
+        ] ) );
248
+        if( !empty($posts) ) {
249 249
             $options = [];
250
-            foreach ($posts as $post) {
251
-                $options[$post->ID] = esc_html($post->post_title);
250
+            foreach( $posts as $post ) {
251
+                $options[$post->ID] = esc_html( $post->post_title );
252 252
             }
253 253
             $field['options'] = $options;
254 254
             $field['type'] = 'listbox';
255
-            return $this->normalizeListbox($field);
255
+            return $this->normalizeListbox( $field );
256 256
         }
257
-        $this->validate($field);
257
+        $this->validate( $field );
258 258
     }
259 259
 
260 260
     /**
261 261
      * @return void|array
262 262
      */
263
-    protected function normalizeTextbox(array $field)
263
+    protected function normalizeTextbox( array $field )
264 264
     {
265
-        return $this->normalizeField($field, [
265
+        return $this->normalizeField( $field, [
266 266
             'hidden' => false,
267 267
             'label' => '',
268 268
             'maxLength' => '',
@@ -275,55 +275,55 @@  discard block
 block discarded – undo
275 275
             'tooltip' => '',
276 276
             'type' => '',
277 277
             'value' => '',
278
-        ]);
278
+        ] );
279 279
     }
280 280
 
281 281
     /**
282 282
      * @return bool
283 283
      */
284
-    protected function validate(array $field)
284
+    protected function validate( array $field )
285 285
     {
286
-        $args = shortcode_atts([
286
+        $args = shortcode_atts( [
287 287
             'label' => '',
288 288
             'name' => false,
289 289
             'required' => false,
290
-        ], $field);
291
-        if (!$args['name']) {
290
+        ], $field );
291
+        if( !$args['name'] ) {
292 292
             return false;
293 293
         }
294
-        return $this->validateErrors($args) && $this->validateRequired($args);
294
+        return $this->validateErrors( $args ) && $this->validateRequired( $args );
295 295
     }
296 296
 
297 297
     /**
298 298
      * @return bool
299 299
      */
300
-    protected function validateErrors(array $args)
300
+    protected function validateErrors( array $args )
301 301
     {
302
-        if (!isset($args['required']['error'])) {
302
+        if( !isset($args['required']['error']) ) {
303 303
             return true;
304 304
         }
305
-        $this->errors[$args['name']] = $this->normalizeContainer([
305
+        $this->errors[$args['name']] = $this->normalizeContainer( [
306 306
             'html' => $args['required']['error'],
307 307
             'type' => 'container',
308
-        ]);
308
+        ] );
309 309
         return false;
310 310
     }
311 311
 
312 312
     /**
313 313
      * @return bool
314 314
      */
315
-    protected function validateRequired(array $args)
315
+    protected function validateRequired( array $args )
316 316
     {
317
-        if (false == $args['required']) {
317
+        if( false == $args['required'] ) {
318 318
             return true;
319 319
         }
320
-        $alert = _x('Some of the shortcode options are required.', 'admin-text', 'site-reviews');
321
-        if (isset($args['required']['alert'])) {
320
+        $alert = _x( 'Some of the shortcode options are required.', 'admin-text', 'site-reviews' );
321
+        if( isset($args['required']['alert']) ) {
322 322
             $alert = $args['required']['alert'];
323
-        } elseif (!empty($args['label'])) {
323
+        } elseif( !empty($args['label']) ) {
324 324
             $alert = sprintf(
325
-                _x('The "%s" option is required.', 'the option label (admin-text)', 'site-reviews'),
326
-                str_replace(':', '', $args['label'])
325
+                _x( 'The "%s" option is required.', 'the option label (admin-text)', 'site-reviews' ),
326
+                str_replace( ':', '', $args['label'] )
327 327
             );
328 328
         }
329 329
         $this->required[$args['name']] = $alert;
Please login to merge, or discard this patch.
plugin/Helpers/Arr.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -6,268 +6,268 @@
 block discarded – undo
6 6
 
7 7
 class Arr
8 8
 {
9
-    /**
10
-     * @return bool
11
-     */
12
-    public static function compare(array $arr1, array $arr2)
13
-    {
14
-        sort($arr1);
15
-        sort($arr2);
16
-        return $arr1 == $arr2;
17
-    }
9
+	/**
10
+	 * @return bool
11
+	 */
12
+	public static function compare(array $arr1, array $arr2)
13
+	{
14
+		sort($arr1);
15
+		sort($arr2);
16
+		return $arr1 == $arr2;
17
+	}
18 18
 
19
-    /**
20
-     * @param mixed $array
21
-     * @param bool $explode
22
-     * @return array
23
-     */
24
-    public static function consolidate($array, $explode = true)
25
-    {
26
-        if (is_string($array) && $explode) {
27
-            $array = static::convertFromString($array, function ($item) {
28
-                return '' !== trim($item);
29
-            });
30
-        }
31
-        if (is_object($array)) {
32
-            return get_object_vars($array);
33
-        }
34
-        return is_array($array) ? $array : [];
35
-    }
19
+	/**
20
+	 * @param mixed $array
21
+	 * @param bool $explode
22
+	 * @return array
23
+	 */
24
+	public static function consolidate($array, $explode = true)
25
+	{
26
+		if (is_string($array) && $explode) {
27
+			$array = static::convertFromString($array, function ($item) {
28
+				return '' !== trim($item);
29
+			});
30
+		}
31
+		if (is_object($array)) {
32
+			return get_object_vars($array);
33
+		}
34
+		return is_array($array) ? $array : [];
35
+	}
36 36
 
37
-    /**
38
-     * @return array
39
-     */
40
-    public static function convertFromDotNotation(array $array)
41
-    {
42
-        $results = [];
43
-        foreach ($array as $path => $value) {
44
-            $results = static::set($results, $path, $value);
45
-        }
46
-        return $results;
47
-    }
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public static function convertFromDotNotation(array $array)
41
+	{
42
+		$results = [];
43
+		foreach ($array as $path => $value) {
44
+			$results = static::set($results, $path, $value);
45
+		}
46
+		return $results;
47
+	}
48 48
 
49
-    /**
50
-     * @param string|array $string
51
-     * @param mixed $callback
52
-     * @return array
53
-     */
54
-    public static function convertFromString($string, $callback = null)
55
-    {
56
-        if (!is_array($array = $string)) {
57
-            $array = array_map('trim', explode(',', $string));
58
-        }
59
-        return $callback
60
-            ? array_filter($array, $callback)
61
-            : array_filter($array);
62
-    }
49
+	/**
50
+	 * @param string|array $string
51
+	 * @param mixed $callback
52
+	 * @return array
53
+	 */
54
+	public static function convertFromString($string, $callback = null)
55
+	{
56
+		if (!is_array($array = $string)) {
57
+			$array = array_map('trim', explode(',', $string));
58
+		}
59
+		return $callback
60
+			? array_filter($array, $callback)
61
+			: array_filter($array);
62
+	}
63 63
 
64
-    /**
65
-     * @param bool $flattenValue
66
-     * @param string $prefix
67
-     * @return array
68
-     */
69
-    public static function flatten(array $array, $flattenValue = false, $prefix = '')
70
-    {
71
-        $result = [];
72
-        foreach ($array as $key => $value) {
73
-            $newKey = ltrim($prefix.'.'.$key, '.');
74
-            if (static::isIndexedAndFlat($value)) {
75
-                if ($flattenValue) {
76
-                    $value = '['.implode(', ', $value).']';
77
-                }
78
-            } elseif (is_array($value)) {
79
-                $result = array_merge($result, static::flatten($value, $flattenValue, $newKey));
80
-                continue;
81
-            }
82
-            $result[$newKey] = $value;
83
-        }
84
-        return $result;
85
-    }
64
+	/**
65
+	 * @param bool $flattenValue
66
+	 * @param string $prefix
67
+	 * @return array
68
+	 */
69
+	public static function flatten(array $array, $flattenValue = false, $prefix = '')
70
+	{
71
+		$result = [];
72
+		foreach ($array as $key => $value) {
73
+			$newKey = ltrim($prefix.'.'.$key, '.');
74
+			if (static::isIndexedAndFlat($value)) {
75
+				if ($flattenValue) {
76
+					$value = '['.implode(', ', $value).']';
77
+				}
78
+			} elseif (is_array($value)) {
79
+				$result = array_merge($result, static::flatten($value, $flattenValue, $newKey));
80
+				continue;
81
+			}
82
+			$result[$newKey] = $value;
83
+		}
84
+		return $result;
85
+	}
86 86
 
87
-    /**
88
-     * Get a value from an array of values using a dot-notation path as reference.
89
-     * @param mixed $data
90
-     * @param string $path
91
-     * @param mixed $fallback
92
-     * @return mixed
93
-     */
94
-    public static function get($data, $path = '', $fallback = '')
95
-    {
96
-        $data = static::consolidate($data);
97
-        $keys = explode('.', $path);
98
-        foreach ($keys as $key) {
99
-            if (!isset($data[$key])) {
100
-                return $fallback;
101
-            }
102
-            if (is_object($data[$key])) {
103
-                $data = static::consolidate($data[$key]);
104
-                continue;
105
-            }
106
-            $data = $data[$key];
107
-        }
108
-        return $data;
109
-    }
87
+	/**
88
+	 * Get a value from an array of values using a dot-notation path as reference.
89
+	 * @param mixed $data
90
+	 * @param string $path
91
+	 * @param mixed $fallback
92
+	 * @return mixed
93
+	 */
94
+	public static function get($data, $path = '', $fallback = '')
95
+	{
96
+		$data = static::consolidate($data);
97
+		$keys = explode('.', $path);
98
+		foreach ($keys as $key) {
99
+			if (!isset($data[$key])) {
100
+				return $fallback;
101
+			}
102
+			if (is_object($data[$key])) {
103
+				$data = static::consolidate($data[$key]);
104
+				continue;
105
+			}
106
+			$data = $data[$key];
107
+		}
108
+		return $data;
109
+	}
110 110
 
111
-    /**
112
-     * @param string $key
113
-     * @return array
114
-     */
115
-    public static function insertAfter($key, array $array, array $insert)
116
-    {
117
-        return static::insert($array, $insert, $key, 'after');
118
-    }
111
+	/**
112
+	 * @param string $key
113
+	 * @return array
114
+	 */
115
+	public static function insertAfter($key, array $array, array $insert)
116
+	{
117
+		return static::insert($array, $insert, $key, 'after');
118
+	}
119 119
 
120
-    /**
121
-     * @param string $key
122
-     * @return array
123
-     */
124
-    public static function insertBefore($key, array $array, array $insert)
125
-    {
126
-        return static::insert($array, $insert, $key, 'before');
127
-    }
120
+	/**
121
+	 * @param string $key
122
+	 * @return array
123
+	 */
124
+	public static function insertBefore($key, array $array, array $insert)
125
+	{
126
+		return static::insert($array, $insert, $key, 'before');
127
+	}
128 128
 
129
-    /**
130
-     * @param string $key
131
-     * @param string $position
132
-     * @return array
133
-     */
134
-    public static function insert(array $array, array $insert, $key, $position = 'before')
135
-    {
136
-        $keyPosition = intval(array_search($key, array_keys($array)));
137
-        if ('after' == $position) {
138
-            ++$keyPosition;
139
-        }
140
-        if (false !== $keyPosition) {
141
-            $result = array_slice($array, 0, $keyPosition);
142
-            $result = array_merge($result, $insert);
143
-            return array_merge($result, array_slice($array, $keyPosition));
144
-        }
145
-        return array_merge($array, $insert);
146
-    }
129
+	/**
130
+	 * @param string $key
131
+	 * @param string $position
132
+	 * @return array
133
+	 */
134
+	public static function insert(array $array, array $insert, $key, $position = 'before')
135
+	{
136
+		$keyPosition = intval(array_search($key, array_keys($array)));
137
+		if ('after' == $position) {
138
+			++$keyPosition;
139
+		}
140
+		if (false !== $keyPosition) {
141
+			$result = array_slice($array, 0, $keyPosition);
142
+			$result = array_merge($result, $insert);
143
+			return array_merge($result, array_slice($array, $keyPosition));
144
+		}
145
+		return array_merge($array, $insert);
146
+	}
147 147
 
148
-    /**
149
-     * @param mixed $array
150
-     * @return bool
151
-     */
152
-    public static function isIndexedAndFlat($array)
153
-    {
154
-        if (!is_array($array) || array_filter($array, 'is_array')) {
155
-            return false;
156
-        }
157
-        return wp_is_numeric_array($array);
158
-    }
148
+	/**
149
+	 * @param mixed $array
150
+	 * @return bool
151
+	 */
152
+	public static function isIndexedAndFlat($array)
153
+	{
154
+		if (!is_array($array) || array_filter($array, 'is_array')) {
155
+			return false;
156
+		}
157
+		return wp_is_numeric_array($array);
158
+	}
159 159
 
160
-    /**
161
-     * @param bool $prefixed
162
-     * @return array
163
-     */
164
-    public static function prefixKeys(array $values, $prefixed = true)
165
-    {
166
-        $trim = '_';
167
-        $prefix = $prefixed
168
-            ? $trim
169
-            : '';
170
-        $prefixed = [];
171
-        foreach ($values as $key => $value) {
172
-            $key = trim($key);
173
-            if (0 === strpos($key, $trim)) {
174
-                $key = substr($key, strlen($trim));
175
-            }
176
-            $prefixed[$prefix.$key] = $value;
177
-        }
178
-        return $prefixed;
179
-    }
160
+	/**
161
+	 * @param bool $prefixed
162
+	 * @return array
163
+	 */
164
+	public static function prefixKeys(array $values, $prefixed = true)
165
+	{
166
+		$trim = '_';
167
+		$prefix = $prefixed
168
+			? $trim
169
+			: '';
170
+		$prefixed = [];
171
+		foreach ($values as $key => $value) {
172
+			$key = trim($key);
173
+			if (0 === strpos($key, $trim)) {
174
+				$key = substr($key, strlen($trim));
175
+			}
176
+			$prefixed[$prefix.$key] = $value;
177
+		}
178
+		return $prefixed;
179
+	}
180 180
 
181
-    /**
182
-     * @param array $array
183
-     * @param mixed $value
184
-     * @param mixed $key
185
-     * @return array
186
-     */
187
-    public static function prepend($array, $value, $key = null)
188
-    {
189
-        if (!is_null($key)) {
190
-            return [$key => $value] + $array;
191
-        }
192
-        array_unshift($array, $value);
193
-        return $array;
194
-    }
181
+	/**
182
+	 * @param array $array
183
+	 * @param mixed $value
184
+	 * @param mixed $key
185
+	 * @return array
186
+	 */
187
+	public static function prepend($array, $value, $key = null)
188
+	{
189
+		if (!is_null($key)) {
190
+			return [$key => $value] + $array;
191
+		}
192
+		array_unshift($array, $value);
193
+		return $array;
194
+	}
195 195
 
196
-    /**
197
-     * @param mixed $array
198
-     * @return array
199
-     */
200
-    public static function reindex($array)
201
-    {
202
-        return static::isIndexedAndFlat($array)
203
-            ? array_values($array)
204
-            : $array;
205
-    }
196
+	/**
197
+	 * @param mixed $array
198
+	 * @return array
199
+	 */
200
+	public static function reindex($array)
201
+	{
202
+		return static::isIndexedAndFlat($array)
203
+			? array_values($array)
204
+			: $array;
205
+	}
206 206
 
207
-    /**
208
-     * @return array
209
-     */
210
-    public static function removeEmptyValues(array $array)
211
-    {
212
-        $result = [];
213
-        foreach ($array as $key => $value) {
214
-            if (Helper::isEmpty($value)) {
215
-                continue;
216
-            }
217
-            $result[$key] = is_array($value)
218
-                ? static::removeEmptyValues($value)
219
-                : $value;
220
-        }
221
-        return $result;
222
-    }
207
+	/**
208
+	 * @return array
209
+	 */
210
+	public static function removeEmptyValues(array $array)
211
+	{
212
+		$result = [];
213
+		foreach ($array as $key => $value) {
214
+			if (Helper::isEmpty($value)) {
215
+				continue;
216
+			}
217
+			$result[$key] = is_array($value)
218
+				? static::removeEmptyValues($value)
219
+				: $value;
220
+		}
221
+		return $result;
222
+	}
223 223
 
224
-    /**
225
-     * Set a value to an array of values using a dot-notation path as reference.
226
-     * @param mixed $data
227
-     * @param string $path
228
-     * @param mixed $value
229
-     * @return array
230
-     */
231
-    public static function set($data, $path, $value)
232
-    {
233
-        $token = strtok($path, '.');
234
-        $ref = &$data;
235
-        while (false !== $token) {
236
-            if (is_object($ref)) {
237
-                $ref = &$ref->$token;
238
-            } else {
239
-                $ref = static::consolidate($ref);
240
-                $ref = &$ref[$token];
241
-            }
242
-            $token = strtok('.');
243
-        }
244
-        $ref = $value;
245
-        return $data;
246
-    }
224
+	/**
225
+	 * Set a value to an array of values using a dot-notation path as reference.
226
+	 * @param mixed $data
227
+	 * @param string $path
228
+	 * @param mixed $value
229
+	 * @return array
230
+	 */
231
+	public static function set($data, $path, $value)
232
+	{
233
+		$token = strtok($path, '.');
234
+		$ref = &$data;
235
+		while (false !== $token) {
236
+			if (is_object($ref)) {
237
+				$ref = &$ref->$token;
238
+			} else {
239
+				$ref = static::consolidate($ref);
240
+				$ref = &$ref[$token];
241
+			}
242
+			$token = strtok('.');
243
+		}
244
+		$ref = $value;
245
+		return $data;
246
+	}
247 247
 
248
-    /**
249
-     * @return array
250
-     */
251
-    public static function unique(array $values)
252
-    {
253
-        return static::isIndexedAndFlat($values)
254
-            ? array_values(array_filter(array_unique($values)))
255
-            : $values;
256
-    }
248
+	/**
249
+	 * @return array
250
+	 */
251
+	public static function unique(array $values)
252
+	{
253
+		return static::isIndexedAndFlat($values)
254
+			? array_values(array_filter(array_unique($values)))
255
+			: $values;
256
+	}
257 257
 
258
-    /**
259
-     * @return array
260
-     */
261
-    public static function uniqueInt(array $values)
262
-    {
263
-        return static::unique(array_map('absint', $values));
264
-    }
258
+	/**
259
+	 * @return array
260
+	 */
261
+	public static function uniqueInt(array $values)
262
+	{
263
+		return static::unique(array_map('absint', $values));
264
+	}
265 265
 
266
-    /**
267
-     * @return array
268
-     */
269
-    public static function unprefixKeys(array $values)
270
-    {
271
-        return static::prefixKeys($values, false);
272
-    }
266
+	/**
267
+	 * @return array
268
+	 */
269
+	public static function unprefixKeys(array $values)
270
+	{
271
+		return static::prefixKeys($values, false);
272
+	}
273 273
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * @return bool
11 11
      */
12
-    public static function compare(array $arr1, array $arr2)
12
+    public static function compare( array $arr1, array $arr2 )
13 13
     {
14
-        sort($arr1);
15
-        sort($arr2);
14
+        sort( $arr1 );
15
+        sort( $arr2 );
16 16
         return $arr1 == $arr2;
17 17
     }
18 18
 
@@ -21,27 +21,27 @@  discard block
 block discarded – undo
21 21
      * @param bool $explode
22 22
      * @return array
23 23
      */
24
-    public static function consolidate($array, $explode = true)
24
+    public static function consolidate( $array, $explode = true )
25 25
     {
26
-        if (is_string($array) && $explode) {
27
-            $array = static::convertFromString($array, function ($item) {
28
-                return '' !== trim($item);
26
+        if( is_string( $array ) && $explode ) {
27
+            $array = static::convertFromString( $array, function( $item ) {
28
+                return '' !== trim( $item );
29 29
             });
30 30
         }
31
-        if (is_object($array)) {
32
-            return get_object_vars($array);
31
+        if( is_object( $array ) ) {
32
+            return get_object_vars( $array );
33 33
         }
34
-        return is_array($array) ? $array : [];
34
+        return is_array( $array ) ? $array : [];
35 35
     }
36 36
 
37 37
     /**
38 38
      * @return array
39 39
      */
40
-    public static function convertFromDotNotation(array $array)
40
+    public static function convertFromDotNotation( array $array )
41 41
     {
42 42
         $results = [];
43
-        foreach ($array as $path => $value) {
44
-            $results = static::set($results, $path, $value);
43
+        foreach( $array as $path => $value ) {
44
+            $results = static::set( $results, $path, $value );
45 45
         }
46 46
         return $results;
47 47
     }
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
      * @param mixed $callback
52 52
      * @return array
53 53
      */
54
-    public static function convertFromString($string, $callback = null)
54
+    public static function convertFromString( $string, $callback = null )
55 55
     {
56
-        if (!is_array($array = $string)) {
57
-            $array = array_map('trim', explode(',', $string));
56
+        if( !is_array( $array = $string ) ) {
57
+            $array = array_map( 'trim', explode( ',', $string ) );
58 58
         }
59 59
         return $callback
60
-            ? array_filter($array, $callback)
61
-            : array_filter($array);
60
+            ? array_filter( $array, $callback )
61
+            : array_filter( $array );
62 62
     }
63 63
 
64 64
     /**
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
      * @param string $prefix
67 67
      * @return array
68 68
      */
69
-    public static function flatten(array $array, $flattenValue = false, $prefix = '')
69
+    public static function flatten( array $array, $flattenValue = false, $prefix = '' )
70 70
     {
71 71
         $result = [];
72
-        foreach ($array as $key => $value) {
73
-            $newKey = ltrim($prefix.'.'.$key, '.');
74
-            if (static::isIndexedAndFlat($value)) {
75
-                if ($flattenValue) {
76
-                    $value = '['.implode(', ', $value).']';
72
+        foreach( $array as $key => $value ) {
73
+            $newKey = ltrim( $prefix.'.'.$key, '.' );
74
+            if( static::isIndexedAndFlat( $value ) ) {
75
+                if( $flattenValue ) {
76
+                    $value = '['.implode( ', ', $value ).']';
77 77
                 }
78
-            } elseif (is_array($value)) {
79
-                $result = array_merge($result, static::flatten($value, $flattenValue, $newKey));
78
+            } elseif( is_array( $value ) ) {
79
+                $result = array_merge( $result, static::flatten( $value, $flattenValue, $newKey ) );
80 80
                 continue;
81 81
             }
82 82
             $result[$newKey] = $value;
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
      * @param mixed $fallback
92 92
      * @return mixed
93 93
      */
94
-    public static function get($data, $path = '', $fallback = '')
94
+    public static function get( $data, $path = '', $fallback = '' )
95 95
     {
96
-        $data = static::consolidate($data);
97
-        $keys = explode('.', $path);
98
-        foreach ($keys as $key) {
99
-            if (!isset($data[$key])) {
96
+        $data = static::consolidate( $data );
97
+        $keys = explode( '.', $path );
98
+        foreach( $keys as $key ) {
99
+            if( !isset($data[$key]) ) {
100 100
                 return $fallback;
101 101
             }
102
-            if (is_object($data[$key])) {
103
-                $data = static::consolidate($data[$key]);
102
+            if( is_object( $data[$key] ) ) {
103
+                $data = static::consolidate( $data[$key] );
104 104
                 continue;
105 105
             }
106 106
             $data = $data[$key];
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
      * @param string $key
113 113
      * @return array
114 114
      */
115
-    public static function insertAfter($key, array $array, array $insert)
115
+    public static function insertAfter( $key, array $array, array $insert )
116 116
     {
117
-        return static::insert($array, $insert, $key, 'after');
117
+        return static::insert( $array, $insert, $key, 'after' );
118 118
     }
119 119
 
120 120
     /**
121 121
      * @param string $key
122 122
      * @return array
123 123
      */
124
-    public static function insertBefore($key, array $array, array $insert)
124
+    public static function insertBefore( $key, array $array, array $insert )
125 125
     {
126
-        return static::insert($array, $insert, $key, 'before');
126
+        return static::insert( $array, $insert, $key, 'before' );
127 127
     }
128 128
 
129 129
     /**
@@ -131,47 +131,47 @@  discard block
 block discarded – undo
131 131
      * @param string $position
132 132
      * @return array
133 133
      */
134
-    public static function insert(array $array, array $insert, $key, $position = 'before')
134
+    public static function insert( array $array, array $insert, $key, $position = 'before' )
135 135
     {
136
-        $keyPosition = intval(array_search($key, array_keys($array)));
137
-        if ('after' == $position) {
136
+        $keyPosition = intval( array_search( $key, array_keys( $array ) ) );
137
+        if( 'after' == $position ) {
138 138
             ++$keyPosition;
139 139
         }
140
-        if (false !== $keyPosition) {
141
-            $result = array_slice($array, 0, $keyPosition);
142
-            $result = array_merge($result, $insert);
143
-            return array_merge($result, array_slice($array, $keyPosition));
140
+        if( false !== $keyPosition ) {
141
+            $result = array_slice( $array, 0, $keyPosition );
142
+            $result = array_merge( $result, $insert );
143
+            return array_merge( $result, array_slice( $array, $keyPosition ) );
144 144
         }
145
-        return array_merge($array, $insert);
145
+        return array_merge( $array, $insert );
146 146
     }
147 147
 
148 148
     /**
149 149
      * @param mixed $array
150 150
      * @return bool
151 151
      */
152
-    public static function isIndexedAndFlat($array)
152
+    public static function isIndexedAndFlat( $array )
153 153
     {
154
-        if (!is_array($array) || array_filter($array, 'is_array')) {
154
+        if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) {
155 155
             return false;
156 156
         }
157
-        return wp_is_numeric_array($array);
157
+        return wp_is_numeric_array( $array );
158 158
     }
159 159
 
160 160
     /**
161 161
      * @param bool $prefixed
162 162
      * @return array
163 163
      */
164
-    public static function prefixKeys(array $values, $prefixed = true)
164
+    public static function prefixKeys( array $values, $prefixed = true )
165 165
     {
166 166
         $trim = '_';
167 167
         $prefix = $prefixed
168 168
             ? $trim
169 169
             : '';
170 170
         $prefixed = [];
171
-        foreach ($values as $key => $value) {
172
-            $key = trim($key);
173
-            if (0 === strpos($key, $trim)) {
174
-                $key = substr($key, strlen($trim));
171
+        foreach( $values as $key => $value ) {
172
+            $key = trim( $key );
173
+            if( 0 === strpos( $key, $trim ) ) {
174
+                $key = substr( $key, strlen( $trim ) );
175 175
             }
176 176
             $prefixed[$prefix.$key] = $value;
177 177
         }
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
      * @param mixed $key
185 185
      * @return array
186 186
      */
187
-    public static function prepend($array, $value, $key = null)
187
+    public static function prepend( $array, $value, $key = null )
188 188
     {
189
-        if (!is_null($key)) {
189
+        if( !is_null( $key ) ) {
190 190
             return [$key => $value] + $array;
191 191
         }
192
-        array_unshift($array, $value);
192
+        array_unshift( $array, $value );
193 193
         return $array;
194 194
     }
195 195
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
      * @param mixed $array
198 198
      * @return array
199 199
      */
200
-    public static function reindex($array)
200
+    public static function reindex( $array )
201 201
     {
202
-        return static::isIndexedAndFlat($array)
203
-            ? array_values($array)
202
+        return static::isIndexedAndFlat( $array )
203
+            ? array_values( $array )
204 204
             : $array;
205 205
     }
206 206
 
207 207
     /**
208 208
      * @return array
209 209
      */
210
-    public static function removeEmptyValues(array $array)
210
+    public static function removeEmptyValues( array $array )
211 211
     {
212 212
         $result = [];
213
-        foreach ($array as $key => $value) {
214
-            if (Helper::isEmpty($value)) {
213
+        foreach( $array as $key => $value ) {
214
+            if( Helper::isEmpty( $value ) ) {
215 215
                 continue;
216 216
             }
217
-            $result[$key] = is_array($value)
218
-                ? static::removeEmptyValues($value)
217
+            $result[$key] = is_array( $value )
218
+                ? static::removeEmptyValues( $value )
219 219
                 : $value;
220 220
         }
221 221
         return $result;
@@ -228,18 +228,18 @@  discard block
 block discarded – undo
228 228
      * @param mixed $value
229 229
      * @return array
230 230
      */
231
-    public static function set($data, $path, $value)
231
+    public static function set( $data, $path, $value )
232 232
     {
233
-        $token = strtok($path, '.');
233
+        $token = strtok( $path, '.' );
234 234
         $ref = &$data;
235
-        while (false !== $token) {
236
-            if (is_object($ref)) {
235
+        while( false !== $token ) {
236
+            if( is_object( $ref ) ) {
237 237
                 $ref = &$ref->$token;
238 238
             } else {
239
-                $ref = static::consolidate($ref);
239
+                $ref = static::consolidate( $ref );
240 240
                 $ref = &$ref[$token];
241 241
             }
242
-            $token = strtok('.');
242
+            $token = strtok( '.' );
243 243
         }
244 244
         $ref = $value;
245 245
         return $data;
@@ -248,26 +248,26 @@  discard block
 block discarded – undo
248 248
     /**
249 249
      * @return array
250 250
      */
251
-    public static function unique(array $values)
251
+    public static function unique( array $values )
252 252
     {
253
-        return static::isIndexedAndFlat($values)
254
-            ? array_values(array_filter(array_unique($values)))
253
+        return static::isIndexedAndFlat( $values )
254
+            ? array_values( array_filter( array_unique( $values ) ) )
255 255
             : $values;
256 256
     }
257 257
 
258 258
     /**
259 259
      * @return array
260 260
      */
261
-    public static function uniqueInt(array $values)
261
+    public static function uniqueInt( array $values )
262 262
     {
263
-        return static::unique(array_map('absint', $values));
263
+        return static::unique( array_map( 'absint', $values ) );
264 264
     }
265 265
 
266 266
     /**
267 267
      * @return array
268 268
      */
269
-    public static function unprefixKeys(array $values)
269
+    public static function unprefixKeys( array $values )
270 270
     {
271
-        return static::prefixKeys($values, false);
271
+        return static::prefixKeys( $values, false );
272 272
     }
273 273
 }
Please login to merge, or discard this patch.
plugin/Review.php 2 patches
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -36,238 +36,238 @@
 block discarded – undo
36 36
  */
37 37
 class Review extends Arguments
38 38
 {
39
-    /**
40
-     * @var Arguments
41
-     */
42
-    protected $_meta;
39
+	/**
40
+	 * @var Arguments
41
+	 */
42
+	protected $_meta;
43 43
 
44
-    /**
45
-     * @var \WP_Post
46
-     */
47
-    protected $_post;
44
+	/**
45
+	 * @var \WP_Post
46
+	 */
47
+	protected $_post;
48 48
 
49
-    /**
50
-     * @var object
51
-     */
52
-    protected $_review;
49
+	/**
50
+	 * @var object
51
+	 */
52
+	protected $_review;
53 53
 
54
-    /**
55
-     * @var bool
56
-     */
57
-    protected $hasCheckedModified;
54
+	/**
55
+	 * @var bool
56
+	 */
57
+	protected $hasCheckedModified;
58 58
 
59
-    /**
60
-     * @var int
61
-     */
62
-    protected $id;
59
+	/**
60
+	 * @var int
61
+	 */
62
+	protected $id;
63 63
 
64
-    /**
65
-     * @param array|object $values
66
-     */
67
-    public function __construct($values)
68
-    {
69
-        $values = glsr()->args($values);
70
-        $this->id = Helper::castToInt($values->review_id);
71
-        $args = [];
72
-        $args['assigned_post_ids'] = Arr::uniqueInt(explode(',', $values->post_ids));
73
-        $args['assigned_term_ids'] = Arr::uniqueInt(explode(',', $values->term_ids));
74
-        $args['assigned_user_ids'] = Arr::uniqueInt(explode(',', $values->user_ids));
75
-        $args['author'] = $values->name;
76
-        $args['author_id'] = Helper::castToInt($values->author_id);
77
-        $args['avatar'] = $values->avatar;
78
-        $args['content'] = $values->content;
79
-        $args['custom'] = new Arguments($this->meta()->custom);
80
-        $args['date'] = $values->date;
81
-        $args['email'] = $values->email;
82
-        $args['ID'] = $this->id;
83
-        $args['ip_address'] = $values->ip_address;
84
-        $args['is_approved'] = Helper::castToBool($values->is_approved);
85
-        $args['is_modified'] = false;
86
-        $args['is_pinned'] = Helper::castToBool($values->is_pinned);
87
-        $args['rating'] = Helper::castToInt($values->rating);
88
-        $args['rating_id'] = Helper::castToInt($values->ID);
89
-        $args['response'] = $this->meta()->response;
90
-        $args['status'] = $values->status;
91
-        $args['title'] = $values->title;
92
-        $args['type'] = $values->type;
93
-        $args['url'] = $values->url;
94
-        parent::__construct($args);
95
-    }
64
+	/**
65
+	 * @param array|object $values
66
+	 */
67
+	public function __construct($values)
68
+	{
69
+		$values = glsr()->args($values);
70
+		$this->id = Helper::castToInt($values->review_id);
71
+		$args = [];
72
+		$args['assigned_post_ids'] = Arr::uniqueInt(explode(',', $values->post_ids));
73
+		$args['assigned_term_ids'] = Arr::uniqueInt(explode(',', $values->term_ids));
74
+		$args['assigned_user_ids'] = Arr::uniqueInt(explode(',', $values->user_ids));
75
+		$args['author'] = $values->name;
76
+		$args['author_id'] = Helper::castToInt($values->author_id);
77
+		$args['avatar'] = $values->avatar;
78
+		$args['content'] = $values->content;
79
+		$args['custom'] = new Arguments($this->meta()->custom);
80
+		$args['date'] = $values->date;
81
+		$args['email'] = $values->email;
82
+		$args['ID'] = $this->id;
83
+		$args['ip_address'] = $values->ip_address;
84
+		$args['is_approved'] = Helper::castToBool($values->is_approved);
85
+		$args['is_modified'] = false;
86
+		$args['is_pinned'] = Helper::castToBool($values->is_pinned);
87
+		$args['rating'] = Helper::castToInt($values->rating);
88
+		$args['rating_id'] = Helper::castToInt($values->ID);
89
+		$args['response'] = $this->meta()->response;
90
+		$args['status'] = $values->status;
91
+		$args['title'] = $values->title;
92
+		$args['type'] = $values->type;
93
+		$args['url'] = $values->url;
94
+		parent::__construct($args);
95
+	}
96 96
 
97
-    /**
98
-     * @return string
99
-     */
100
-    public function __toString()
101
-    {
102
-        return (string) $this->build();
103
-    }
97
+	/**
98
+	 * @return string
99
+	 */
100
+	public function __toString()
101
+	{
102
+		return (string) $this->build();
103
+	}
104 104
 
105
-    /**
106
-     * @return ReviewHtml
107
-     */
108
-    public function build(array $args = [])
109
-    {
110
-        if (empty($this->id)) {
111
-            return new ReviewHtml($this);
112
-        }
113
-        $partial = glsr(SiteReviewsPartial::class);
114
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
115
-        $partial->options = Arr::flatten(glsr(OptionManager::class)->all());
116
-        return $partial->buildReview($this);
117
-    }
105
+	/**
106
+	 * @return ReviewHtml
107
+	 */
108
+	public function build(array $args = [])
109
+	{
110
+		if (empty($this->id)) {
111
+			return new ReviewHtml($this);
112
+		}
113
+		$partial = glsr(SiteReviewsPartial::class);
114
+		$partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
115
+		$partial->options = Arr::flatten(glsr(OptionManager::class)->all());
116
+		return $partial->buildReview($this);
117
+	}
118 118
 
119
-    /**
120
-     * @return string
121
-     */
122
-    public function date()
123
-    {
124
-        return get_date_from_gmt($this->get('date'), 'F j, Y');
125
-    }
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function date()
123
+	{
124
+		return get_date_from_gmt($this->get('date'), 'F j, Y');
125
+	}
126 126
 
127
-    /**
128
-     * @param int|\WP_Post $postId
129
-     * @return bool
130
-     */
131
-    public static function isEditable($postId)
132
-    {
133
-        $post = get_post($postId);
134
-        return static::isReview($post)
135
-            && post_type_supports(glsr()->post_type, 'title')
136
-            && 'local' === glsr(Query::class)->review($post->ID)->type;
137
-    }
127
+	/**
128
+	 * @param int|\WP_Post $postId
129
+	 * @return bool
130
+	 */
131
+	public static function isEditable($postId)
132
+	{
133
+		$post = get_post($postId);
134
+		return static::isReview($post)
135
+			&& post_type_supports(glsr()->post_type, 'title')
136
+			&& 'local' === glsr(Query::class)->review($post->ID)->type;
137
+	}
138 138
 
139
-    /**
140
-     * @param int|\WP_Post $postId
141
-     * @return bool
142
-     */
143
-    public static function isReview($postId)
144
-    {
145
-        return glsr()->post_type === get_post_type($postId);
146
-    }
139
+	/**
140
+	 * @param int|\WP_Post $postId
141
+	 * @return bool
142
+	 */
143
+	public static function isReview($postId)
144
+	{
145
+		return glsr()->post_type === get_post_type($postId);
146
+	}
147 147
 
148
-    /**
149
-     * @return bool
150
-     */
151
-    public function isValid()
152
-    {
153
-        return !empty($this->ID);
154
-    }
148
+	/**
149
+	 * @return bool
150
+	 */
151
+	public function isValid()
152
+	{
153
+		return !empty($this->ID);
154
+	}
155 155
 
156
-    /**
157
-     * @return Arguments
158
-     */
159
-    public function meta()
160
-    {
161
-        if (!$this->_meta instanceof Arguments) {
162
-            $meta = Arr::consolidate(get_post_meta($this->id));
163
-            $meta = array_map('array_shift', array_filter($meta));
164
-            $meta = Arr::unprefixKeys(array_filter($meta, 'strlen'));
165
-            $meta = array_map('maybe_unserialize', $meta);
166
-            $meta = glsr(CreateReviewDefaults::class)->restrict($meta);
167
-            $this->_meta = new Arguments($meta);
168
-        }
169
-        return $this->_meta;
170
-    }
156
+	/**
157
+	 * @return Arguments
158
+	 */
159
+	public function meta()
160
+	{
161
+		if (!$this->_meta instanceof Arguments) {
162
+			$meta = Arr::consolidate(get_post_meta($this->id));
163
+			$meta = array_map('array_shift', array_filter($meta));
164
+			$meta = Arr::unprefixKeys(array_filter($meta, 'strlen'));
165
+			$meta = array_map('maybe_unserialize', $meta);
166
+			$meta = glsr(CreateReviewDefaults::class)->restrict($meta);
167
+			$this->_meta = new Arguments($meta);
168
+		}
169
+		return $this->_meta;
170
+	}
171 171
 
172
-    /**
173
-     * @param mixed $key
174
-     * @return bool
175
-     */
176
-    public function offsetExists($key)
177
-    {
178
-        return parent::offsetExists($key) || !is_null($this->custom->$key);
179
-    }
172
+	/**
173
+	 * @param mixed $key
174
+	 * @return bool
175
+	 */
176
+	public function offsetExists($key)
177
+	{
178
+		return parent::offsetExists($key) || !is_null($this->custom->$key);
179
+	}
180 180
 
181
-    /**
182
-     * @param mixed $key
183
-     * @return mixed
184
-     */
185
-    public function offsetGet($key)
186
-    {
187
-        $alternateKeys = [
188
-            'approved' => 'is_approved',
189
-            'modified' => 'is_modified',
190
-            'pinned' => 'is_pinned',
191
-            'user_id' => 'author_id',
192
-        ];
193
-        if (array_key_exists($key, $alternateKeys)) {
194
-            return $this->offsetGet($alternateKeys[$key]);
195
-        }
196
-        if ('is_modified' === $key) {
197
-            return $this->isModified();
198
-        }
199
-        if (is_null($value = parent::offsetGet($key))) {
200
-            return $this->custom->$key;
201
-        }
202
-        return $value;
203
-    }
181
+	/**
182
+	 * @param mixed $key
183
+	 * @return mixed
184
+	 */
185
+	public function offsetGet($key)
186
+	{
187
+		$alternateKeys = [
188
+			'approved' => 'is_approved',
189
+			'modified' => 'is_modified',
190
+			'pinned' => 'is_pinned',
191
+			'user_id' => 'author_id',
192
+		];
193
+		if (array_key_exists($key, $alternateKeys)) {
194
+			return $this->offsetGet($alternateKeys[$key]);
195
+		}
196
+		if ('is_modified' === $key) {
197
+			return $this->isModified();
198
+		}
199
+		if (is_null($value = parent::offsetGet($key))) {
200
+			return $this->custom->$key;
201
+		}
202
+		return $value;
203
+	}
204 204
 
205
-    /**
206
-     * @param mixed $key
207
-     * @return void
208
-     */
209
-    public function offsetSet($key, $value)
210
-    {
211
-        // This class is read-only
212
-    }
205
+	/**
206
+	 * @param mixed $key
207
+	 * @return void
208
+	 */
209
+	public function offsetSet($key, $value)
210
+	{
211
+		// This class is read-only
212
+	}
213 213
 
214
-    /**
215
-     * @param mixed $key
216
-     * @return void
217
-     */
218
-    public function offsetUnset($key)
219
-    {
220
-        // This class is read-only
221
-    }
214
+	/**
215
+	 * @param mixed $key
216
+	 * @return void
217
+	 */
218
+	public function offsetUnset($key)
219
+	{
220
+		// This class is read-only
221
+	}
222 222
 
223
-    /**
224
-     * @return \WP_Post|null
225
-     */
226
-    public function post()
227
-    {
228
-        if (!$this->_post instanceof \WP_Post) {
229
-            $this->_post = get_post($this->id);
230
-        }
231
-        return $this->_post;
232
-    }
223
+	/**
224
+	 * @return \WP_Post|null
225
+	 */
226
+	public function post()
227
+	{
228
+		if (!$this->_post instanceof \WP_Post) {
229
+			$this->_post = get_post($this->id);
230
+		}
231
+		return $this->_post;
232
+	}
233 233
 
234
-    /**
235
-     * @return void
236
-     */
237
-    public function render()
238
-    {
239
-        echo $this->build();
240
-    }
234
+	/**
235
+	 * @return void
236
+	 */
237
+	public function render()
238
+	{
239
+		echo $this->build();
240
+	}
241 241
 
242
-    /**
243
-     * @return string
244
-     */
245
-    public function rating()
246
-    {
247
-        return glsr_star_rating($this->get('rating'));
248
-    }
242
+	/**
243
+	 * @return string
244
+	 */
245
+	public function rating()
246
+	{
247
+		return glsr_star_rating($this->get('rating'));
248
+	}
249 249
 
250
-    /**
251
-     * @return string
252
-     */
253
-    public function type()
254
-    {
255
-        $type = $this->get('type');
256
-        return array_key_exists($type, glsr()->reviewTypes)
257
-            ? glsr()->reviewTypes[$type]
258
-            : _x('Unknown', 'admin-text', 'site-reviews');
259
-    }
250
+	/**
251
+	 * @return string
252
+	 */
253
+	public function type()
254
+	{
255
+		$type = $this->get('type');
256
+		return array_key_exists($type, glsr()->reviewTypes)
257
+			? glsr()->reviewTypes[$type]
258
+			: _x('Unknown', 'admin-text', 'site-reviews');
259
+	}
260 260
 
261
-    /**
262
-     * @return bool
263
-     */
264
-    protected function isModified()
265
-    {
266
-        if (!$this->hasCheckedModified) {
267
-            $modified = glsr(Query::class)->hasRevisions($this->ID);
268
-            $this->set('is_modified', $modified);
269
-            $this->hasCheckedModified = true;
270
-        }
271
-        return $this->get('is_modified');
272
-    }
261
+	/**
262
+	 * @return bool
263
+	 */
264
+	protected function isModified()
265
+	{
266
+		if (!$this->hasCheckedModified) {
267
+			$modified = glsr(Query::class)->hasRevisions($this->ID);
268
+			$this->set('is_modified', $modified);
269
+			$this->hasCheckedModified = true;
270
+		}
271
+		return $this->get('is_modified');
272
+	}
273 273
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -64,34 +64,34 @@  discard block
 block discarded – undo
64 64
     /**
65 65
      * @param array|object $values
66 66
      */
67
-    public function __construct($values)
67
+    public function __construct( $values )
68 68
     {
69
-        $values = glsr()->args($values);
70
-        $this->id = Helper::castToInt($values->review_id);
69
+        $values = glsr()->args( $values );
70
+        $this->id = Helper::castToInt( $values->review_id );
71 71
         $args = [];
72
-        $args['assigned_post_ids'] = Arr::uniqueInt(explode(',', $values->post_ids));
73
-        $args['assigned_term_ids'] = Arr::uniqueInt(explode(',', $values->term_ids));
74
-        $args['assigned_user_ids'] = Arr::uniqueInt(explode(',', $values->user_ids));
72
+        $args['assigned_post_ids'] = Arr::uniqueInt( explode( ',', $values->post_ids ) );
73
+        $args['assigned_term_ids'] = Arr::uniqueInt( explode( ',', $values->term_ids ) );
74
+        $args['assigned_user_ids'] = Arr::uniqueInt( explode( ',', $values->user_ids ) );
75 75
         $args['author'] = $values->name;
76
-        $args['author_id'] = Helper::castToInt($values->author_id);
76
+        $args['author_id'] = Helper::castToInt( $values->author_id );
77 77
         $args['avatar'] = $values->avatar;
78 78
         $args['content'] = $values->content;
79
-        $args['custom'] = new Arguments($this->meta()->custom);
79
+        $args['custom'] = new Arguments( $this->meta()->custom );
80 80
         $args['date'] = $values->date;
81 81
         $args['email'] = $values->email;
82 82
         $args['ID'] = $this->id;
83 83
         $args['ip_address'] = $values->ip_address;
84
-        $args['is_approved'] = Helper::castToBool($values->is_approved);
84
+        $args['is_approved'] = Helper::castToBool( $values->is_approved );
85 85
         $args['is_modified'] = false;
86
-        $args['is_pinned'] = Helper::castToBool($values->is_pinned);
87
-        $args['rating'] = Helper::castToInt($values->rating);
88
-        $args['rating_id'] = Helper::castToInt($values->ID);
86
+        $args['is_pinned'] = Helper::castToBool( $values->is_pinned );
87
+        $args['rating'] = Helper::castToInt( $values->rating );
88
+        $args['rating_id'] = Helper::castToInt( $values->ID );
89 89
         $args['response'] = $this->meta()->response;
90 90
         $args['status'] = $values->status;
91 91
         $args['title'] = $values->title;
92 92
         $args['type'] = $values->type;
93 93
         $args['url'] = $values->url;
94
-        parent::__construct($args);
94
+        parent::__construct( $args );
95 95
     }
96 96
 
97 97
     /**
@@ -99,21 +99,21 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function __toString()
101 101
     {
102
-        return (string) $this->build();
102
+        return (string)$this->build();
103 103
     }
104 104
 
105 105
     /**
106 106
      * @return ReviewHtml
107 107
      */
108
-    public function build(array $args = [])
108
+    public function build( array $args = [] )
109 109
     {
110
-        if (empty($this->id)) {
111
-            return new ReviewHtml($this);
110
+        if( empty($this->id) ) {
111
+            return new ReviewHtml( $this );
112 112
         }
113
-        $partial = glsr(SiteReviewsPartial::class);
114
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
115
-        $partial->options = Arr::flatten(glsr(OptionManager::class)->all());
116
-        return $partial->buildReview($this);
113
+        $partial = glsr( SiteReviewsPartial::class );
114
+        $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args );
115
+        $partial->options = Arr::flatten( glsr( OptionManager::class )->all() );
116
+        return $partial->buildReview( $this );
117 117
     }
118 118
 
119 119
     /**
@@ -121,28 +121,28 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function date()
123 123
     {
124
-        return get_date_from_gmt($this->get('date'), 'F j, Y');
124
+        return get_date_from_gmt( $this->get( 'date' ), 'F j, Y' );
125 125
     }
126 126
 
127 127
     /**
128 128
      * @param int|\WP_Post $postId
129 129
      * @return bool
130 130
      */
131
-    public static function isEditable($postId)
131
+    public static function isEditable( $postId )
132 132
     {
133
-        $post = get_post($postId);
134
-        return static::isReview($post)
135
-            && post_type_supports(glsr()->post_type, 'title')
136
-            && 'local' === glsr(Query::class)->review($post->ID)->type;
133
+        $post = get_post( $postId );
134
+        return static::isReview( $post )
135
+            && post_type_supports( glsr()->post_type, 'title' )
136
+            && 'local' === glsr( Query::class )->review( $post->ID )->type;
137 137
     }
138 138
 
139 139
     /**
140 140
      * @param int|\WP_Post $postId
141 141
      * @return bool
142 142
      */
143
-    public static function isReview($postId)
143
+    public static function isReview( $postId )
144 144
     {
145
-        return glsr()->post_type === get_post_type($postId);
145
+        return glsr()->post_type === get_post_type( $postId );
146 146
     }
147 147
 
148 148
     /**
@@ -158,13 +158,13 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function meta()
160 160
     {
161
-        if (!$this->_meta instanceof Arguments) {
162
-            $meta = Arr::consolidate(get_post_meta($this->id));
163
-            $meta = array_map('array_shift', array_filter($meta));
164
-            $meta = Arr::unprefixKeys(array_filter($meta, 'strlen'));
165
-            $meta = array_map('maybe_unserialize', $meta);
166
-            $meta = glsr(CreateReviewDefaults::class)->restrict($meta);
167
-            $this->_meta = new Arguments($meta);
161
+        if( !$this->_meta instanceof Arguments ) {
162
+            $meta = Arr::consolidate( get_post_meta( $this->id ) );
163
+            $meta = array_map( 'array_shift', array_filter( $meta ) );
164
+            $meta = Arr::unprefixKeys( array_filter( $meta, 'strlen' ) );
165
+            $meta = array_map( 'maybe_unserialize', $meta );
166
+            $meta = glsr( CreateReviewDefaults::class )->restrict( $meta );
167
+            $this->_meta = new Arguments( $meta );
168 168
         }
169 169
         return $this->_meta;
170 170
     }
@@ -173,16 +173,16 @@  discard block
 block discarded – undo
173 173
      * @param mixed $key
174 174
      * @return bool
175 175
      */
176
-    public function offsetExists($key)
176
+    public function offsetExists( $key )
177 177
     {
178
-        return parent::offsetExists($key) || !is_null($this->custom->$key);
178
+        return parent::offsetExists( $key ) || !is_null( $this->custom->$key );
179 179
     }
180 180
 
181 181
     /**
182 182
      * @param mixed $key
183 183
      * @return mixed
184 184
      */
185
-    public function offsetGet($key)
185
+    public function offsetGet( $key )
186 186
     {
187 187
         $alternateKeys = [
188 188
             'approved' => 'is_approved',
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
             'pinned' => 'is_pinned',
191 191
             'user_id' => 'author_id',
192 192
         ];
193
-        if (array_key_exists($key, $alternateKeys)) {
194
-            return $this->offsetGet($alternateKeys[$key]);
193
+        if( array_key_exists( $key, $alternateKeys ) ) {
194
+            return $this->offsetGet( $alternateKeys[$key] );
195 195
         }
196
-        if ('is_modified' === $key) {
196
+        if( 'is_modified' === $key ) {
197 197
             return $this->isModified();
198 198
         }
199
-        if (is_null($value = parent::offsetGet($key))) {
199
+        if( is_null( $value = parent::offsetGet( $key ) ) ) {
200 200
             return $this->custom->$key;
201 201
         }
202 202
         return $value;
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      * @param mixed $key
207 207
      * @return void
208 208
      */
209
-    public function offsetSet($key, $value)
209
+    public function offsetSet( $key, $value )
210 210
     {
211 211
         // This class is read-only
212 212
     }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * @param mixed $key
216 216
      * @return void
217 217
      */
218
-    public function offsetUnset($key)
218
+    public function offsetUnset( $key )
219 219
     {
220 220
         // This class is read-only
221 221
     }
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
      */
226 226
     public function post()
227 227
     {
228
-        if (!$this->_post instanceof \WP_Post) {
229
-            $this->_post = get_post($this->id);
228
+        if( !$this->_post instanceof \WP_Post ) {
229
+            $this->_post = get_post( $this->id );
230 230
         }
231 231
         return $this->_post;
232 232
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function rating()
246 246
     {
247
-        return glsr_star_rating($this->get('rating'));
247
+        return glsr_star_rating( $this->get( 'rating' ) );
248 248
     }
249 249
 
250 250
     /**
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
      */
253 253
     public function type()
254 254
     {
255
-        $type = $this->get('type');
256
-        return array_key_exists($type, glsr()->reviewTypes)
255
+        $type = $this->get( 'type' );
256
+        return array_key_exists( $type, glsr()->reviewTypes )
257 257
             ? glsr()->reviewTypes[$type]
258
-            : _x('Unknown', 'admin-text', 'site-reviews');
258
+            : _x( 'Unknown', 'admin-text', 'site-reviews' );
259 259
     }
260 260
 
261 261
     /**
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
      */
264 264
     protected function isModified()
265 265
     {
266
-        if (!$this->hasCheckedModified) {
267
-            $modified = glsr(Query::class)->hasRevisions($this->ID);
268
-            $this->set('is_modified', $modified);
266
+        if( !$this->hasCheckedModified ) {
267
+            $modified = glsr( Query::class )->hasRevisions( $this->ID );
268
+            $this->set( 'is_modified', $modified );
269 269
             $this->hasCheckedModified = true;
270 270
         }
271
-        return $this->get('is_modified');
271
+        return $this->get( 'is_modified' );
272 272
     }
273 273
 }
Please login to merge, or discard this patch.
deprecated.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -3,170 +3,170 @@  discard block
 block discarded – undo
3 3
 defined('WPINC') || die;
4 4
 
5 5
 add_action('plugins_loaded', function () {
6
-    if (!glsr()->filterBool('support/deprecated/v4', true)) {
7
-        return;
8
-    }
9
-    // Unprotected review meta has been deprecated
10
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
11
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
12
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
13
-            return $data;
14
-        }
15
-        $message = sprintf(
16
-            'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
17
-            $metaKey
18
-        );
19
-        glsr()->append('deprecated', $message);
20
-        return get_post_meta($postId, '_'.$metaKey, $single);
21
-    }, 10, 4);
22
-
23
-    // Modules/Html/Template.php
24
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
25
-        $search = '{{ navigation }}';
26
-        if (false !== strpos($template, $search)) {
27
-            $context['navigation'] = $context['pagination'];
28
-            $message = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
29
-            glsr()->append('deprecated', $message);
30
-        }
31
-        return $context;
32
-    }, 10, 2);
33
-
34
-    // Modules/Html/Template.php
35
-    add_filter('site-reviews/build/template/reviews', function ($template) {
36
-        if (has_filter('site-reviews/reviews/pagination-wrapper')) {
37
-            $message = 'The "site-reviews/reviews/pagination-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
38
-            glsr()->append('deprecated', $message);
39
-        }
40
-        if (has_filter('site-reviews/reviews/reviews-wrapper')) {
41
-            $message = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
42
-            glsr()->append('deprecated', $message);
43
-        }
44
-        return $template;
45
-    });
46
-
47
-    // Database/ReviewManager.php
48
-    add_action('site-reviews/review/created', function ($review) {
49
-        if (has_action('site-reviews/local/review/create')) {
50
-            $message = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
51
-            glsr()->append('deprecated', $message);
52
-            glsr()->action('local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
53
-        }
54
-    }, 9);
55
-
56
-    // Commands/CreateReview.php
57
-    add_action('site-reviews/review/submitted', function ($review) {
58
-        if (has_action('site-reviews/local/review/submitted')) {
59
-            $message = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
60
-            glsr()->append('deprecated', $message);
61
-            glsr()->action('local/review/submitted', null, $review);
62
-        }
63
-        if (has_filter('site-reviews/local/review/submitted/message')) {
64
-            $message = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
65
-            glsr()->append('deprecated', $message);
66
-        }
67
-    }, 9);
68
-
69
-    // Database/ReviewManager.php
70
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
71
-        if (has_filter('site-reviews/local/review')) {
72
-            $message = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
73
-            glsr()->append('deprecated', $message);
74
-            return glsr()->filterArray('local/review', $values, $command);
75
-        }
76
-        return $values;
77
-    }, 9, 2);
78
-
79
-    // Commands/EnqueuePublicAssets.php
80
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
81
-        if (has_filter('site-reviews/enqueue/localize')) {
82
-            $message = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
83
-            glsr()->append('deprecated', $message);
84
-            return glsr()->filterArray('enqueue/localize', $variables);
85
-        }
86
-        return $variables;
87
-    }, 9);
88
-
89
-    // Modules/Rating.php
90
-    add_filter('site-reviews/rating/average', function ($average) {
91
-        if (has_filter('site-reviews/average/rating')) {
92
-            $message = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
93
-            glsr()->append('deprecated', $message);
94
-        }
95
-        return $average;
96
-    }, 9);
97
-
98
-    // Modules/Rating.php
99
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
100
-        if (has_filter('site-reviews/bayesian/ranking')) {
101
-            $message = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
102
-            glsr()->append('deprecated', $message);
103
-        }
104
-        return $ranking;
105
-    }, 9);
106
-
107
-    // Modules/Html/Partials/SiteReviews.php
108
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
109
-        if (has_filter('site-reviews/reviews/review/text')) {
110
-            $message = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
111
-            glsr()->append('deprecated', $message);
112
-        }
113
-        if (has_filter('site-reviews/reviews/review/title')) {
114
-            $message = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
115
-            glsr()->append('deprecated', $message);
116
-        }
117
-        return $renderedFields;
118
-    }, 9);
119
-
120
-    // Modules/Html/Partials/SiteReviews.php
121
-    add_filter('site-reviews/review/build/before', function ($review) {
122
-        if (has_filter('site-reviews/rendered/review')) {
123
-            $message = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
124
-            glsr()->append('deprecated', $message);
125
-        }
126
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
127
-            $message = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
128
-            glsr()->append('deprecated', $message);
129
-        }
130
-        if (has_filter('site-reviews/rendered/review/order')) {
131
-            $message = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
132
-            glsr()->append('deprecated', $message);
133
-        }
134
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
135
-            $message = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
136
-            glsr()->append('deprecated', $message);
137
-        }
138
-        if (has_filter('site-reviews/reviews/navigation_links')) {
139
-            $message = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
140
-            glsr()->append('deprecated', $message);
141
-        }
142
-        return $review;
143
-    }, 9);
144
-
145
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
146
-        if (has_filter('site-reviews/validate/review/submission')) {
147
-            $message = 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.';
148
-            glsr()->append('deprecated', $message);
149
-            return glsr()->filterBool('validate/review/submission', $result, $request);
150
-        }
151
-        return $result;
152
-    }, 9, 2);
153
-
154
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
155
-        if (has_filter('site-reviews/addon/views/file')) {
156
-            $message = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
157
-            glsr()->append('deprecated', $message);
158
-            $file = glsr()->filterString('addon/views/file', $file, $view, $data);
159
-        }
160
-        return $file;
161
-    }, 9, 3);
6
+	if (!glsr()->filterBool('support/deprecated/v4', true)) {
7
+		return;
8
+	}
9
+	// Unprotected review meta has been deprecated
10
+	add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
11
+		$metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
12
+		if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
13
+			return $data;
14
+		}
15
+		$message = sprintf(
16
+			'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
17
+			$metaKey
18
+		);
19
+		glsr()->append('deprecated', $message);
20
+		return get_post_meta($postId, '_'.$metaKey, $single);
21
+	}, 10, 4);
22
+
23
+	// Modules/Html/Template.php
24
+	add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
25
+		$search = '{{ navigation }}';
26
+		if (false !== strpos($template, $search)) {
27
+			$context['navigation'] = $context['pagination'];
28
+			$message = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
29
+			glsr()->append('deprecated', $message);
30
+		}
31
+		return $context;
32
+	}, 10, 2);
33
+
34
+	// Modules/Html/Template.php
35
+	add_filter('site-reviews/build/template/reviews', function ($template) {
36
+		if (has_filter('site-reviews/reviews/pagination-wrapper')) {
37
+			$message = 'The "site-reviews/reviews/pagination-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
38
+			glsr()->append('deprecated', $message);
39
+		}
40
+		if (has_filter('site-reviews/reviews/reviews-wrapper')) {
41
+			$message = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
42
+			glsr()->append('deprecated', $message);
43
+		}
44
+		return $template;
45
+	});
46
+
47
+	// Database/ReviewManager.php
48
+	add_action('site-reviews/review/created', function ($review) {
49
+		if (has_action('site-reviews/local/review/create')) {
50
+			$message = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
51
+			glsr()->append('deprecated', $message);
52
+			glsr()->action('local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
53
+		}
54
+	}, 9);
55
+
56
+	// Commands/CreateReview.php
57
+	add_action('site-reviews/review/submitted', function ($review) {
58
+		if (has_action('site-reviews/local/review/submitted')) {
59
+			$message = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
60
+			glsr()->append('deprecated', $message);
61
+			glsr()->action('local/review/submitted', null, $review);
62
+		}
63
+		if (has_filter('site-reviews/local/review/submitted/message')) {
64
+			$message = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
65
+			glsr()->append('deprecated', $message);
66
+		}
67
+	}, 9);
68
+
69
+	// Database/ReviewManager.php
70
+	add_filter('site-reviews/create/review-values', function ($values, $command) {
71
+		if (has_filter('site-reviews/local/review')) {
72
+			$message = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
73
+			glsr()->append('deprecated', $message);
74
+			return glsr()->filterArray('local/review', $values, $command);
75
+		}
76
+		return $values;
77
+	}, 9, 2);
78
+
79
+	// Commands/EnqueuePublicAssets.php
80
+	add_filter('site-reviews/enqueue/public/localize', function ($variables) {
81
+		if (has_filter('site-reviews/enqueue/localize')) {
82
+			$message = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
83
+			glsr()->append('deprecated', $message);
84
+			return glsr()->filterArray('enqueue/localize', $variables);
85
+		}
86
+		return $variables;
87
+	}, 9);
88
+
89
+	// Modules/Rating.php
90
+	add_filter('site-reviews/rating/average', function ($average) {
91
+		if (has_filter('site-reviews/average/rating')) {
92
+			$message = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
93
+			glsr()->append('deprecated', $message);
94
+		}
95
+		return $average;
96
+	}, 9);
97
+
98
+	// Modules/Rating.php
99
+	add_filter('site-reviews/rating/ranking', function ($ranking) {
100
+		if (has_filter('site-reviews/bayesian/ranking')) {
101
+			$message = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
102
+			glsr()->append('deprecated', $message);
103
+		}
104
+		return $ranking;
105
+	}, 9);
106
+
107
+	// Modules/Html/Partials/SiteReviews.php
108
+	add_filter('site-reviews/review/build/after', function ($renderedFields) {
109
+		if (has_filter('site-reviews/reviews/review/text')) {
110
+			$message = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
111
+			glsr()->append('deprecated', $message);
112
+		}
113
+		if (has_filter('site-reviews/reviews/review/title')) {
114
+			$message = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
115
+			glsr()->append('deprecated', $message);
116
+		}
117
+		return $renderedFields;
118
+	}, 9);
119
+
120
+	// Modules/Html/Partials/SiteReviews.php
121
+	add_filter('site-reviews/review/build/before', function ($review) {
122
+		if (has_filter('site-reviews/rendered/review')) {
123
+			$message = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
124
+			glsr()->append('deprecated', $message);
125
+		}
126
+		if (has_filter('site-reviews/rendered/review/meta/order')) {
127
+			$message = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
128
+			glsr()->append('deprecated', $message);
129
+		}
130
+		if (has_filter('site-reviews/rendered/review/order')) {
131
+			$message = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
132
+			glsr()->append('deprecated', $message);
133
+		}
134
+		if (has_filter('site-reviews/rendered/review-form/login-register')) {
135
+			$message = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
136
+			glsr()->append('deprecated', $message);
137
+		}
138
+		if (has_filter('site-reviews/reviews/navigation_links')) {
139
+			$message = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
140
+			glsr()->append('deprecated', $message);
141
+		}
142
+		return $review;
143
+	}, 9);
144
+
145
+	add_filter('site-reviews/validate/custom', function ($result, $request) {
146
+		if (has_filter('site-reviews/validate/review/submission')) {
147
+			$message = 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.';
148
+			glsr()->append('deprecated', $message);
149
+			return glsr()->filterBool('validate/review/submission', $result, $request);
150
+		}
151
+		return $result;
152
+	}, 9, 2);
153
+
154
+	add_filter('site-reviews/views/file', function ($file, $view, $data) {
155
+		if (has_filter('site-reviews/addon/views/file')) {
156
+			$message = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
157
+			glsr()->append('deprecated', $message);
158
+			$file = glsr()->filterString('addon/views/file', $file, $view, $data);
159
+		}
160
+		return $file;
161
+	}, 9, 3);
162 162
 });
163 163
 
164 164
 add_action('wp_footer', function () {
165
-    $notices = array_keys(array_flip(glsr()->retrieve('deprecated', [])));
166
-    natsort($notices);
167
-    foreach ($notices as $notice) {
168
-        glsr_log()->warning($notice);
169
-    }
165
+	$notices = array_keys(array_flip(glsr()->retrieve('deprecated', [])));
166
+	natsort($notices);
167
+	foreach ($notices as $notice) {
168
+		glsr_log()->warning($notice);
169
+	}
170 170
 });
171 171
 
172 172
 /**
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
  */
176 176
 function glsr_calculate_ratings()
177 177
 {
178
-    glsr_log()->error(sprintf(
179
-        _x('The %s function has been deprecated and removed, please update your code.', 'admin-text', 'site-reviews'), 
180
-        'glsr_calculate_ratings()'
181
-    ));
178
+	glsr_log()->error(sprintf(
179
+		_x('The %s function has been deprecated and removed, please update your code.', 'admin-text', 'site-reviews'), 
180
+		'glsr_calculate_ratings()'
181
+	));
182 182
 }
183 183
 
184 184
 /**
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
  */
187 187
 function glsr_get_rating($args = array())
188 188
 {
189
-    glsr_log()->warning(sprintf(
190
-        _x('The %s function has been deprecated and will be removed in a future version, please use %s instead.', 'admin-text', 'site-reviews'), 
191
-        'glsr_get_rating()',
192
-        'glsr_get_ratings()'
193
-    ));
194
-    return glsr_get_ratings($args);
189
+	glsr_log()->warning(sprintf(
190
+		_x('The %s function has been deprecated and will be removed in a future version, please use %s instead.', 'admin-text', 'site-reviews'), 
191
+		'glsr_get_rating()',
192
+		'glsr_get_ratings()'
193
+	));
194
+	return glsr_get_ratings($args);
195 195
 }
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1,171 +1,171 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-defined('WPINC') || die;
3
+defined( 'WPINC' ) || die;
4 4
 
5
-add_action('plugins_loaded', function () {
6
-    if (!glsr()->filterBool('support/deprecated/v4', true)) {
5
+add_action( 'plugins_loaded', function() {
6
+    if( !glsr()->filterBool( 'support/deprecated/v4', true ) ) {
7 7
         return;
8 8
     }
9 9
     // Unprotected review meta has been deprecated
10
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
11
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
12
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
+    add_filter( 'get_post_metadata', function( $data, $postId, $metaKey, $single ) {
11
+        $metaKeys = array_keys( glsr( 'Defaults\CreateReviewDefaults' )->defaults() );
12
+        if( !in_array( $metaKey, $metaKeys ) || glsr()->post_type != get_post_type( $postId ) ) {
13 13
             return $data;
14 14
         }
15 15
         $message = sprintf(
16 16
             'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
17 17
             $metaKey
18 18
         );
19
-        glsr()->append('deprecated', $message);
20
-        return get_post_meta($postId, '_'.$metaKey, $single);
21
-    }, 10, 4);
19
+        glsr()->append( 'deprecated', $message );
20
+        return get_post_meta( $postId, '_'.$metaKey, $single );
21
+    }, 10, 4 );
22 22
 
23 23
     // Modules/Html/Template.php
24
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
24
+    add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) {
25 25
         $search = '{{ navigation }}';
26
-        if (false !== strpos($template, $search)) {
26
+        if( false !== strpos( $template, $search ) ) {
27 27
             $context['navigation'] = $context['pagination'];
28 28
             $message = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
29
-            glsr()->append('deprecated', $message);
29
+            glsr()->append( 'deprecated', $message );
30 30
         }
31 31
         return $context;
32
-    }, 10, 2);
32
+    }, 10, 2 );
33 33
 
34 34
     // Modules/Html/Template.php
35
-    add_filter('site-reviews/build/template/reviews', function ($template) {
36
-        if (has_filter('site-reviews/reviews/pagination-wrapper')) {
35
+    add_filter( 'site-reviews/build/template/reviews', function( $template ) {
36
+        if( has_filter( 'site-reviews/reviews/pagination-wrapper' ) ) {
37 37
             $message = 'The "site-reviews/reviews/pagination-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
38
-            glsr()->append('deprecated', $message);
38
+            glsr()->append( 'deprecated', $message );
39 39
         }
40
-        if (has_filter('site-reviews/reviews/reviews-wrapper')) {
40
+        if( has_filter( 'site-reviews/reviews/reviews-wrapper' ) ) {
41 41
             $message = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.';
42
-            glsr()->append('deprecated', $message);
42
+            glsr()->append( 'deprecated', $message );
43 43
         }
44 44
         return $template;
45 45
     });
46 46
 
47 47
     // Database/ReviewManager.php
48
-    add_action('site-reviews/review/created', function ($review) {
49
-        if (has_action('site-reviews/local/review/create')) {
48
+    add_action( 'site-reviews/review/created', function( $review ) {
49
+        if( has_action( 'site-reviews/local/review/create' ) ) {
50 50
             $message = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
51
-            glsr()->append('deprecated', $message);
52
-            glsr()->action('local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
51
+            glsr()->append( 'deprecated', $message );
52
+            glsr()->action( 'local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID );
53 53
         }
54
-    }, 9);
54
+    }, 9 );
55 55
 
56 56
     // Commands/CreateReview.php
57
-    add_action('site-reviews/review/submitted', function ($review) {
58
-        if (has_action('site-reviews/local/review/submitted')) {
57
+    add_action( 'site-reviews/review/submitted', function( $review ) {
58
+        if( has_action( 'site-reviews/local/review/submitted' ) ) {
59 59
             $message = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
60
-            glsr()->append('deprecated', $message);
61
-            glsr()->action('local/review/submitted', null, $review);
60
+            glsr()->append( 'deprecated', $message );
61
+            glsr()->action( 'local/review/submitted', null, $review );
62 62
         }
63
-        if (has_filter('site-reviews/local/review/submitted/message')) {
63
+        if( has_filter( 'site-reviews/local/review/submitted/message' ) ) {
64 64
             $message = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
65
-            glsr()->append('deprecated', $message);
65
+            glsr()->append( 'deprecated', $message );
66 66
         }
67
-    }, 9);
67
+    }, 9 );
68 68
 
69 69
     // Database/ReviewManager.php
70
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
71
-        if (has_filter('site-reviews/local/review')) {
70
+    add_filter( 'site-reviews/create/review-values', function( $values, $command ) {
71
+        if( has_filter( 'site-reviews/local/review' ) ) {
72 72
             $message = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
73
-            glsr()->append('deprecated', $message);
74
-            return glsr()->filterArray('local/review', $values, $command);
73
+            glsr()->append( 'deprecated', $message );
74
+            return glsr()->filterArray( 'local/review', $values, $command );
75 75
         }
76 76
         return $values;
77
-    }, 9, 2);
77
+    }, 9, 2 );
78 78
 
79 79
     // Commands/EnqueuePublicAssets.php
80
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
81
-        if (has_filter('site-reviews/enqueue/localize')) {
80
+    add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) {
81
+        if( has_filter( 'site-reviews/enqueue/localize' ) ) {
82 82
             $message = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
83
-            glsr()->append('deprecated', $message);
84
-            return glsr()->filterArray('enqueue/localize', $variables);
83
+            glsr()->append( 'deprecated', $message );
84
+            return glsr()->filterArray( 'enqueue/localize', $variables );
85 85
         }
86 86
         return $variables;
87
-    }, 9);
87
+    }, 9 );
88 88
 
89 89
     // Modules/Rating.php
90
-    add_filter('site-reviews/rating/average', function ($average) {
91
-        if (has_filter('site-reviews/average/rating')) {
90
+    add_filter( 'site-reviews/rating/average', function( $average ) {
91
+        if( has_filter( 'site-reviews/average/rating' ) ) {
92 92
             $message = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
93
-            glsr()->append('deprecated', $message);
93
+            glsr()->append( 'deprecated', $message );
94 94
         }
95 95
         return $average;
96
-    }, 9);
96
+    }, 9 );
97 97
 
98 98
     // Modules/Rating.php
99
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
100
-        if (has_filter('site-reviews/bayesian/ranking')) {
99
+    add_filter( 'site-reviews/rating/ranking', function( $ranking ) {
100
+        if( has_filter( 'site-reviews/bayesian/ranking' ) ) {
101 101
             $message = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
102
-            glsr()->append('deprecated', $message);
102
+            glsr()->append( 'deprecated', $message );
103 103
         }
104 104
         return $ranking;
105
-    }, 9);
105
+    }, 9 );
106 106
 
107 107
     // Modules/Html/Partials/SiteReviews.php
108
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
109
-        if (has_filter('site-reviews/reviews/review/text')) {
108
+    add_filter( 'site-reviews/review/build/after', function( $renderedFields ) {
109
+        if( has_filter( 'site-reviews/reviews/review/text' ) ) {
110 110
             $message = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
111
-            glsr()->append('deprecated', $message);
111
+            glsr()->append( 'deprecated', $message );
112 112
         }
113
-        if (has_filter('site-reviews/reviews/review/title')) {
113
+        if( has_filter( 'site-reviews/reviews/review/title' ) ) {
114 114
             $message = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
115
-            glsr()->append('deprecated', $message);
115
+            glsr()->append( 'deprecated', $message );
116 116
         }
117 117
         return $renderedFields;
118
-    }, 9);
118
+    }, 9 );
119 119
 
120 120
     // Modules/Html/Partials/SiteReviews.php
121
-    add_filter('site-reviews/review/build/before', function ($review) {
122
-        if (has_filter('site-reviews/rendered/review')) {
121
+    add_filter( 'site-reviews/review/build/before', function( $review ) {
122
+        if( has_filter( 'site-reviews/rendered/review' ) ) {
123 123
             $message = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
124
-            glsr()->append('deprecated', $message);
124
+            glsr()->append( 'deprecated', $message );
125 125
         }
126
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
126
+        if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) {
127 127
             $message = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
128
-            glsr()->append('deprecated', $message);
128
+            glsr()->append( 'deprecated', $message );
129 129
         }
130
-        if (has_filter('site-reviews/rendered/review/order')) {
130
+        if( has_filter( 'site-reviews/rendered/review/order' ) ) {
131 131
             $message = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
132
-            glsr()->append('deprecated', $message);
132
+            glsr()->append( 'deprecated', $message );
133 133
         }
134
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
134
+        if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) {
135 135
             $message = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
136
-            glsr()->append('deprecated', $message);
136
+            glsr()->append( 'deprecated', $message );
137 137
         }
138
-        if (has_filter('site-reviews/reviews/navigation_links')) {
138
+        if( has_filter( 'site-reviews/reviews/navigation_links' ) ) {
139 139
             $message = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
140
-            glsr()->append('deprecated', $message);
140
+            glsr()->append( 'deprecated', $message );
141 141
         }
142 142
         return $review;
143
-    }, 9);
143
+    }, 9 );
144 144
 
145
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
146
-        if (has_filter('site-reviews/validate/review/submission')) {
145
+    add_filter( 'site-reviews/validate/custom', function( $result, $request ) {
146
+        if( has_filter( 'site-reviews/validate/review/submission' ) ) {
147 147
             $message = 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.';
148
-            glsr()->append('deprecated', $message);
149
-            return glsr()->filterBool('validate/review/submission', $result, $request);
148
+            glsr()->append( 'deprecated', $message );
149
+            return glsr()->filterBool( 'validate/review/submission', $result, $request );
150 150
         }
151 151
         return $result;
152
-    }, 9, 2);
152
+    }, 9, 2 );
153 153
 
154
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
155
-        if (has_filter('site-reviews/addon/views/file')) {
154
+    add_filter( 'site-reviews/views/file', function( $file, $view, $data ) {
155
+        if( has_filter( 'site-reviews/addon/views/file' ) ) {
156 156
             $message = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
157
-            glsr()->append('deprecated', $message);
158
-            $file = glsr()->filterString('addon/views/file', $file, $view, $data);
157
+            glsr()->append( 'deprecated', $message );
158
+            $file = glsr()->filterString( 'addon/views/file', $file, $view, $data );
159 159
         }
160 160
         return $file;
161
-    }, 9, 3);
161
+    }, 9, 3 );
162 162
 });
163 163
 
164
-add_action('wp_footer', function () {
165
-    $notices = array_keys(array_flip(glsr()->retrieve('deprecated', [])));
166
-    natsort($notices);
167
-    foreach ($notices as $notice) {
168
-        glsr_log()->warning($notice);
164
+add_action( 'wp_footer', function() {
165
+    $notices = array_keys( array_flip( glsr()->retrieve( 'deprecated', [] ) ) );
166
+    natsort( $notices );
167
+    foreach( $notices as $notice ) {
168
+        glsr_log()->warning( $notice );
169 169
     }
170 170
 });
171 171
 
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
  */
176 176
 function glsr_calculate_ratings()
177 177
 {
178
-    glsr_log()->error(sprintf(
179
-        _x('The %s function has been deprecated and removed, please update your code.', 'admin-text', 'site-reviews'), 
178
+    glsr_log()->error( sprintf(
179
+        _x( 'The %s function has been deprecated and removed, please update your code.', 'admin-text', 'site-reviews' ), 
180 180
         'glsr_calculate_ratings()'
181
-    ));
181
+    ) );
182 182
 }
183 183
 
184 184
 /**
185 185
  * @return object
186 186
  */
187
-function glsr_get_rating($args = array())
187
+function glsr_get_rating( $args = array() )
188 188
 {
189
-    glsr_log()->warning(sprintf(
190
-        _x('The %s function has been deprecated and will be removed in a future version, please use %s instead.', 'admin-text', 'site-reviews'), 
189
+    glsr_log()->warning( sprintf(
190
+        _x( 'The %s function has been deprecated and will be removed in a future version, please use %s instead.', 'admin-text', 'site-reviews' ), 
191 191
         'glsr_get_rating()',
192 192
         'glsr_get_ratings()'
193
-    ));
194
-    return glsr_get_ratings($args);
193
+    ) );
194
+    return glsr_get_ratings( $args );
195 195
 }
Please login to merge, or discard this patch.
uninstall.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,44 +6,44 @@
 block discarded – undo
6 6
 require_once $file;
7 7
 
8 8
 if (!(new GL_Plugin_Check_v4($file))->isValid()) {
9
-    return;
9
+	return;
10 10
 }
11 11
 
12 12
 global $wpdb;
13 13
 $uninstallOption = glsr_get_option('general.delete_data_on_uninstall');
14 14
 
15 15
 if (in_array($uninstallOption, ['all', 'minimal'])) {
16
-    foreach (range(1, glsr()->version('major')) as $version) {
17
-        delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey($version));
18
-    }
19
-    delete_option('_glsr_trustalyze');
20
-    delete_option('widget_glsr_site-reviews');
21
-    delete_option('widget_glsr_site-reviews-form');
22
-    delete_option('widget_glsr_site-reviews-summary');
23
-    delete_option(glsr()->id.'activated');
24
-    delete_transient('glsr_migrations');
25
-    delete_transient(glsr()->id.'_cloudflare_ips');
26
-    delete_transient(glsr()->id.'_remote_post_test');
27
-    wp_cache_delete(glsr()->id);
28
-    $wpdb->query("
16
+	foreach (range(1, glsr()->version('major')) as $version) {
17
+		delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey($version));
18
+	}
19
+	delete_option('_glsr_trustalyze');
20
+	delete_option('widget_glsr_site-reviews');
21
+	delete_option('widget_glsr_site-reviews-form');
22
+	delete_option('widget_glsr_site-reviews-summary');
23
+	delete_option(glsr()->id.'activated');
24
+	delete_transient('glsr_migrations');
25
+	delete_transient(glsr()->id.'_cloudflare_ips');
26
+	delete_transient(glsr()->id.'_remote_post_test');
27
+	wp_cache_delete(glsr()->id);
28
+	$wpdb->query("
29 29
         OPTIMIZE TABLE {$wpdb->options}
30 30
     ");
31
-    $wpdb->query("
31
+	$wpdb->query("
32 32
         DELETE FROM {$wpdb->usermeta} WHERE meta_key = '_glsr_notices'
33 33
     ");
34 34
 }
35 35
 if ('all' === $uninstallOption) {
36
-    $wpdb->query($wpdb->prepare("
36
+	$wpdb->query($wpdb->prepare("
37 37
         DELETE p, tr, pm
38 38
         FROM {$wpdb->posts} p
39 39
         LEFT JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)
40 40
         LEFT JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id)
41 41
         WHERE p.post_type = %s", 
42
-        glsr()->post_type
43
-    ));
44
-    $prefix = $wpdb->prefix.glsr()->prefix;
45
-    $wpdb->query("DROP TABLE {$prefix}assigned_posts");
46
-    $wpdb->query("DROP TABLE {$prefix}assigned_terms");
47
-    $wpdb->query("DROP TABLE {$prefix}assigned_users");
48
-    $wpdb->query("DROP TABLE {$prefix}ratings");
42
+		glsr()->post_type
43
+	));
44
+	$prefix = $wpdb->prefix.glsr()->prefix;
45
+	$wpdb->query("DROP TABLE {$prefix}assigned_posts");
46
+	$wpdb->query("DROP TABLE {$prefix}assigned_terms");
47
+	$wpdb->query("DROP TABLE {$prefix}assigned_users");
48
+	$wpdb->query("DROP TABLE {$prefix}ratings");
49 49
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,49 +1,49 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-defined('WP_UNINSTALL_PLUGIN') || die;
3
+defined( 'WP_UNINSTALL_PLUGIN' ) || die;
4 4
 
5 5
 $file = __DIR__.'/site-reviews.php';
6 6
 require_once $file;
7 7
 
8
-if (!(new GL_Plugin_Check_v4($file))->isValid()) {
8
+if( !(new GL_Plugin_Check_v4( $file ))->isValid() ) {
9 9
     return;
10 10
 }
11 11
 
12 12
 global $wpdb;
13
-$uninstallOption = glsr_get_option('general.delete_data_on_uninstall');
13
+$uninstallOption = glsr_get_option( 'general.delete_data_on_uninstall' );
14 14
 
15
-if (in_array($uninstallOption, ['all', 'minimal'])) {
16
-    foreach (range(1, glsr()->version('major')) as $version) {
17
-        delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey($version));
15
+if( in_array( $uninstallOption, ['all', 'minimal'] ) ) {
16
+    foreach( range( 1, glsr()->version( 'major' ) ) as $version ) {
17
+        delete_option( GeminiLabs\SiteReviews\Database\OptionManager::databaseKey( $version ) );
18 18
     }
19
-    delete_option('_glsr_trustalyze');
20
-    delete_option('widget_glsr_site-reviews');
21
-    delete_option('widget_glsr_site-reviews-form');
22
-    delete_option('widget_glsr_site-reviews-summary');
23
-    delete_option(glsr()->id.'activated');
24
-    delete_transient('glsr_migrations');
25
-    delete_transient(glsr()->id.'_cloudflare_ips');
26
-    delete_transient(glsr()->id.'_remote_post_test');
27
-    wp_cache_delete(glsr()->id);
28
-    $wpdb->query("
19
+    delete_option( '_glsr_trustalyze' );
20
+    delete_option( 'widget_glsr_site-reviews' );
21
+    delete_option( 'widget_glsr_site-reviews-form' );
22
+    delete_option( 'widget_glsr_site-reviews-summary' );
23
+    delete_option( glsr()->id.'activated' );
24
+    delete_transient( 'glsr_migrations' );
25
+    delete_transient( glsr()->id.'_cloudflare_ips' );
26
+    delete_transient( glsr()->id.'_remote_post_test' );
27
+    wp_cache_delete( glsr()->id );
28
+    $wpdb->query( "
29 29
         OPTIMIZE TABLE {$wpdb->options}
30
-    ");
31
-    $wpdb->query("
30
+    " );
31
+    $wpdb->query( "
32 32
         DELETE FROM {$wpdb->usermeta} WHERE meta_key = '_glsr_notices'
33
-    ");
33
+    " );
34 34
 }
35
-if ('all' === $uninstallOption) {
36
-    $wpdb->query($wpdb->prepare("
35
+if( 'all' === $uninstallOption ) {
36
+    $wpdb->query( $wpdb->prepare( "
37 37
         DELETE p, tr, pm
38 38
         FROM {$wpdb->posts} p
39 39
         LEFT JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)
40 40
         LEFT JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id)
41 41
         WHERE p.post_type = %s", 
42 42
         glsr()->post_type
43
-    ));
43
+    ) );
44 44
     $prefix = $wpdb->prefix.glsr()->prefix;
45
-    $wpdb->query("DROP TABLE {$prefix}assigned_posts");
46
-    $wpdb->query("DROP TABLE {$prefix}assigned_terms");
47
-    $wpdb->query("DROP TABLE {$prefix}assigned_users");
48
-    $wpdb->query("DROP TABLE {$prefix}ratings");
45
+    $wpdb->query( "DROP TABLE {$prefix}assigned_posts" );
46
+    $wpdb->query( "DROP TABLE {$prefix}assigned_terms" );
47
+    $wpdb->query( "DROP TABLE {$prefix}assigned_users" );
48
+    $wpdb->query( "DROP TABLE {$prefix}ratings" );
49 49
 }
Please login to merge, or discard this patch.
views/partials/editor/metabox-assigned-to.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <div class="glsr-search-box" id="glsr-search-posts">
4 4
     <span class="glsr-spinner"><span class="spinner"></span></span>
5
-    <input type="search" class="glsr-search-input" autocomplete="off" placeholder="<?= esc_attr_x('Type to search...', 'admin-text', 'site-reviews'); ?>">
6
-    <?php wp_nonce_field('search-posts', '_search_nonce', false); ?>
5
+    <input type="search" class="glsr-search-input" autocomplete="off" placeholder="<?= esc_attr_x( 'Type to search...', 'admin-text', 'site-reviews' ); ?>">
6
+    <?php wp_nonce_field( 'search-posts', '_search_nonce', false ); ?>
7 7
     <span class="glsr-search-results"></span>
8
-    <p><?= _x('Search here for a page or post that you would like to assign this review to. You may search by title or ID.', 'admin-text', 'site-reviews'); ?></p>
8
+    <p><?= _x( 'Search here for a page or post that you would like to assign this review to. You may search by title or ID.', 'admin-text', 'site-reviews' ); ?></p>
9 9
     <span class="description"><?= $templates; ?></span>
10 10
 </div>
11 11
 
12 12
 <script type="text/html" id="tmpl-glsr-assigned-post">
13
-<?php include glsr()->path('views/partials/editor/assigned-post.php'); ?>
13
+<?php include glsr()->path( 'views/partials/editor/assigned-post.php' ); ?>
14 14
 </script>
Please login to merge, or discard this patch.
views/partials/editor/assigned-post.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <span class="glsr-assigned-post">
4 4
     <input type="hidden" name="assigned_to[]" value="{{ data.id }}">
5 5
     <button type="button" class="glsr-remove-button">
6 6
         <span class="glsr-remove-icon" aria-hidden="true"></span>
7
-        <span class="screen-reader-text"><?= _x('Remove assignment', 'admin-text', 'site-reviews'); ?></span>
7
+        <span class="screen-reader-text"><?= _x( 'Remove assignment', 'admin-text', 'site-reviews' ); ?></span>
8 8
     </button>
9 9
     <a href="{{ data.url }}">{{ data.title }}</a>
10 10
 </span>
Please login to merge, or discard this patch.
views/partials/notices/rate.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <div class="notice notice-success is-dismissible glsr-notice" data-dismiss="rate">
2 2
     <p>Hi there, thanks for using Site Reviews! I hope you are finding it useful and that it has exceeded your expectations. In turn, would you consider giving it a rating on WordPress?</p>
3 3
     <p class="actions">
4
-        <a id="glsr-rate-now" class="button button-primary" href="https://wordpress.org/plugins/site-reviews/#reviews" target="_blank"><?= _x('Rate the plugin', 'admin-text', 'site-reviews'); ?></a>
5
-        <a id="glsr-rate-later" href="#" style="margin-left:10px"><?= _x('Remind me later', 'admin-text', 'site-reviews'); ?></a>
6
-        <a id="glsr-rate-never" href="#" style="margin-left:10px"><?= _x('Don\'t show again', 'admin-text', 'site-reviews'); ?></a>
4
+        <a id="glsr-rate-now" class="button button-primary" href="https://wordpress.org/plugins/site-reviews/#reviews" target="_blank"><?= _x( 'Rate the plugin', 'admin-text', 'site-reviews' ); ?></a>
5
+        <a id="glsr-rate-later" href="#" style="margin-left:10px"><?= _x( 'Remind me later', 'admin-text', 'site-reviews' ); ?></a>
6
+        <a id="glsr-rate-never" href="#" style="margin-left:10px"><?= _x( 'Don\'t show again', 'admin-text', 'site-reviews' ); ?></a>
7 7
     </p>
8 8
 </div>
Please login to merge, or discard this patch.