Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Modules/Html/Partials/SiteReviewsSummary.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -11,197 +11,197 @@
 block discarded – undo
11 11
 
12 12
 class SiteReviewsSummary implements PartialContract
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    protected $args;
18
-
19
-    /**
20
-     * @var float
21
-     */
22
-    protected $averageRating;
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    protected $ratingCounts;
28
-
29
-    /**
30
-     * {@inheritdoc}
31
-     */
32
-    public function build(array $args = [])
33
-    {
34
-        $this->args = $args;
35
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
37
-            return '';
38
-        }
39
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
40
-        $this->generateSchema();
41
-        return glsr(Template::class)->build('templates/reviews-summary', [
42
-            'context' => [
43
-                'assigned_to' => $this->args['assigned_to'],
44
-                'category' => $this->args['category'],
45
-                'class' => $this->getClass(),
46
-                'id' => $this->args['id'],
47
-                'percentages' => $this->buildPercentage(),
48
-                'rating' => $this->buildRating(),
49
-                'stars' => $this->buildStars(),
50
-                'text' => $this->buildText(),
51
-            ],
52
-        ]);
53
-    }
54
-
55
-    /**
56
-     * @return void|string
57
-     */
58
-    protected function buildPercentage()
59
-    {
60
-        if ($this->isHidden('bars')) {
61
-            return;
62
-        }
63
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
-            $background = $this->buildPercentageBackground($percentages[$level]);
67
-            $count = apply_filters('site-reviews/summary/counts',
68
-                $percentages[$level],
69
-                $this->ratingCounts[$level]
70
-            );
71
-            $percent = $this->buildPercentageCount($count);
72
-            $value = $label.$background.$percent;
73
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
-                'percent' => wp_strip_all_tags($count, true),
75
-                'rating' => $level,
76
-            ]);
77
-            return $carry.glsr(Builder::class)->div($value, [
78
-                'class' => 'glsr-bar',
79
-            ]);
80
-        });
81
-        return $this->wrap('percentage', $bars);
82
-    }
83
-
84
-    /**
85
-     * @param string $percent
86
-     * @return string
87
-     */
88
-    protected function buildPercentageBackground($percent)
89
-    {
90
-        $backgroundPercent = glsr(Builder::class)->span([
91
-            'class' => 'glsr-bar-background-percent',
92
-            'style' => 'width:'.$percent,
93
-        ]);
94
-        return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95
-    }
96
-
97
-    /**
98
-     * @param string $count
99
-     * @return string
100
-     */
101
-    protected function buildPercentageCount($count)
102
-    {
103
-        return '<span class="glsr-bar-percent">'.$count.'</span>';
104
-    }
105
-
106
-    /**
107
-     * @param string $label
108
-     * @return string
109
-     */
110
-    protected function buildPercentageLabel($label)
111
-    {
112
-        return '<span class="glsr-bar-label">'.$label.'</span>';
113
-    }
114
-
115
-    /**
116
-     * @return void|string
117
-     */
118
-    protected function buildRating()
119
-    {
120
-        if ($this->isHidden('rating')) {
121
-            return;
122
-        }
123
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
124
-    }
125
-
126
-    /**
127
-     * @return void|string
128
-     */
129
-    protected function buildStars()
130
-    {
131
-        if ($this->isHidden('stars')) {
132
-            return;
133
-        }
134
-        $stars = glsr_star_rating($this->averageRating);
135
-        return $this->wrap('stars', $stars);
136
-    }
137
-
138
-    /**
139
-     * @return void|string
140
-     */
141
-    protected function buildText()
142
-    {
143
-        if ($this->isHidden('summary')) {
144
-            return;
145
-        }
146
-        $count = intval(array_sum($this->ratingCounts));
147
-        if (empty($this->args['text'])) {
148
-            // @todo document this change
149
-            $this->args['text'] = _nx(
150
-                '{rating} out of {max} stars (based on {num} review)',
151
-                '{rating} out of {max} stars (based on {num} reviews)',
152
-                $count,
153
-                'Do not translate {rating}, {max}, and {num}, they are template tags.',
154
-                'site-reviews'
155
-            );
156
-        }
157
-        $summary = str_replace(
158
-            ['{rating}', '{max}', '{num}'],
159
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
160
-            $this->args['text']
161
-        );
162
-        return $this->wrap('text', '<span>'.$summary.'</span>');
163
-    }
164
-
165
-    /**
166
-     * @return void
167
-     */
168
-    protected function generateSchema()
169
-    {
170
-        if (!wp_validate_boolean($this->args['schema'])) {
171
-            return;
172
-        }
173
-        glsr(Schema::class)->store(
174
-            glsr(Schema::class)->buildSummary($this->args)
175
-        );
176
-    }
177
-
178
-    /**
179
-     * @return string
180
-     */
181
-    protected function getClass()
182
-    {
183
-        return trim('glsr-summary '.$this->args['class']);
184
-    }
185
-
186
-    /**
187
-     * @param string $key
188
-     * @return bool
189
-     */
190
-    protected function isHidden($key)
191
-    {
192
-        return in_array($key, $this->args['hide']);
193
-    }
194
-
195
-    /**
196
-     * @param string $key
197
-     * @param string $value
198
-     * @return string
199
-     */
200
-    protected function wrap($key, $value)
201
-    {
202
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
-        return glsr(Builder::class)->div($value, [
204
-            'class' => 'glsr-summary-'.$key,
205
-        ]);
206
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	protected $args;
18
+
19
+	/**
20
+	 * @var float
21
+	 */
22
+	protected $averageRating;
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	protected $ratingCounts;
28
+
29
+	/**
30
+	 * {@inheritdoc}
31
+	 */
32
+	public function build(array $args = [])
33
+	{
34
+		$this->args = $args;
35
+		$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
+		if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
37
+			return '';
38
+		}
39
+		$this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
40
+		$this->generateSchema();
41
+		return glsr(Template::class)->build('templates/reviews-summary', [
42
+			'context' => [
43
+				'assigned_to' => $this->args['assigned_to'],
44
+				'category' => $this->args['category'],
45
+				'class' => $this->getClass(),
46
+				'id' => $this->args['id'],
47
+				'percentages' => $this->buildPercentage(),
48
+				'rating' => $this->buildRating(),
49
+				'stars' => $this->buildStars(),
50
+				'text' => $this->buildText(),
51
+			],
52
+		]);
53
+	}
54
+
55
+	/**
56
+	 * @return void|string
57
+	 */
58
+	protected function buildPercentage()
59
+	{
60
+		if ($this->isHidden('bars')) {
61
+			return;
62
+		}
63
+		$percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
+		$bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
+			$label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
+			$background = $this->buildPercentageBackground($percentages[$level]);
67
+			$count = apply_filters('site-reviews/summary/counts',
68
+				$percentages[$level],
69
+				$this->ratingCounts[$level]
70
+			);
71
+			$percent = $this->buildPercentageCount($count);
72
+			$value = $label.$background.$percent;
73
+			$value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
+				'percent' => wp_strip_all_tags($count, true),
75
+				'rating' => $level,
76
+			]);
77
+			return $carry.glsr(Builder::class)->div($value, [
78
+				'class' => 'glsr-bar',
79
+			]);
80
+		});
81
+		return $this->wrap('percentage', $bars);
82
+	}
83
+
84
+	/**
85
+	 * @param string $percent
86
+	 * @return string
87
+	 */
88
+	protected function buildPercentageBackground($percent)
89
+	{
90
+		$backgroundPercent = glsr(Builder::class)->span([
91
+			'class' => 'glsr-bar-background-percent',
92
+			'style' => 'width:'.$percent,
93
+		]);
94
+		return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95
+	}
96
+
97
+	/**
98
+	 * @param string $count
99
+	 * @return string
100
+	 */
101
+	protected function buildPercentageCount($count)
102
+	{
103
+		return '<span class="glsr-bar-percent">'.$count.'</span>';
104
+	}
105
+
106
+	/**
107
+	 * @param string $label
108
+	 * @return string
109
+	 */
110
+	protected function buildPercentageLabel($label)
111
+	{
112
+		return '<span class="glsr-bar-label">'.$label.'</span>';
113
+	}
114
+
115
+	/**
116
+	 * @return void|string
117
+	 */
118
+	protected function buildRating()
119
+	{
120
+		if ($this->isHidden('rating')) {
121
+			return;
122
+		}
123
+		return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
124
+	}
125
+
126
+	/**
127
+	 * @return void|string
128
+	 */
129
+	protected function buildStars()
130
+	{
131
+		if ($this->isHidden('stars')) {
132
+			return;
133
+		}
134
+		$stars = glsr_star_rating($this->averageRating);
135
+		return $this->wrap('stars', $stars);
136
+	}
137
+
138
+	/**
139
+	 * @return void|string
140
+	 */
141
+	protected function buildText()
142
+	{
143
+		if ($this->isHidden('summary')) {
144
+			return;
145
+		}
146
+		$count = intval(array_sum($this->ratingCounts));
147
+		if (empty($this->args['text'])) {
148
+			// @todo document this change
149
+			$this->args['text'] = _nx(
150
+				'{rating} out of {max} stars (based on {num} review)',
151
+				'{rating} out of {max} stars (based on {num} reviews)',
152
+				$count,
153
+				'Do not translate {rating}, {max}, and {num}, they are template tags.',
154
+				'site-reviews'
155
+			);
156
+		}
157
+		$summary = str_replace(
158
+			['{rating}', '{max}', '{num}'],
159
+			[$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
160
+			$this->args['text']
161
+		);
162
+		return $this->wrap('text', '<span>'.$summary.'</span>');
163
+	}
164
+
165
+	/**
166
+	 * @return void
167
+	 */
168
+	protected function generateSchema()
169
+	{
170
+		if (!wp_validate_boolean($this->args['schema'])) {
171
+			return;
172
+		}
173
+		glsr(Schema::class)->store(
174
+			glsr(Schema::class)->buildSummary($this->args)
175
+		);
176
+	}
177
+
178
+	/**
179
+	 * @return string
180
+	 */
181
+	protected function getClass()
182
+	{
183
+		return trim('glsr-summary '.$this->args['class']);
184
+	}
185
+
186
+	/**
187
+	 * @param string $key
188
+	 * @return bool
189
+	 */
190
+	protected function isHidden($key)
191
+	{
192
+		return in_array($key, $this->args['hide']);
193
+	}
194
+
195
+	/**
196
+	 * @param string $key
197
+	 * @param string $value
198
+	 * @return string
199
+	 */
200
+	protected function wrap($key, $value)
201
+	{
202
+		$value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
+		return glsr(Builder::class)->div($value, [
204
+			'class' => 'glsr-summary-'.$key,
205
+		]);
206
+	}
207 207
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * {@inheritdoc}
31 31
      */
32
-    public function build(array $args = [])
32
+    public function build( array $args = [] )
33 33
     {
34 34
         $this->args = $args;
35
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
36
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
35
+        $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args );
36
+        if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) {
37 37
             return '';
38 38
         }
39
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
+        $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts );
40 40
         $this->generateSchema();
41
-        return glsr(Template::class)->build('templates/reviews-summary', [
41
+        return glsr( Template::class )->build( 'templates/reviews-summary', [
42 42
             'context' => [
43 43
                 'assigned_to' => $this->args['assigned_to'],
44 44
                 'category' => $this->args['category'],
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                 'stars' => $this->buildStars(),
50 50
                 'text' => $this->buildText(),
51 51
             ],
52
-        ]);
52
+        ] );
53 53
     }
54 54
 
55 55
     /**
@@ -57,40 +57,40 @@  discard block
 block discarded – undo
57 57
      */
58 58
     protected function buildPercentage()
59 59
     {
60
-        if ($this->isHidden('bars')) {
60
+        if( $this->isHidden( 'bars' ) ) {
61 61
             return;
62 62
         }
63
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
64
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
65
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
66
-            $background = $this->buildPercentageBackground($percentages[$level]);
67
-            $count = apply_filters('site-reviews/summary/counts',
63
+        $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) );
64
+        $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) {
65
+            $label = $this->buildPercentageLabel( $this->args['labels'][$level] );
66
+            $background = $this->buildPercentageBackground( $percentages[$level] );
67
+            $count = apply_filters( 'site-reviews/summary/counts',
68 68
                 $percentages[$level],
69 69
                 $this->ratingCounts[$level]
70 70
             );
71
-            $percent = $this->buildPercentageCount($count);
71
+            $percent = $this->buildPercentageCount( $count );
72 72
             $value = $label.$background.$percent;
73
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
74
-                'percent' => wp_strip_all_tags($count, true),
73
+            $value = apply_filters( 'site-reviews/summary/wrap/bar', $value, $this->args, [
74
+                'percent' => wp_strip_all_tags( $count, true ),
75 75
                 'rating' => $level,
76
-            ]);
77
-            return $carry.glsr(Builder::class)->div($value, [
76
+            ] );
77
+            return $carry.glsr( Builder::class )->div( $value, [
78 78
                 'class' => 'glsr-bar',
79
-            ]);
79
+            ] );
80 80
         });
81
-        return $this->wrap('percentage', $bars);
81
+        return $this->wrap( 'percentage', $bars );
82 82
     }
83 83
 
84 84
     /**
85 85
      * @param string $percent
86 86
      * @return string
87 87
      */
88
-    protected function buildPercentageBackground($percent)
88
+    protected function buildPercentageBackground( $percent )
89 89
     {
90
-        $backgroundPercent = glsr(Builder::class)->span([
90
+        $backgroundPercent = glsr( Builder::class )->span( [
91 91
             'class' => 'glsr-bar-background-percent',
92 92
             'style' => 'width:'.$percent,
93
-        ]);
93
+        ] );
94 94
         return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
95 95
     }
96 96
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      * @param string $count
99 99
      * @return string
100 100
      */
101
-    protected function buildPercentageCount($count)
101
+    protected function buildPercentageCount( $count )
102 102
     {
103 103
         return '<span class="glsr-bar-percent">'.$count.'</span>';
104 104
     }
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param string $label
108 108
      * @return string
109 109
      */
110
-    protected function buildPercentageLabel($label)
110
+    protected function buildPercentageLabel( $label )
111 111
     {
112 112
         return '<span class="glsr-bar-label">'.$label.'</span>';
113 113
     }
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
      */
118 118
     protected function buildRating()
119 119
     {
120
-        if ($this->isHidden('rating')) {
120
+        if( $this->isHidden( 'rating' ) ) {
121 121
             return;
122 122
         }
123
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
+        return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' );
124 124
     }
125 125
 
126 126
     /**
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
      */
129 129
     protected function buildStars()
130 130
     {
131
-        if ($this->isHidden('stars')) {
131
+        if( $this->isHidden( 'stars' ) ) {
132 132
             return;
133 133
         }
134
-        $stars = glsr_star_rating($this->averageRating);
135
-        return $this->wrap('stars', $stars);
134
+        $stars = glsr_star_rating( $this->averageRating );
135
+        return $this->wrap( 'stars', $stars );
136 136
     }
137 137
 
138 138
     /**
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
      */
141 141
     protected function buildText()
142 142
     {
143
-        if ($this->isHidden('summary')) {
143
+        if( $this->isHidden( 'summary' ) ) {
144 144
             return;
145 145
         }
146
-        $count = intval(array_sum($this->ratingCounts));
147
-        if (empty($this->args['text'])) {
146
+        $count = intval( array_sum( $this->ratingCounts ) );
147
+        if( empty($this->args['text']) ) {
148 148
             // @todo document this change
149 149
             $this->args['text'] = _nx(
150 150
                 '{rating} out of {max} stars (based on {num} review)',
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
         }
157 157
         $summary = str_replace(
158 158
             ['{rating}', '{max}', '{num}'],
159
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
+            [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count],
160 160
             $this->args['text']
161 161
         );
162
-        return $this->wrap('text', '<span>'.$summary.'</span>');
162
+        return $this->wrap( 'text', '<span>'.$summary.'</span>' );
163 163
     }
164 164
 
165 165
     /**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
      */
168 168
     protected function generateSchema()
169 169
     {
170
-        if (!wp_validate_boolean($this->args['schema'])) {
170
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
171 171
             return;
172 172
         }
173
-        glsr(Schema::class)->store(
174
-            glsr(Schema::class)->buildSummary($this->args)
173
+        glsr( Schema::class )->store(
174
+            glsr( Schema::class )->buildSummary( $this->args )
175 175
         );
176 176
     }
177 177
 
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
      */
181 181
     protected function getClass()
182 182
     {
183
-        return trim('glsr-summary '.$this->args['class']);
183
+        return trim( 'glsr-summary '.$this->args['class'] );
184 184
     }
185 185
 
186 186
     /**
187 187
      * @param string $key
188 188
      * @return bool
189 189
      */
190
-    protected function isHidden($key)
190
+    protected function isHidden( $key )
191 191
     {
192
-        return in_array($key, $this->args['hide']);
192
+        return in_array( $key, $this->args['hide'] );
193 193
     }
194 194
 
195 195
     /**
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
      * @param string $value
198 198
      * @return string
199 199
      */
200
-    protected function wrap($key, $value)
200
+    protected function wrap( $key, $value )
201 201
     {
202
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
203
-        return glsr(Builder::class)->div($value, [
202
+        $value = apply_filters( 'site-reviews/summary/wrap/'.$key, $value, $this->args );
203
+        return glsr( Builder::class )->div( $value, [
204 204
             'class' => 'glsr-summary-'.$key,
205
-        ]);
205
+        ] );
206 206
     }
207 207
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/StarRating.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -8,54 +8,54 @@
 block discarded – undo
8 8
 
9 9
 class StarRating implements PartialContract
10 10
 {
11
-    protected $prefix;
12
-    protected $rating;
11
+	protected $prefix;
12
+	protected $rating;
13 13
 
14
-    /**
15
-     * {@inheritdoc}
16
-     */
17
-    public function build(array $args = [])
18
-    {
19
-        $this->setProperties($args);
20
-        $fullStars = intval(floor($this->rating));
21
-        $halfStars = intval(ceil($this->rating - $fullStars));
22
-        $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
-        return glsr(Template::class)->build('templates/rating/stars', [
24
-            'context' => [
25
-                'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
-                'full_stars' => $this->getTemplate('full-star', $fullStars),
27
-                'half_stars' => $this->getTemplate('half-star', $halfStars),
28
-                'prefix' => $this->prefix,
29
-                'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
30
-            ],
31
-        ]);
32
-    }
14
+	/**
15
+	 * {@inheritdoc}
16
+	 */
17
+	public function build(array $args = [])
18
+	{
19
+		$this->setProperties($args);
20
+		$fullStars = intval(floor($this->rating));
21
+		$halfStars = intval(ceil($this->rating - $fullStars));
22
+		$emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
+		return glsr(Template::class)->build('templates/rating/stars', [
24
+			'context' => [
25
+				'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
+				'full_stars' => $this->getTemplate('full-star', $fullStars),
27
+				'half_stars' => $this->getTemplate('half-star', $halfStars),
28
+				'prefix' => $this->prefix,
29
+				'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
30
+			],
31
+		]);
32
+	}
33 33
 
34
-    /**
35
-     * @param string $templateName
36
-     * @param int $timesRepeated
37
-     * @return string
38
-     */
39
-    protected function getTemplate($templateName, $timesRepeated)
40
-    {
41
-        $template = glsr(Template::class)->build('templates/rating/'.$templateName, [
42
-            'context' => [
43
-                'prefix' => $this->prefix,
44
-            ],
45
-        ]);
46
-        return str_repeat($template, $timesRepeated);
47
-    }
34
+	/**
35
+	 * @param string $templateName
36
+	 * @param int $timesRepeated
37
+	 * @return string
38
+	 */
39
+	protected function getTemplate($templateName, $timesRepeated)
40
+	{
41
+		$template = glsr(Template::class)->build('templates/rating/'.$templateName, [
42
+			'context' => [
43
+				'prefix' => $this->prefix,
44
+			],
45
+		]);
46
+		return str_repeat($template, $timesRepeated);
47
+	}
48 48
 
49
-    /**
50
-     * @return array
51
-     */
52
-    protected function setProperties(array $args)
53
-    {
54
-        $args = wp_parse_args($args, [
55
-            'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56
-            'rating' => 0,
57
-        ]);
58
-        $this->prefix = $args['prefix'];
59
-        $this->rating = (float) str_replace(',', '.', $args['rating']);
60
-    }
49
+	/**
50
+	 * @return array
51
+	 */
52
+	protected function setProperties(array $args)
53
+	{
54
+		$args = wp_parse_args($args, [
55
+			'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56
+			'rating' => 0,
57
+		]);
58
+		$this->prefix = $args['prefix'];
59
+		$this->rating = (float) str_replace(',', '.', $args['rating']);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,21 +14,21 @@  discard block
 block discarded – undo
14 14
     /**
15 15
      * {@inheritdoc}
16 16
      */
17
-    public function build(array $args = [])
17
+    public function build( array $args = [] )
18 18
     {
19
-        $this->setProperties($args);
20
-        $fullStars = intval(floor($this->rating));
21
-        $halfStars = intval(ceil($this->rating - $fullStars));
22
-        $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars);
23
-        return glsr(Template::class)->build('templates/rating/stars', [
19
+        $this->setProperties( $args );
20
+        $fullStars = intval( floor( $this->rating ) );
21
+        $halfStars = intval( ceil( $this->rating - $fullStars ) );
22
+        $emptyStars = max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $fullStars - $halfStars );
23
+        return glsr( Template::class )->build( 'templates/rating/stars', [
24 24
             'context' => [
25
-                'empty_stars' => $this->getTemplate('empty-star', $emptyStars),
26
-                'full_stars' => $this->getTemplate('full-star', $fullStars),
27
-                'half_stars' => $this->getTemplate('half-star', $halfStars),
25
+                'empty_stars' => $this->getTemplate( 'empty-star', $emptyStars ),
26
+                'full_stars' => $this->getTemplate( 'full-star', $fullStars ),
27
+                'half_stars' => $this->getTemplate( 'half-star', $halfStars ),
28 28
                 'prefix' => $this->prefix,
29
-                'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)),
29
+                'title' => sprintf( __( '%s rating', 'site-reviews' ), number_format_i18n( $this->rating, 1 ) ),
30 30
             ],
31
-        ]);
31
+        ] );
32 32
     }
33 33
 
34 34
     /**
@@ -36,26 +36,26 @@  discard block
 block discarded – undo
36 36
      * @param int $timesRepeated
37 37
      * @return string
38 38
      */
39
-    protected function getTemplate($templateName, $timesRepeated)
39
+    protected function getTemplate( $templateName, $timesRepeated )
40 40
     {
41
-        $template = glsr(Template::class)->build('templates/rating/'.$templateName, [
41
+        $template = glsr( Template::class )->build( 'templates/rating/'.$templateName, [
42 42
             'context' => [
43 43
                 'prefix' => $this->prefix,
44 44
             ],
45
-        ]);
46
-        return str_repeat($template, $timesRepeated);
45
+        ] );
46
+        return str_repeat( $template, $timesRepeated );
47 47
     }
48 48
 
49 49
     /**
50 50
      * @return array
51 51
      */
52
-    protected function setProperties(array $args)
52
+    protected function setProperties( array $args )
53 53
     {
54
-        $args = wp_parse_args($args, [
54
+        $args = wp_parse_args( $args, [
55 55
             'prefix' => glsr()->isAdmin() ? '' : 'glsr-',
56 56
             'rating' => 0,
57
-        ]);
57
+        ] );
58 58
         $this->prefix = $args['prefix'];
59
-        $this->rating = (float) str_replace(',', '.', $args['rating']);
59
+        $this->rating = (float)str_replace( ',', '.', $args['rating'] );
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 2 patches
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -21,384 +21,384 @@
 block discarded – undo
21 21
 
22 22
 class SiteReviews
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    public $args;
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $args;
28 28
 
29
-    /**
30
-     * @var Review
31
-     */
32
-    public $current;
29
+	/**
30
+	 * @var Review
31
+	 */
32
+	public $current;
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    public $options;
34
+	/**
35
+	 * @var array
36
+	 */
37
+	public $options;
38 38
 
39
-    /**
40
-     * @var Reviews
41
-     */
42
-    protected $reviews;
39
+	/**
40
+	 * @var Reviews
41
+	 */
42
+	protected $reviews;
43 43
 
44
-    /**
45
-     * @param Reviews|null $reviews
46
-     * @return ReviewsHtml
47
-     */
48
-    public function build(array $args = [], $reviews = null)
49
-    {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flatten(glsr(OptionManager::class)->all());
52
-        $this->reviews = $reviews instanceof Reviews
53
-            ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
55
-        $this->generateSchema();
56
-        return $this->buildReviews();
57
-    }
44
+	/**
45
+	 * @param Reviews|null $reviews
46
+	 * @return ReviewsHtml
47
+	 */
48
+	public function build(array $args = [], $reviews = null)
49
+	{
50
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
+		$this->options = Arr::flatten(glsr(OptionManager::class)->all());
52
+		$this->reviews = $reviews instanceof Reviews
53
+			? $reviews
54
+			: glsr(ReviewManager::class)->get($this->args);
55
+		$this->generateSchema();
56
+		return $this->buildReviews();
57
+	}
58 58
 
59
-    /**
60
-     * @return ReviewHtml
61
-     */
62
-    public function buildReview(Review $review)
63
-    {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
65
-        $this->current = $review;
66
-        $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
71
-                : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
74
-                continue;
75
-            }
76
-            $renderedFields[$key] = $field;
77
-        }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
-        $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
82
-    }
59
+	/**
60
+	 * @return ReviewHtml
61
+	 */
62
+	public function buildReview(Review $review)
63
+	{
64
+		$review = apply_filters('site-reviews/review/build/before', $review);
65
+		$this->current = $review;
66
+		$renderedFields = [];
67
+		foreach ($review as $key => $value) {
68
+			$method = Helper::buildMethodName($key, 'buildOption');
69
+			$field = method_exists($this, $method)
70
+				? $this->$method($key, $value)
71
+				: false;
72
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
+			if (false === $field) {
74
+				continue;
75
+			}
76
+			$renderedFields[$key] = $field;
77
+		}
78
+		$this->wrap($renderedFields, $review);
79
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
+		$this->current = null;
81
+		return new ReviewHtml($review, (array) $renderedFields);
82
+	}
83 83
 
84
-    /**
85
-     * @return ReviewsHtml
86
-     */
87
-    public function buildReviews()
88
-    {
89
-        $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
92
-        }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
-    }
84
+	/**
85
+	 * @return ReviewsHtml
86
+	 */
87
+	public function buildReviews()
88
+	{
89
+		$renderedReviews = [];
90
+		foreach ($this->reviews as $index => $review) {
91
+			$renderedReviews[] = $this->buildReview($review);
92
+		}
93
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
+	}
95 95
 
96
-    /**
97
-     * @return void
98
-     */
99
-    public function generateSchema()
100
-    {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
102
-            return;
103
-        }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
106
-        );
107
-    }
96
+	/**
97
+	 * @return void
98
+	 */
99
+	public function generateSchema()
100
+	{
101
+		if (!wp_validate_boolean($this->args['schema'])) {
102
+			return;
103
+		}
104
+		glsr(Schema::class)->store(
105
+			glsr(Schema::class)->build($this->args)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @param string $text
111
-     * @return string
112
-     */
113
-    public function getExcerpt($text)
114
-    {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
122
-                'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
127
-        }
128
-        return $text;
129
-    }
109
+	/**
110
+	 * @param string $text
111
+	 * @return string
112
+	 */
113
+	public function getExcerpt($text)
114
+	{
115
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
+		$split = extension_loaded('intl')
117
+			? $this->getExcerptIntlSplit($text, $limit)
118
+			: $this->getExcerptSplit($text, $limit);
119
+		$hiddenText = substr($text, $split);
120
+		if (!empty($hiddenText)) {
121
+			$showMore = glsr(Builder::class)->span($hiddenText, [
122
+				'class' => 'glsr-hidden glsr-hidden-text',
123
+				'data-show-less' => __('Show less', 'site-reviews'),
124
+				'data-show-more' => __('Show more', 'site-reviews'),
125
+			]);
126
+			$text = ltrim(substr($text, 0, $split)).$showMore;
127
+		}
128
+		return $text;
129
+	}
130 130
 
131
-    /**
132
-     * @param string $key
133
-     * @param string $path
134
-     * @return bool
135
-     */
136
-    public function isHidden($key, $path = '')
137
-    {
138
-        $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
140
-            : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
-    }
131
+	/**
132
+	 * @param string $key
133
+	 * @param string $path
134
+	 * @return bool
135
+	 */
136
+	public function isHidden($key, $path = '')
137
+	{
138
+		$isOptionEnabled = !empty($path)
139
+			? $this->isOptionEnabled($path)
140
+			: true;
141
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
+	}
143 143
 
144
-    /**
145
-     * @param string $key
146
-     * @param string $value
147
-     * @return bool
148
-     */
149
-    public function isHiddenOrEmpty($key, $value)
150
-    {
151
-        return $this->isHidden($key) || empty($value);
152
-    }
144
+	/**
145
+	 * @param string $key
146
+	 * @param string $value
147
+	 * @return bool
148
+	 */
149
+	public function isHiddenOrEmpty($key, $value)
150
+	{
151
+		return $this->isHidden($key) || empty($value);
152
+	}
153 153
 
154
-    /**
155
-     * @param string $text
156
-     * @return string
157
-     */
158
-    public function normalizeText($text)
159
-    {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
166
-        }
167
-        return wptexturize(nl2br($text));
168
-    }
154
+	/**
155
+	 * @param string $text
156
+	 * @return string
157
+	 */
158
+	public function normalizeText($text)
159
+	{
160
+		$text = wp_kses($text, wp_kses_allowed_html());
161
+		$text = convert_smilies(strip_shortcodes($text));
162
+		$text = str_replace(']]>', ']]&gt;', $text);
163
+		$text = preg_replace('/(\R){2,}/', '$1', $text);
164
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
+			$text = $this->getExcerpt($text);
166
+		}
167
+		return wptexturize(nl2br($text));
168
+	}
169 169
 
170
-    /**
171
-     * @param string $key
172
-     * @param string $value
173
-     * @return void|string
174
-     */
175
-    protected function buildOptionAssignedTo($key, $value)
176
-    {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
-            return;
179
-        }
180
-        $post = get_post(glsr(Multilingual::class)->getPostId($value));
181
-        if (empty($post->ID)) {
182
-            return;
183
-        }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
-        return '<span>'.$assignedTo.'</span>';
189
-    }
170
+	/**
171
+	 * @param string $key
172
+	 * @param string $value
173
+	 * @return void|string
174
+	 */
175
+	protected function buildOptionAssignedTo($key, $value)
176
+	{
177
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
+			return;
179
+		}
180
+		$post = get_post(glsr(Multilingual::class)->getPostId($value));
181
+		if (empty($post->ID)) {
182
+			return;
183
+		}
184
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
+			'href' => get_the_permalink($post->ID),
186
+		]);
187
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
+		return '<span>'.$assignedTo.'</span>';
189
+	}
190 190
 
191
-    /**
192
-     * @param string $key
193
-     * @param string $value
194
-     * @return void|string
195
-     */
196
-    protected function buildOptionAuthor($key, $value)
197
-    {
198
-        if (!$this->isHidden($key)) {
199
-            $name = Str::convertName(
200
-                $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
203
-            );
204
-            return '<span>'.$name.'</span>';
205
-        }
206
-    }
191
+	/**
192
+	 * @param string $key
193
+	 * @param string $value
194
+	 * @return void|string
195
+	 */
196
+	protected function buildOptionAuthor($key, $value)
197
+	{
198
+		if (!$this->isHidden($key)) {
199
+			$name = Str::convertName(
200
+				$value,
201
+				glsr_get_option('reviews.name.format'),
202
+				glsr_get_option('reviews.name.initial')
203
+			);
204
+			return '<span>'.$name.'</span>';
205
+		}
206
+	}
207 207
 
208
-    /**
209
-     * @param string $key
210
-     * @param string $value
211
-     * @return void|string
212
-     */
213
-    protected function buildOptionAvatar($key, $value)
214
-    {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
-            return;
217
-        }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
220
-            'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
-            'width' => $size,
224
-        ]);
225
-    }
208
+	/**
209
+	 * @param string $key
210
+	 * @param string $value
211
+	 * @return void|string
212
+	 */
213
+	protected function buildOptionAvatar($key, $value)
214
+	{
215
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
+			return;
217
+		}
218
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
219
+		return glsr(Builder::class)->img([
220
+			'height' => $size,
221
+			'src' => $this->generateAvatar($value),
222
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
+			'width' => $size,
224
+		]);
225
+	}
226 226
 
227
-    /**
228
-     * @param string $key
229
-     * @param string $value
230
-     * @return void|string
231
-     */
232
-    protected function buildOptionContent($key, $value)
233
-    {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
236
-            return '<p>'.$text.'</p>';
237
-        }
238
-    }
227
+	/**
228
+	 * @param string $key
229
+	 * @param string $value
230
+	 * @return void|string
231
+	 */
232
+	protected function buildOptionContent($key, $value)
233
+	{
234
+		$text = $this->normalizeText($value);
235
+		if (!$this->isHiddenOrEmpty($key, $text)) {
236
+			return '<p>'.$text.'</p>';
237
+		}
238
+	}
239 239
 
240
-    /**
241
-     * @param string $key
242
-     * @param string $value
243
-     * @return void|string
244
-     */
245
-    protected function buildOptionDate($key, $value)
246
-    {
247
-        if ($this->isHidden($key)) {
248
-            return;
249
-        }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
253
-        } else {
254
-            $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
258
-        }
259
-        return '<span>'.$date.'</span>';
260
-    }
240
+	/**
241
+	 * @param string $key
242
+	 * @param string $value
243
+	 * @return void|string
244
+	 */
245
+	protected function buildOptionDate($key, $value)
246
+	{
247
+		if ($this->isHidden($key)) {
248
+			return;
249
+		}
250
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
+		if ('relative' == $dateFormat) {
252
+			$date = glsr(Date::class)->relative($value);
253
+		} else {
254
+			$format = 'custom' == $dateFormat
255
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
+				: glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
+			$date = date_i18n($format, strtotime($value));
258
+		}
259
+		return '<span>'.$date.'</span>';
260
+	}
261 261
 
262
-    /**
263
-     * @param string $key
264
-     * @param string $value
265
-     * @return void|string
266
-     */
267
-    protected function buildOptionRating($key, $value)
268
-    {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
271
-        }
272
-    }
262
+	/**
263
+	 * @param string $key
264
+	 * @param string $value
265
+	 * @return void|string
266
+	 */
267
+	protected function buildOptionRating($key, $value)
268
+	{
269
+		if (!$this->isHiddenOrEmpty($key, $value)) {
270
+			return glsr_star_rating($value);
271
+		}
272
+	}
273 273
 
274
-    /**
275
-     * @param string $key
276
-     * @param string $value
277
-     * @return void|string
278
-     */
279
-    protected function buildOptionResponse($key, $value)
280
-    {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
282
-            return;
283
-        }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
286
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
-        return $response.$background;
290
-    }
274
+	/**
275
+	 * @param string $key
276
+	 * @param string $value
277
+	 * @return void|string
278
+	 */
279
+	protected function buildOptionResponse($key, $value)
280
+	{
281
+		if ($this->isHiddenOrEmpty($key, $value)) {
282
+			return;
283
+		}
284
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
+		$text = $this->normalizeText($value);
286
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
+		return $response.$background;
290
+	}
291 291
 
292
-    /**
293
-     * @param string $key
294
-     * @param string $value
295
-     * @return void|string
296
-     */
297
-    protected function buildOptionTitle($key, $value)
298
-    {
299
-        if ($this->isHidden($key)) {
300
-            return;
301
-        }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
304
-        }
305
-        return '<h3>'.$value.'</h3>';
306
-    }
292
+	/**
293
+	 * @param string $key
294
+	 * @param string $value
295
+	 * @return void|string
296
+	 */
297
+	protected function buildOptionTitle($key, $value)
298
+	{
299
+		if ($this->isHidden($key)) {
300
+			return;
301
+		}
302
+		if (empty($value)) {
303
+			$value = __('No Title', 'site-reviews');
304
+		}
305
+		return '<h3>'.$value.'</h3>';
306
+	}
307 307
 
308
-    /**
309
-     * @param string $avatarUrl
310
-     * @return string
311
-     */
312
-    protected function generateAvatar($avatarUrl)
313
-    {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
-            return $avatarUrl;
316
-        }
317
-        if ($this->current->user_id) {
318
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
319
-        }
320
-        if (empty($authorIdOrEmail)) {
321
-            $authorIdOrEmail = $this->current->email;
322
-        }
323
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
324
-            return $newAvatar;
325
-        }
326
-        return $avatarUrl;
327
-    }
308
+	/**
309
+	 * @param string $avatarUrl
310
+	 * @return string
311
+	 */
312
+	protected function generateAvatar($avatarUrl)
313
+	{
314
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
+			return $avatarUrl;
316
+		}
317
+		if ($this->current->user_id) {
318
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
319
+		}
320
+		if (empty($authorIdOrEmail)) {
321
+			$authorIdOrEmail = $this->current->email;
322
+		}
323
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
324
+			return $newAvatar;
325
+		}
326
+		return $avatarUrl;
327
+	}
328 328
 
329
-    /**
330
-     * @param string $text
331
-     * @param int $limit
332
-     * @return int
333
-     */
334
-    protected function getExcerptIntlSplit($text, $limit)
335
-    {
336
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
337
-        $words->setText($text);
338
-        $count = 0;
339
-        foreach ($words as $offset) {
340
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
341
-                continue;
342
-            }
343
-            ++$count;
344
-            if ($count != $limit) {
345
-                continue;
346
-            }
347
-            return $offset;
348
-        }
349
-        return strlen($text);
350
-    }
329
+	/**
330
+	 * @param string $text
331
+	 * @param int $limit
332
+	 * @return int
333
+	 */
334
+	protected function getExcerptIntlSplit($text, $limit)
335
+	{
336
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
337
+		$words->setText($text);
338
+		$count = 0;
339
+		foreach ($words as $offset) {
340
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
341
+				continue;
342
+			}
343
+			++$count;
344
+			if ($count != $limit) {
345
+				continue;
346
+			}
347
+			return $offset;
348
+		}
349
+		return strlen($text);
350
+	}
351 351
 
352
-    /**
353
-     * @param string $text
354
-     * @param int $limit
355
-     * @return int
356
-     */
357
-    protected function getExcerptSplit($text, $limit)
358
-    {
359
-        if (str_word_count($text, 0) > $limit) {
360
-            $words = array_keys(str_word_count($text, 2));
361
-            return $words[$limit];
362
-        }
363
-        return strlen($text);
364
-    }
352
+	/**
353
+	 * @param string $text
354
+	 * @param int $limit
355
+	 * @return int
356
+	 */
357
+	protected function getExcerptSplit($text, $limit)
358
+	{
359
+		if (str_word_count($text, 0) > $limit) {
360
+			$words = array_keys(str_word_count($text, 2));
361
+			return $words[$limit];
362
+		}
363
+		return strlen($text);
364
+	}
365 365
 
366
-    /**
367
-     * @param string $path
368
-     * @param mixed $fallback
369
-     * @return mixed
370
-     */
371
-    protected function getOption($path, $fallback = '')
372
-    {
373
-        if (array_key_exists($path, $this->options)) {
374
-            return $this->options[$path];
375
-        }
376
-        return $fallback;
377
-    }
366
+	/**
367
+	 * @param string $path
368
+	 * @param mixed $fallback
369
+	 * @return mixed
370
+	 */
371
+	protected function getOption($path, $fallback = '')
372
+	{
373
+		if (array_key_exists($path, $this->options)) {
374
+			return $this->options[$path];
375
+		}
376
+		return $fallback;
377
+	}
378 378
 
379
-    /**
380
-     * @param string $path
381
-     * @return bool
382
-     */
383
-    protected function isOptionEnabled($path)
384
-    {
385
-        return 'yes' == $this->getOption($path);
386
-    }
379
+	/**
380
+	 * @param string $path
381
+	 * @return bool
382
+	 */
383
+	protected function isOptionEnabled($path)
384
+	{
385
+		return 'yes' == $this->getOption($path);
386
+	}
387 387
 
388
-    /**
389
-     * @return void
390
-     */
391
-    protected function wrap(array &$renderedFields, Review $review)
392
-    {
393
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
395
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
-            if (empty($value)) {
397
-                return;
398
-            }
399
-            $value = glsr(Builder::class)->div($value, [
400
-                'class' => 'glsr-review-'.$key,
401
-            ]);
402
-        });
403
-    }
388
+	/**
389
+	 * @return void
390
+	 */
391
+	protected function wrap(array &$renderedFields, Review $review)
392
+	{
393
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
395
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
+			if (empty($value)) {
397
+				return;
398
+			}
399
+			$value = glsr(Builder::class)->div($value, [
400
+				'class' => 'glsr-review-'.$key,
401
+			]);
402
+		});
403
+	}
404 404
 }
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @param Reviews|null $reviews
46 46
      * @return ReviewsHtml
47 47
      */
48
-    public function build(array $args = [], $reviews = null)
48
+    public function build( array $args = [], $reviews = null )
49 49
     {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flatten(glsr(OptionManager::class)->all());
50
+        $this->args = glsr( SiteReviewsDefaults::class )->merge( $args );
51
+        $this->options = Arr::flatten( glsr( OptionManager::class )->all() );
52 52
         $this->reviews = $reviews instanceof Reviews
53 53
             ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
54
+            : glsr( ReviewManager::class )->get( $this->args );
55 55
         $this->generateSchema();
56 56
         return $this->buildReviews();
57 57
     }
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
     /**
60 60
      * @return ReviewHtml
61 61
      */
62
-    public function buildReview(Review $review)
62
+    public function buildReview( Review $review )
63 63
     {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
64
+        $review = apply_filters( 'site-reviews/review/build/before', $review );
65 65
         $this->current = $review;
66 66
         $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
67
+        foreach( $review as $key => $value ) {
68
+            $method = Helper::buildMethodName( $key, 'buildOption' );
69
+            $field = method_exists( $this, $method )
70
+                ? $this->$method( $key, $value )
71 71
                 : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
72
+            $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $review, $this );
73
+            if( false === $field ) {
74 74
                 continue;
75 75
             }
76 76
             $renderedFields[$key] = $field;
77 77
         }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
+        $this->wrap( $renderedFields, $review );
79
+        $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this );
80 80
         $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
81
+        return new ReviewHtml( $review, (array)$renderedFields );
82 82
     }
83 83
 
84 84
     /**
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
     public function buildReviews()
88 88
     {
89 89
         $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
90
+        foreach( $this->reviews as $index => $review ) {
91
+            $renderedReviews[] = $this->buildReview( $review );
92 92
         }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
93
+        return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args );
94 94
     }
95 95
 
96 96
     /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function generateSchema()
100 100
     {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
101
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
102 102
             return;
103 103
         }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
104
+        glsr( Schema::class )->store(
105
+            glsr( Schema::class )->build( $this->args )
106 106
         );
107 107
     }
108 108
 
@@ -110,20 +110,20 @@  discard block
 block discarded – undo
110 110
      * @param string $text
111 111
      * @return string
112 112
      */
113
-    public function getExcerpt($text)
113
+    public function getExcerpt( $text )
114 114
     {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
115
+        $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) );
116
+        $split = extension_loaded( 'intl' )
117
+            ? $this->getExcerptIntlSplit( $text, $limit )
118
+            : $this->getExcerptSplit( $text, $limit );
119
+        $hiddenText = substr( $text, $split );
120
+        if( !empty($hiddenText) ) {
121
+            $showMore = glsr( Builder::class )->span( $hiddenText, [
122 122
                 'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
123
+                'data-show-less' => __( 'Show less', 'site-reviews' ),
124
+                'data-show-more' => __( 'Show more', 'site-reviews' ),
125
+            ] );
126
+            $text = ltrim( substr( $text, 0, $split ) ).$showMore;
127 127
         }
128 128
         return $text;
129 129
     }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
      * @param string $path
134 134
      * @return bool
135 135
      */
136
-    public function isHidden($key, $path = '')
136
+    public function isHidden( $key, $path = '' )
137 137
     {
138 138
         $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
139
+            ? $this->isOptionEnabled( $path )
140 140
             : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
141
+        return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled;
142 142
     }
143 143
 
144 144
     /**
@@ -146,25 +146,25 @@  discard block
 block discarded – undo
146 146
      * @param string $value
147 147
      * @return bool
148 148
      */
149
-    public function isHiddenOrEmpty($key, $value)
149
+    public function isHiddenOrEmpty( $key, $value )
150 150
     {
151
-        return $this->isHidden($key) || empty($value);
151
+        return $this->isHidden( $key ) || empty($value);
152 152
     }
153 153
 
154 154
     /**
155 155
      * @param string $text
156 156
      * @return string
157 157
      */
158
-    public function normalizeText($text)
158
+    public function normalizeText( $text )
159 159
     {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
160
+        $text = wp_kses( $text, wp_kses_allowed_html() );
161
+        $text = convert_smilies( strip_shortcodes( $text ) );
162
+        $text = str_replace( ']]>', ']]&gt;', $text );
163
+        $text = preg_replace( '/(\R){2,}/', '$1', $text );
164
+        if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) {
165
+            $text = $this->getExcerpt( $text );
166 166
         }
167
-        return wptexturize(nl2br($text));
167
+        return wptexturize( nl2br( $text ) );
168 168
     }
169 169
 
170 170
     /**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
      * @param string $value
173 173
      * @return void|string
174 174
      */
175
-    protected function buildOptionAssignedTo($key, $value)
175
+    protected function buildOptionAssignedTo( $key, $value )
176 176
     {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
177
+        if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) {
178 178
             return;
179 179
         }
180
-        $post = get_post(glsr(Multilingual::class)->getPostId($value));
181
-        if (empty($post->ID)) {
180
+        $post = get_post( glsr( Multilingual::class )->getPostId( $value ) );
181
+        if( empty($post->ID) ) {
182 182
             return;
183 183
         }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
184
+        $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [
185
+            'href' => get_the_permalink( $post->ID ),
186
+        ] );
187
+        $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink );
188 188
         return '<span>'.$assignedTo.'</span>';
189 189
     }
190 190
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
      * @param string $value
194 194
      * @return void|string
195 195
      */
196
-    protected function buildOptionAuthor($key, $value)
196
+    protected function buildOptionAuthor( $key, $value )
197 197
     {
198
-        if (!$this->isHidden($key)) {
198
+        if( !$this->isHidden( $key ) ) {
199 199
             $name = Str::convertName(
200 200
                 $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
201
+                glsr_get_option( 'reviews.name.format' ),
202
+                glsr_get_option( 'reviews.name.initial' )
203 203
             );
204 204
             return '<span>'.$name.'</span>';
205 205
         }
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
      * @param string $value
211 211
      * @return void|string
212 212
      */
213
-    protected function buildOptionAvatar($key, $value)
213
+    protected function buildOptionAvatar( $key, $value )
214 214
     {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
215
+        if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) {
216 216
             return;
217 217
         }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
218
+        $size = $this->getOption( 'settings.reviews.avatars_size', 40 );
219
+        return glsr( Builder::class )->img( [
220 220
             'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
221
+            'src' => $this->generateAvatar( $value ),
222
+            'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ),
223 223
             'width' => $size,
224
-        ]);
224
+        ] );
225 225
     }
226 226
 
227 227
     /**
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
      * @param string $value
230 230
      * @return void|string
231 231
      */
232
-    protected function buildOptionContent($key, $value)
232
+    protected function buildOptionContent( $key, $value )
233 233
     {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
234
+        $text = $this->normalizeText( $value );
235
+        if( !$this->isHiddenOrEmpty( $key, $text ) ) {
236 236
             return '<p>'.$text.'</p>';
237 237
         }
238 238
     }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
      * @param string $value
243 243
      * @return void|string
244 244
      */
245
-    protected function buildOptionDate($key, $value)
245
+    protected function buildOptionDate( $key, $value )
246 246
     {
247
-        if ($this->isHidden($key)) {
247
+        if( $this->isHidden( $key ) ) {
248 248
             return;
249 249
         }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
250
+        $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' );
251
+        if( 'relative' == $dateFormat ) {
252
+            $date = glsr( Date::class )->relative( $value );
253 253
         } else {
254 254
             $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
255
+                ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' )
256
+                : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' );
257
+            $date = date_i18n( $format, strtotime( $value ) );
258 258
         }
259 259
         return '<span>'.$date.'</span>';
260 260
     }
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
      * @param string $value
265 265
      * @return void|string
266 266
      */
267
-    protected function buildOptionRating($key, $value)
267
+    protected function buildOptionRating( $key, $value )
268 268
     {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
269
+        if( !$this->isHiddenOrEmpty( $key, $value ) ) {
270
+            return glsr_star_rating( $value );
271 271
         }
272 272
     }
273 273
 
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
      * @param string $value
277 277
      * @return void|string
278 278
      */
279
-    protected function buildOptionResponse($key, $value)
279
+    protected function buildOptionResponse( $key, $value )
280 280
     {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
281
+        if( $this->isHiddenOrEmpty( $key, $value ) ) {
282 282
             return;
283 283
         }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
284
+        $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) );
285
+        $text = $this->normalizeText( $value );
286 286
         $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
287
+        $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] );
288
+        $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] );
289 289
         return $response.$background;
290 290
     }
291 291
 
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      * @param string $value
295 295
      * @return void|string
296 296
      */
297
-    protected function buildOptionTitle($key, $value)
297
+    protected function buildOptionTitle( $key, $value )
298 298
     {
299
-        if ($this->isHidden($key)) {
299
+        if( $this->isHidden( $key ) ) {
300 300
             return;
301 301
         }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
302
+        if( empty($value) ) {
303
+            $value = __( 'No Title', 'site-reviews' );
304 304
         }
305 305
         return '<h3>'.$value.'</h3>';
306 306
     }
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
      * @param string $avatarUrl
310 310
      * @return string
311 311
      */
312
-    protected function generateAvatar($avatarUrl)
312
+    protected function generateAvatar( $avatarUrl )
313 313
     {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
314
+        if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) {
315 315
             return $avatarUrl;
316 316
         }
317
-        if ($this->current->user_id) {
318
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
317
+        if( $this->current->user_id ) {
318
+        $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id );
319 319
         }
320
-        if (empty($authorIdOrEmail)) {
320
+        if( empty($authorIdOrEmail) ) {
321 321
             $authorIdOrEmail = $this->current->email;
322 322
         }
323
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
323
+        if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) {
324 324
             return $newAvatar;
325 325
         }
326 326
         return $avatarUrl;
@@ -331,22 +331,22 @@  discard block
 block discarded – undo
331 331
      * @param int $limit
332 332
      * @return int
333 333
      */
334
-    protected function getExcerptIntlSplit($text, $limit)
334
+    protected function getExcerptIntlSplit( $text, $limit )
335 335
     {
336
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
337
-        $words->setText($text);
336
+        $words = IntlRuleBasedBreakIterator::createWordInstance( '' );
337
+        $words->setText( $text );
338 338
         $count = 0;
339
-        foreach ($words as $offset) {
340
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
+        foreach( $words as $offset ) {
340
+            if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) {
341 341
                 continue;
342 342
             }
343 343
             ++$count;
344
-            if ($count != $limit) {
344
+            if( $count != $limit ) {
345 345
                 continue;
346 346
             }
347 347
             return $offset;
348 348
         }
349
-        return strlen($text);
349
+        return strlen( $text );
350 350
     }
351 351
 
352 352
     /**
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
      * @param int $limit
355 355
      * @return int
356 356
      */
357
-    protected function getExcerptSplit($text, $limit)
357
+    protected function getExcerptSplit( $text, $limit )
358 358
     {
359
-        if (str_word_count($text, 0) > $limit) {
360
-            $words = array_keys(str_word_count($text, 2));
359
+        if( str_word_count( $text, 0 ) > $limit ) {
360
+            $words = array_keys( str_word_count( $text, 2 ) );
361 361
             return $words[$limit];
362 362
         }
363
-        return strlen($text);
363
+        return strlen( $text );
364 364
     }
365 365
 
366 366
     /**
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
      * @param mixed $fallback
369 369
      * @return mixed
370 370
      */
371
-    protected function getOption($path, $fallback = '')
371
+    protected function getOption( $path, $fallback = '' )
372 372
     {
373
-        if (array_key_exists($path, $this->options)) {
373
+        if( array_key_exists( $path, $this->options ) ) {
374 374
             return $this->options[$path];
375 375
         }
376 376
         return $fallback;
@@ -380,25 +380,25 @@  discard block
 block discarded – undo
380 380
      * @param string $path
381 381
      * @return bool
382 382
      */
383
-    protected function isOptionEnabled($path)
383
+    protected function isOptionEnabled( $path )
384 384
     {
385
-        return 'yes' == $this->getOption($path);
385
+        return 'yes' == $this->getOption( $path );
386 386
     }
387 387
 
388 388
     /**
389 389
      * @return void
390 390
      */
391
-    protected function wrap(array &$renderedFields, Review $review)
391
+    protected function wrap( array &$renderedFields, Review $review )
392 392
     {
393
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
395
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
-            if (empty($value)) {
393
+        $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this );
394
+        array_walk( $renderedFields, function( &$value, $key ) use ($review) {
395
+            $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review );
396
+            if( empty($value) ) {
397 397
                 return;
398 398
             }
399
-            $value = glsr(Builder::class)->div($value, [
399
+            $value = glsr( Builder::class )->div( $value, [
400 400
                 'class' => 'glsr-review-'.$key,
401
-            ]);
401
+            ] );
402 402
         });
403 403
     }
404 404
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partial.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,31 +6,31 @@
 block discarded – undo
6 6
 
7 7
 class Partial
8 8
 {
9
-    /**
10
-     * @param string $partialPath
11
-     * @return string
12
-     */
13
-    public function build($partialPath, array $args = [])
14
-    {
15
-        $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
-        $className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
-        if (!class_exists($className)) {
18
-            glsr_log()->error('Partial missing: '.$className);
19
-            return;
20
-        }
21
-        $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
-        $partial = glsr($className)->build($args);
23
-        $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
-        $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
25
-        return $partial;
26
-    }
9
+	/**
10
+	 * @param string $partialPath
11
+	 * @return string
12
+	 */
13
+	public function build($partialPath, array $args = [])
14
+	{
15
+		$className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
+		$className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
+		if (!class_exists($className)) {
18
+			glsr_log()->error('Partial missing: '.$className);
19
+			return;
20
+		}
21
+		$args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
+		$partial = glsr($className)->build($args);
23
+		$partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
+		$partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
25
+		return $partial;
26
+	}
27 27
 
28
-    /**
29
-     * @param string $partialPath
30
-     * @return void
31
-     */
32
-    public function render($partialPath, array $args = [])
33
-    {
34
-        echo $this->build($partialPath, $args);
35
-    }
28
+	/**
29
+	 * @param string $partialPath
30
+	 * @return void
31
+	 */
32
+	public function render($partialPath, array $args = [])
33
+	{
34
+		echo $this->build($partialPath, $args);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@  discard block
 block discarded – undo
10 10
      * @param string $partialPath
11 11
      * @return string
12 12
      */
13
-    public function build($partialPath, array $args = [])
13
+    public function build( $partialPath, array $args = [] )
14 14
     {
15
-        $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials');
16
-        $className = apply_filters('site-reviews/partial/classname', $className, $partialPath);
17
-        if (!class_exists($className)) {
18
-            glsr_log()->error('Partial missing: '.$className);
15
+        $className = Helper::buildClassName( $partialPath, 'Modules\Html\Partials' );
16
+        $className = apply_filters( 'site-reviews/partial/classname', $className, $partialPath );
17
+        if( !class_exists( $className ) ) {
18
+            glsr_log()->error( 'Partial missing: '.$className );
19 19
             return;
20 20
         }
21
-        $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args);
22
-        $partial = glsr($className)->build($args);
23
-        $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args);
24
-        $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args);
21
+        $args = apply_filters( 'site-reviews/partial/args/'.$partialPath, $args );
22
+        $partial = glsr( $className )->build( $args );
23
+        $partial = apply_filters( 'site-reviews/rendered/partial', $partial, $partialPath, $args );
24
+        $partial = apply_filters( 'site-reviews/rendered/partial/'.$partialPath, $partial, $args );
25 25
         return $partial;
26 26
     }
27 27
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      * @param string $partialPath
30 30
      * @return void
31 31
      */
32
-    public function render($partialPath, array $args = [])
32
+    public function render( $partialPath, array $args = [] )
33 33
     {
34
-        echo $this->build($partialPath, $args);
34
+        echo $this->build( $partialPath, $args );
35 35
     }
36 36
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/ReviewsHtml.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
 
9 9
 class ReviewsHtml extends ArrayObject
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    public $args;
11
+	/**
12
+	 * @var array
13
+	 */
14
+	public $args;
15 15
 
16
-    /**
17
-     * @var int
18
-     */
19
-    public $max_num_pages;
16
+	/**
17
+	 * @var int
18
+	 */
19
+	public $max_num_pages;
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    public $pagination;
21
+	/**
22
+	 * @var string
23
+	 */
24
+	public $pagination;
25 25
 
26
-    /**
27
-     * @var array
28
-     */
29
-    public $reviews;
26
+	/**
27
+	 * @var array
28
+	 */
29
+	public $reviews;
30 30
 
31
-    public function __construct(array $renderedReviews, $maxPageCount, array $args)
32
-    {
33
-        $this->args = $args;
34
-        $this->max_num_pages = $maxPageCount;
35
-        $this->reviews = $renderedReviews;
36
-        $this->pagination = $this->buildPagination();
37
-        parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
38
-    }
31
+	public function __construct(array $renderedReviews, $maxPageCount, array $args)
32
+	{
33
+		$this->args = $args;
34
+		$this->max_num_pages = $maxPageCount;
35
+		$this->reviews = $renderedReviews;
36
+		$this->pagination = $this->buildPagination();
37
+		parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
38
+	}
39 39
 
40
-    /**
41
-     * @return string
42
-     */
43
-    public function __toString()
44
-    {
45
-        return glsr(Template::class)->build('templates/reviews', [
46
-            'args' => $this->args,
47
-            'context' => [
48
-                'assigned_to' => $this->args['assigned_to'],
49
-                'category' => $this->args['category'],
50
-                'class' => $this->getClass(),
51
-                'id' => $this->args['id'],
52
-                'pagination' => $this->getPagination(),
53
-                'reviews' => $this->getReviews(),
54
-            ],
55
-        ]);
56
-    }
40
+	/**
41
+	 * @return string
42
+	 */
43
+	public function __toString()
44
+	{
45
+		return glsr(Template::class)->build('templates/reviews', [
46
+			'args' => $this->args,
47
+			'context' => [
48
+				'assigned_to' => $this->args['assigned_to'],
49
+				'category' => $this->args['category'],
50
+				'class' => $this->getClass(),
51
+				'id' => $this->args['id'],
52
+				'pagination' => $this->getPagination(),
53
+				'reviews' => $this->getReviews(),
54
+			],
55
+		]);
56
+	}
57 57
 
58
-    /**
59
-     * @return string
60
-     */
61
-    public function getPagination()
62
-    {
63
-        return wp_validate_boolean($this->args['pagination'])
64
-            ? $this->pagination
65
-            : '';
66
-    }
58
+	/**
59
+	 * @return string
60
+	 */
61
+	public function getPagination()
62
+	{
63
+		return wp_validate_boolean($this->args['pagination'])
64
+			? $this->pagination
65
+			: '';
66
+	}
67 67
 
68
-    /**
69
-     * @return string
70
-     */
71
-    public function getReviews()
72
-    {
73
-        $html = empty($this->reviews)
74
-            ? $this->getReviewsFallback()
75
-            : implode(PHP_EOL, $this->reviews);
76
-        return glsr(Builder::class)->div($html, [
77
-            'class' => 'glsr-reviews-list',
78
-            'data-reviews' => '',
79
-        ]);
80
-    }
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function getReviews()
72
+	{
73
+		$html = empty($this->reviews)
74
+			? $this->getReviewsFallback()
75
+			: implode(PHP_EOL, $this->reviews);
76
+		return glsr(Builder::class)->div($html, [
77
+			'class' => 'glsr-reviews-list',
78
+			'data-reviews' => '',
79
+		]);
80
+	}
81 81
 
82
-    /**
83
-     * @param mixed $key
84
-     * @return mixed
85
-     */
86
-    public function offsetGet($key)
87
-    {
88
-        if ('navigation' == $key) {
89
-            glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90
-            return $this->pagination;
91
-        }
92
-        if (array_key_exists($key, $this->reviews)) {
93
-            return $this->reviews[$key];
94
-        }
95
-        return property_exists($this, $key)
96
-            ? $this->$key
97
-            : null;
98
-    }
82
+	/**
83
+	 * @param mixed $key
84
+	 * @return mixed
85
+	 */
86
+	public function offsetGet($key)
87
+	{
88
+		if ('navigation' == $key) {
89
+			glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90
+			return $this->pagination;
91
+		}
92
+		if (array_key_exists($key, $this->reviews)) {
93
+			return $this->reviews[$key];
94
+		}
95
+		return property_exists($this, $key)
96
+			? $this->$key
97
+			: null;
98
+	}
99 99
 
100
-    /**
101
-     * @return string
102
-     */
103
-    protected function buildPagination()
104
-    {
105
-        $html = glsr(Partial::class)->build('pagination', [
106
-            'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
-            'current' => Arr::get($this->args, 'paged'),
108
-            'total' => $this->max_num_pages,
109
-        ]);
110
-        return glsr(Builder::class)->div($html, [
111
-            'class' => 'glsr-pagination',
112
-            'data-atts' => $this->args['json'],
113
-            'data-pagination' => '',
114
-        ]);
115
-    }
100
+	/**
101
+	 * @return string
102
+	 */
103
+	protected function buildPagination()
104
+	{
105
+		$html = glsr(Partial::class)->build('pagination', [
106
+			'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
+			'current' => Arr::get($this->args, 'paged'),
108
+			'total' => $this->max_num_pages,
109
+		]);
110
+		return glsr(Builder::class)->div($html, [
111
+			'class' => 'glsr-pagination',
112
+			'data-atts' => $this->args['json'],
113
+			'data-pagination' => '',
114
+		]);
115
+	}
116 116
 
117
-    /**
118
-     * @return string
119
-     */
120
-    protected function getClass()
121
-    {
122
-        $defaults = [
123
-            'glsr-reviews',
124
-        ];
125
-        if ('ajax' == $this->args['pagination']) {
126
-            $defaults[] = 'glsr-ajax-pagination';
127
-        }
128
-        $classes = explode(' ', $this->args['class']);
129
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
130
-        return implode(' ', $classes);
131
-    }
117
+	/**
118
+	 * @return string
119
+	 */
120
+	protected function getClass()
121
+	{
122
+		$defaults = [
123
+			'glsr-reviews',
124
+		];
125
+		if ('ajax' == $this->args['pagination']) {
126
+			$defaults[] = 'glsr-ajax-pagination';
127
+		}
128
+		$classes = explode(' ', $this->args['class']);
129
+		$classes = array_unique(array_merge($defaults, array_filter($classes)));
130
+		return implode(' ', $classes);
131
+	}
132 132
 
133
-    /**
134
-     * @return string
135
-     */
136
-    protected function getReviewsFallback()
137
-    {
138
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
140
-        }
141
-        $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
143
-    }
133
+	/**
134
+	 * @return string
135
+	 */
136
+	protected function getReviewsFallback()
137
+	{
138
+		if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
+			$this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
140
+		}
141
+		$fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
+		return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public $reviews;
30 30
 
31
-    public function __construct(array $renderedReviews, $maxPageCount, array $args)
31
+    public function __construct( array $renderedReviews, $maxPageCount, array $args )
32 32
     {
33 33
         $this->args = $args;
34 34
         $this->max_num_pages = $maxPageCount;
35 35
         $this->reviews = $renderedReviews;
36 36
         $this->pagination = $this->buildPagination();
37
-        parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
+        parent::__construct( $renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS );
38 38
     }
39 39
 
40 40
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function __toString()
44 44
     {
45
-        return glsr(Template::class)->build('templates/reviews', [
45
+        return glsr( Template::class )->build( 'templates/reviews', [
46 46
             'args' => $this->args,
47 47
             'context' => [
48 48
                 'assigned_to' => $this->args['assigned_to'],
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
                 'pagination' => $this->getPagination(),
53 53
                 'reviews' => $this->getReviews(),
54 54
             ],
55
-        ]);
55
+        ] );
56 56
     }
57 57
 
58 58
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function getPagination()
62 62
     {
63
-        return wp_validate_boolean($this->args['pagination'])
63
+        return wp_validate_boolean( $this->args['pagination'] )
64 64
             ? $this->pagination
65 65
             : '';
66 66
     }
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $html = empty($this->reviews)
74 74
             ? $this->getReviewsFallback()
75
-            : implode(PHP_EOL, $this->reviews);
76
-        return glsr(Builder::class)->div($html, [
75
+            : implode( PHP_EOL, $this->reviews );
76
+        return glsr( Builder::class )->div( $html, [
77 77
             'class' => 'glsr-reviews-list',
78 78
             'data-reviews' => '',
79
-        ]);
79
+        ] );
80 80
     }
81 81
 
82 82
     /**
83 83
      * @param mixed $key
84 84
      * @return mixed
85 85
      */
86
-    public function offsetGet($key)
86
+    public function offsetGet( $key )
87 87
     {
88
-        if ('navigation' == $key) {
88
+        if( 'navigation' == $key ) {
89 89
             glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
90 90
             return $this->pagination;
91 91
         }
92
-        if (array_key_exists($key, $this->reviews)) {
92
+        if( array_key_exists( $key, $this->reviews ) ) {
93 93
             return $this->reviews[$key];
94 94
         }
95
-        return property_exists($this, $key)
95
+        return property_exists( $this, $key )
96 96
             ? $this->$key
97 97
             : null;
98 98
     }
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      */
103 103
     protected function buildPagination()
104 104
     {
105
-        $html = glsr(Partial::class)->build('pagination', [
106
-            'baseUrl' => Arr::get($this->args, 'pagedUrl'),
107
-            'current' => Arr::get($this->args, 'paged'),
105
+        $html = glsr( Partial::class )->build( 'pagination', [
106
+            'baseUrl' => Arr::get( $this->args, 'pagedUrl' ),
107
+            'current' => Arr::get( $this->args, 'paged' ),
108 108
             'total' => $this->max_num_pages,
109
-        ]);
110
-        return glsr(Builder::class)->div($html, [
109
+        ] );
110
+        return glsr( Builder::class )->div( $html, [
111 111
             'class' => 'glsr-pagination',
112 112
             'data-atts' => $this->args['json'],
113 113
             'data-pagination' => '',
114
-        ]);
114
+        ] );
115 115
     }
116 116
 
117 117
     /**
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
         $defaults = [
123 123
             'glsr-reviews',
124 124
         ];
125
-        if ('ajax' == $this->args['pagination']) {
125
+        if( 'ajax' == $this->args['pagination'] ) {
126 126
             $defaults[] = 'glsr-ajax-pagination';
127 127
         }
128
-        $classes = explode(' ', $this->args['class']);
129
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
130
-        return implode(' ', $classes);
128
+        $classes = explode( ' ', $this->args['class'] );
129
+        $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) );
130
+        return implode( ' ', $classes );
131 131
     }
132 132
 
133 133
     /**
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
      */
136 136
     protected function getReviewsFallback()
137 137
     {
138
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
139
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
138
+        if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) {
139
+            $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' );
140 140
         }
141 141
         $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
142
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
142
+        return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args );
143 143
     }
144 144
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Builder.php 3 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -19,343 +19,343 @@
 block discarded – undo
19 19
  */
20 20
 class Builder
21 21
 {
22
-    const INPUT_TYPES = [
23
-        'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
24
-        'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
25
-        'url', 'week',
26
-    ];
27
-
28
-    const TAGS_FORM = [
29
-        'input', 'select', 'textarea',
30
-    ];
31
-
32
-    const TAGS_SINGLE = [
33
-        'img',
34
-    ];
35
-
36
-    const TAGS_STRUCTURE = [
37
-        'div', 'form', 'nav', 'ol', 'section', 'ul',
38
-    ];
39
-
40
-    const TAGS_TEXT = [
41
-        'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
42
-        'small', 'span',
43
-    ];
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    public $args = [];
49
-
50
-    /**
51
-     * @var bool
52
-     */
53
-    public $render = false;
54
-
55
-    /**
56
-     * @var string
57
-     */
58
-    public $tag;
59
-
60
-    /**
61
-     * @param string $method
62
-     * @param array $args
63
-     * @return string|void
64
-     */
65
-    public function __call($method, $args)
66
-    {
67
-        $instance = new static();
68
-        $instance->setTagFromMethod($method);
69
-        call_user_func_array([$instance, 'normalize'], $args);
70
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
-        do_action_ref_array('site-reviews/builder', [$instance]);
72
-        $generatedTag = in_array($instance->tag, $tags)
73
-            ? $instance->buildTag()
74
-            : $instance->buildCustomField();
75
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
-        if (!$this->render) {
77
-            return $generatedTag;
78
-        }
79
-        echo $generatedTag;
80
-    }
81
-
82
-    /**
83
-     * @param string $property
84
-     * @param mixed $value
85
-     * @return void
86
-     */
87
-    public function __set($property, $value)
88
-    {
89
-        $properties = [
90
-            'args' => 'is_array',
91
-            'render' => 'is_bool',
92
-            'tag' => 'is_string',
93
-        ];
94
-        if (array_key_exists($property, $properties) && !empty($value)) {
95
-            $this->$property = $value;
96
-        }
97
-    }
98
-
99
-    /**
100
-     * @return void|string
101
-     */
102
-    public function getClosingTag()
103
-    {
104
-        if (!empty($this->tag)) {
105
-            return '</'.$this->tag.'>';
106
-        }
107
-    }
108
-
109
-    /**
110
-     * @return void|string
111
-     */
112
-    public function getOpeningTag()
113
-    {
114
-        if (!empty($this->tag)) {
115
-            $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
-            return '<'.trim($this->tag.' '.$attributes).'>';
117
-        }
118
-    }
119
-
120
-    /**
121
-     * @return void|string
122
-     */
123
-    public function getTag()
124
-    {
125
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
126
-            return $this->getOpeningTag();
127
-        }
128
-        if (!in_array($this->tag, static::TAGS_FORM)) {
129
-            return $this->buildDefaultTag();
130
-        }
131
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
132
-    }
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    public function raw(array $field)
138
-    {
139
-        unset($field['label']);
140
-        return $this->{$field['type']}($field);
141
-    }
142
-
143
-    /**
144
-     * @return string|void
145
-     */
146
-    protected function buildCustomField()
147
-    {
148
-        $className = $this->getCustomFieldClassName();
149
-        if (class_exists($className)) {
150
-            return (new $className($this))->build();
151
-        }
152
-        glsr_log()->error('Field class missing: '.$className);
153
-    }
154
-
155
-    /**
156
-     * @return string|void
157
-     */
158
-    protected function buildDefaultTag($text = '')
159
-    {
160
-        if (empty($text)) {
161
-            $text = $this->args['text'];
162
-        }
163
-        return $this->getOpeningTag().$text.$this->getClosingTag();
164
-    }
165
-
166
-    /**
167
-     * @return string|void
168
-     */
169
-    protected function buildFieldDescription()
170
-    {
171
-        if (empty($this->args['description'])) {
172
-            return;
173
-        }
174
-        if ($this->args['is_widget']) {
175
-            return $this->small($this->args['description']);
176
-        }
177
-        return $this->p($this->args['description'], ['class' => 'description']);
178
-    }
179
-
180
-    /**
181
-     * @return string|void
182
-     */
183
-    protected function buildFormInput()
184
-    {
185
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
-            if (isset($this->args['multiple'])) {
187
-                $this->args['name'] .= '[]';
188
-            }
189
-            return $this->buildFormLabel().$this->getOpeningTag();
190
-        }
191
-        return empty($this->args['options'])
192
-            ? $this->buildFormInputChoice()
193
-            : $this->buildFormInputMultiChoice();
194
-    }
195
-
196
-    /**
197
-     * @return string|void
198
-     */
199
-    protected function buildFormInputChoice()
200
-    {
201
-        if (!empty($this->args['text'])) {
202
-            $this->args['label'] = $this->args['text'];
203
-        }
204
-        if (!$this->args['is_public']) {
205
-            return $this->buildFormLabel([
206
-                'class' => 'glsr-'.$this->args['type'].'-label',
207
-                'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
-            ]);
209
-        }
210
-        return $this->getOpeningTag().$this->buildFormLabel([
211
-            'class' => 'glsr-'.$this->args['type'].'-label',
212
-            'text' => $this->args['label'].'<span></span>',
213
-        ]);
214
-    }
215
-
216
-    /**
217
-     * @return string|void
218
-     */
219
-    protected function buildFormInputMultiChoice()
220
-    {
221
-        if ('checkbox' == $this->args['type']) {
222
-            $this->args['name'] .= '[]';
223
-        }
224
-        $index = 0;
225
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
-            return $carry.$this->li($this->{$this->args['type']}([
227
-                'checked' => in_array($key, (array) $this->args['value']),
228
-                'id' => $this->args['id'].'-'.$index++,
229
-                'name' => $this->args['name'],
230
-                'text' => $this->args['options'][$key],
231
-                'value' => $key,
232
-            ]));
233
-        });
234
-        return $this->ul($options, [
235
-            'class' => $this->args['class'],
236
-            'id' => $this->args['id'],
237
-        ]);
238
-    }
239
-
240
-    /**
241
-     * @return void|string
242
-     */
243
-    protected function buildFormLabel(array $customArgs = [])
244
-    {
245
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
246
-            return;
247
-        }
248
-        return $this->label(wp_parse_args($customArgs, [
249
-            'for' => $this->args['id'],
250
-            'is_public' => $this->args['is_public'],
251
-            'text' => $this->args['label'],
252
-            'type' => $this->args['type'],
253
-        ]));
254
-    }
255
-
256
-    /**
257
-     * @return string|void
258
-     */
259
-    protected function buildFormSelect()
260
-    {
261
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
262
-    }
263
-
264
-    /**
265
-     * @return string|void
266
-     */
267
-    protected function buildFormSelectOptions()
268
-    {
269
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
-            return $carry.$this->option([
271
-                'selected' => $this->args['value'] === (string) $key,
272
-                'text' => $this->args['options'][$key],
273
-                'value' => $key,
274
-            ]);
275
-        });
276
-    }
277
-
278
-    /**
279
-     * @return string|void
280
-     */
281
-    protected function buildFormTextarea()
282
-    {
283
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
284
-    }
285
-
286
-    /**
287
-     * @return string|void
288
-     */
289
-    protected function buildTag()
290
-    {
291
-        $this->mergeArgsWithRequiredDefaults();
292
-        return $this->getTag();
293
-    }
294
-
295
-    /**
296
-     * @return string
297
-     */
298
-    protected function getCustomFieldClassName()
299
-    {
300
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
302
-    }
303
-
304
-    /**
305
-     * @return void
306
-     */
307
-    protected function mergeArgsWithRequiredDefaults()
308
-    {
309
-        $className = $this->getCustomFieldClassName();
310
-        if (class_exists($className)) {
311
-            $this->args = $className::merge($this->args);
312
-        }
313
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
314
-    }
315
-
316
-    /**
317
-     * @param string|array ...$params
318
-     * @return void
319
-     */
320
-    protected function normalize(...$params)
321
-    {
322
-        $parameter1 = Arr::get($params, 0);
323
-        $parameter2 = Arr::get($params, 1);
324
-        if (is_string($parameter1) || is_numeric($parameter1)) {
325
-            $this->setNameOrTextAttributeForTag($parameter1);
326
-        }
327
-        if (is_array($parameter1)) {
328
-            $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
330
-            $this->args += $parameter2;
331
-        }
332
-        if (!isset($this->args['is_public'])) {
333
-            $this->args['is_public'] = false;
334
-        }
335
-    }
336
-
337
-    /**
338
-     * @param string $value
339
-     * @return void
340
-     */
341
-    protected function setNameOrTextAttributeForTag($value)
342
-    {
343
-        $attribute = in_array($this->tag, static::TAGS_FORM)
344
-            ? 'name'
345
-            : 'text';
346
-        $this->args[$attribute] = $value;
347
-    }
348
-
349
-    /**
350
-     * @param string $method
351
-     * @return void
352
-     */
353
-    protected function setTagFromMethod($method)
354
-    {
355
-        $this->tag = strtolower($method);
356
-        if (in_array($this->tag, static::INPUT_TYPES)) {
357
-            $this->args['type'] = $this->tag;
358
-            $this->tag = 'input';
359
-        }
360
-    }
22
+	const INPUT_TYPES = [
23
+		'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
24
+		'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
25
+		'url', 'week',
26
+	];
27
+
28
+	const TAGS_FORM = [
29
+		'input', 'select', 'textarea',
30
+	];
31
+
32
+	const TAGS_SINGLE = [
33
+		'img',
34
+	];
35
+
36
+	const TAGS_STRUCTURE = [
37
+		'div', 'form', 'nav', 'ol', 'section', 'ul',
38
+	];
39
+
40
+	const TAGS_TEXT = [
41
+		'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
42
+		'small', 'span',
43
+	];
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	public $args = [];
49
+
50
+	/**
51
+	 * @var bool
52
+	 */
53
+	public $render = false;
54
+
55
+	/**
56
+	 * @var string
57
+	 */
58
+	public $tag;
59
+
60
+	/**
61
+	 * @param string $method
62
+	 * @param array $args
63
+	 * @return string|void
64
+	 */
65
+	public function __call($method, $args)
66
+	{
67
+		$instance = new static();
68
+		$instance->setTagFromMethod($method);
69
+		call_user_func_array([$instance, 'normalize'], $args);
70
+		$tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
+		do_action_ref_array('site-reviews/builder', [$instance]);
72
+		$generatedTag = in_array($instance->tag, $tags)
73
+			? $instance->buildTag()
74
+			: $instance->buildCustomField();
75
+		$generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
+		if (!$this->render) {
77
+			return $generatedTag;
78
+		}
79
+		echo $generatedTag;
80
+	}
81
+
82
+	/**
83
+	 * @param string $property
84
+	 * @param mixed $value
85
+	 * @return void
86
+	 */
87
+	public function __set($property, $value)
88
+	{
89
+		$properties = [
90
+			'args' => 'is_array',
91
+			'render' => 'is_bool',
92
+			'tag' => 'is_string',
93
+		];
94
+		if (array_key_exists($property, $properties) && !empty($value)) {
95
+			$this->$property = $value;
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * @return void|string
101
+	 */
102
+	public function getClosingTag()
103
+	{
104
+		if (!empty($this->tag)) {
105
+			return '</'.$this->tag.'>';
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * @return void|string
111
+	 */
112
+	public function getOpeningTag()
113
+	{
114
+		if (!empty($this->tag)) {
115
+			$attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
+			return '<'.trim($this->tag.' '.$attributes).'>';
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * @return void|string
122
+	 */
123
+	public function getTag()
124
+	{
125
+		if (in_array($this->tag, static::TAGS_SINGLE)) {
126
+			return $this->getOpeningTag();
127
+		}
128
+		if (!in_array($this->tag, static::TAGS_FORM)) {
129
+			return $this->buildDefaultTag();
130
+		}
131
+		return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
132
+	}
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	public function raw(array $field)
138
+	{
139
+		unset($field['label']);
140
+		return $this->{$field['type']}($field);
141
+	}
142
+
143
+	/**
144
+	 * @return string|void
145
+	 */
146
+	protected function buildCustomField()
147
+	{
148
+		$className = $this->getCustomFieldClassName();
149
+		if (class_exists($className)) {
150
+			return (new $className($this))->build();
151
+		}
152
+		glsr_log()->error('Field class missing: '.$className);
153
+	}
154
+
155
+	/**
156
+	 * @return string|void
157
+	 */
158
+	protected function buildDefaultTag($text = '')
159
+	{
160
+		if (empty($text)) {
161
+			$text = $this->args['text'];
162
+		}
163
+		return $this->getOpeningTag().$text.$this->getClosingTag();
164
+	}
165
+
166
+	/**
167
+	 * @return string|void
168
+	 */
169
+	protected function buildFieldDescription()
170
+	{
171
+		if (empty($this->args['description'])) {
172
+			return;
173
+		}
174
+		if ($this->args['is_widget']) {
175
+			return $this->small($this->args['description']);
176
+		}
177
+		return $this->p($this->args['description'], ['class' => 'description']);
178
+	}
179
+
180
+	/**
181
+	 * @return string|void
182
+	 */
183
+	protected function buildFormInput()
184
+	{
185
+		if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
+			if (isset($this->args['multiple'])) {
187
+				$this->args['name'] .= '[]';
188
+			}
189
+			return $this->buildFormLabel().$this->getOpeningTag();
190
+		}
191
+		return empty($this->args['options'])
192
+			? $this->buildFormInputChoice()
193
+			: $this->buildFormInputMultiChoice();
194
+	}
195
+
196
+	/**
197
+	 * @return string|void
198
+	 */
199
+	protected function buildFormInputChoice()
200
+	{
201
+		if (!empty($this->args['text'])) {
202
+			$this->args['label'] = $this->args['text'];
203
+		}
204
+		if (!$this->args['is_public']) {
205
+			return $this->buildFormLabel([
206
+				'class' => 'glsr-'.$this->args['type'].'-label',
207
+				'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
+			]);
209
+		}
210
+		return $this->getOpeningTag().$this->buildFormLabel([
211
+			'class' => 'glsr-'.$this->args['type'].'-label',
212
+			'text' => $this->args['label'].'<span></span>',
213
+		]);
214
+	}
215
+
216
+	/**
217
+	 * @return string|void
218
+	 */
219
+	protected function buildFormInputMultiChoice()
220
+	{
221
+		if ('checkbox' == $this->args['type']) {
222
+			$this->args['name'] .= '[]';
223
+		}
224
+		$index = 0;
225
+		$options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
+			return $carry.$this->li($this->{$this->args['type']}([
227
+				'checked' => in_array($key, (array) $this->args['value']),
228
+				'id' => $this->args['id'].'-'.$index++,
229
+				'name' => $this->args['name'],
230
+				'text' => $this->args['options'][$key],
231
+				'value' => $key,
232
+			]));
233
+		});
234
+		return $this->ul($options, [
235
+			'class' => $this->args['class'],
236
+			'id' => $this->args['id'],
237
+		]);
238
+	}
239
+
240
+	/**
241
+	 * @return void|string
242
+	 */
243
+	protected function buildFormLabel(array $customArgs = [])
244
+	{
245
+		if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
246
+			return;
247
+		}
248
+		return $this->label(wp_parse_args($customArgs, [
249
+			'for' => $this->args['id'],
250
+			'is_public' => $this->args['is_public'],
251
+			'text' => $this->args['label'],
252
+			'type' => $this->args['type'],
253
+		]));
254
+	}
255
+
256
+	/**
257
+	 * @return string|void
258
+	 */
259
+	protected function buildFormSelect()
260
+	{
261
+		return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
262
+	}
263
+
264
+	/**
265
+	 * @return string|void
266
+	 */
267
+	protected function buildFormSelectOptions()
268
+	{
269
+		return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
+			return $carry.$this->option([
271
+				'selected' => $this->args['value'] === (string) $key,
272
+				'text' => $this->args['options'][$key],
273
+				'value' => $key,
274
+			]);
275
+		});
276
+	}
277
+
278
+	/**
279
+	 * @return string|void
280
+	 */
281
+	protected function buildFormTextarea()
282
+	{
283
+		return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
284
+	}
285
+
286
+	/**
287
+	 * @return string|void
288
+	 */
289
+	protected function buildTag()
290
+	{
291
+		$this->mergeArgsWithRequiredDefaults();
292
+		return $this->getTag();
293
+	}
294
+
295
+	/**
296
+	 * @return string
297
+	 */
298
+	protected function getCustomFieldClassName()
299
+	{
300
+		$classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
+		return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
302
+	}
303
+
304
+	/**
305
+	 * @return void
306
+	 */
307
+	protected function mergeArgsWithRequiredDefaults()
308
+	{
309
+		$className = $this->getCustomFieldClassName();
310
+		if (class_exists($className)) {
311
+			$this->args = $className::merge($this->args);
312
+		}
313
+		$this->args = glsr(BuilderDefaults::class)->merge($this->args);
314
+	}
315
+
316
+	/**
317
+	 * @param string|array ...$params
318
+	 * @return void
319
+	 */
320
+	protected function normalize(...$params)
321
+	{
322
+		$parameter1 = Arr::get($params, 0);
323
+		$parameter2 = Arr::get($params, 1);
324
+		if (is_string($parameter1) || is_numeric($parameter1)) {
325
+			$this->setNameOrTextAttributeForTag($parameter1);
326
+		}
327
+		if (is_array($parameter1)) {
328
+			$this->args += $parameter1;
329
+		} elseif (is_array($parameter2)) {
330
+			$this->args += $parameter2;
331
+		}
332
+		if (!isset($this->args['is_public'])) {
333
+			$this->args['is_public'] = false;
334
+		}
335
+	}
336
+
337
+	/**
338
+	 * @param string $value
339
+	 * @return void
340
+	 */
341
+	protected function setNameOrTextAttributeForTag($value)
342
+	{
343
+		$attribute = in_array($this->tag, static::TAGS_FORM)
344
+			? 'name'
345
+			: 'text';
346
+		$this->args[$attribute] = $value;
347
+	}
348
+
349
+	/**
350
+	 * @param string $method
351
+	 * @return void
352
+	 */
353
+	protected function setTagFromMethod($method)
354
+	{
355
+		$this->tag = strtolower($method);
356
+		if (in_array($this->tag, static::INPUT_TYPES)) {
357
+			$this->args['type'] = $this->tag;
358
+			$this->tag = 'input';
359
+		}
360
+	}
361 361
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
      * @param array $args
63 63
      * @return string|void
64 64
      */
65
-    public function __call($method, $args)
65
+    public function __call( $method, $args )
66 66
     {
67 67
         $instance = new static();
68
-        $instance->setTagFromMethod($method);
69
-        call_user_func_array([$instance, 'normalize'], $args);
70
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
71
-        do_action_ref_array('site-reviews/builder', [$instance]);
72
-        $generatedTag = in_array($instance->tag, $tags)
68
+        $instance->setTagFromMethod( $method );
69
+        call_user_func_array( [$instance, 'normalize'], $args );
70
+        $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT );
71
+        do_action_ref_array( 'site-reviews/builder', [$instance] );
72
+        $generatedTag = in_array( $instance->tag, $tags )
73 73
             ? $instance->buildTag()
74 74
             : $instance->buildCustomField();
75
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
76
-        if (!$this->render) {
75
+        $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance );
76
+        if( !$this->render ) {
77 77
             return $generatedTag;
78 78
         }
79 79
         echo $generatedTag;
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
      * @param mixed $value
85 85
      * @return void
86 86
      */
87
-    public function __set($property, $value)
87
+    public function __set( $property, $value )
88 88
     {
89 89
         $properties = [
90 90
             'args' => 'is_array',
91 91
             'render' => 'is_bool',
92 92
             'tag' => 'is_string',
93 93
         ];
94
-        if (array_key_exists($property, $properties) && !empty($value)) {
94
+        if( array_key_exists( $property, $properties ) && !empty($value) ) {
95 95
             $this->$property = $value;
96 96
         }
97 97
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function getClosingTag()
103 103
     {
104
-        if (!empty($this->tag)) {
104
+        if( !empty($this->tag) ) {
105 105
             return '</'.$this->tag.'>';
106 106
         }
107 107
     }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function getOpeningTag()
113 113
     {
114
-        if (!empty($this->tag)) {
115
-            $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
116
-            return '<'.trim($this->tag.' '.$attributes).'>';
114
+        if( !empty($this->tag) ) {
115
+            $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString();
116
+            return '<'.trim( $this->tag.' '.$attributes ).'>';
117 117
         }
118 118
     }
119 119
 
@@ -122,19 +122,19 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function getTag()
124 124
     {
125
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
125
+        if( in_array( $this->tag, static::TAGS_SINGLE ) ) {
126 126
             return $this->getOpeningTag();
127 127
         }
128
-        if (!in_array($this->tag, static::TAGS_FORM)) {
128
+        if( !in_array( $this->tag, static::TAGS_FORM ) ) {
129 129
             return $this->buildDefaultTag();
130 130
         }
131
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
131
+        return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription();
132 132
     }
133 133
 
134 134
     /**
135 135
      * @return string
136 136
      */
137
-    public function raw(array $field)
137
+    public function raw( array $field )
138 138
     {
139 139
         unset($field['label']);
140 140
         return $this->{$field['type']}($field);
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
     protected function buildCustomField()
147 147
     {
148 148
         $className = $this->getCustomFieldClassName();
149
-        if (class_exists($className)) {
150
-            return (new $className($this))->build();
149
+        if( class_exists( $className ) ) {
150
+            return (new $className( $this ))->build();
151 151
         }
152
-        glsr_log()->error('Field class missing: '.$className);
152
+        glsr_log()->error( 'Field class missing: '.$className );
153 153
     }
154 154
 
155 155
     /**
156 156
      * @return string|void
157 157
      */
158
-    protected function buildDefaultTag($text = '')
158
+    protected function buildDefaultTag( $text = '' )
159 159
     {
160
-        if (empty($text)) {
160
+        if( empty($text) ) {
161 161
             $text = $this->args['text'];
162 162
         }
163 163
         return $this->getOpeningTag().$text.$this->getClosingTag();
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
      */
169 169
     protected function buildFieldDescription()
170 170
     {
171
-        if (empty($this->args['description'])) {
171
+        if( empty($this->args['description']) ) {
172 172
             return;
173 173
         }
174
-        if ($this->args['is_widget']) {
175
-            return $this->small($this->args['description']);
174
+        if( $this->args['is_widget'] ) {
175
+            return $this->small( $this->args['description'] );
176 176
         }
177
-        return $this->p($this->args['description'], ['class' => 'description']);
177
+        return $this->p( $this->args['description'], ['class' => 'description'] );
178 178
     }
179 179
 
180 180
     /**
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function buildFormInput()
184 184
     {
185
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
186
-            if (isset($this->args['multiple'])) {
185
+        if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) {
186
+            if( isset($this->args['multiple']) ) {
187 187
                 $this->args['name'] .= '[]';
188 188
             }
189 189
             return $this->buildFormLabel().$this->getOpeningTag();
@@ -198,19 +198,19 @@  discard block
 block discarded – undo
198 198
      */
199 199
     protected function buildFormInputChoice()
200 200
     {
201
-        if (!empty($this->args['text'])) {
201
+        if( !empty($this->args['text']) ) {
202 202
             $this->args['label'] = $this->args['text'];
203 203
         }
204
-        if (!$this->args['is_public']) {
205
-            return $this->buildFormLabel([
204
+        if( !$this->args['is_public'] ) {
205
+            return $this->buildFormLabel( [
206 206
                 'class' => 'glsr-'.$this->args['type'].'-label',
207 207
                 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
208
-            ]);
208
+            ] );
209 209
         }
210
-        return $this->getOpeningTag().$this->buildFormLabel([
210
+        return $this->getOpeningTag().$this->buildFormLabel( [
211 211
             'class' => 'glsr-'.$this->args['type'].'-label',
212 212
             'text' => $this->args['label'].'<span></span>',
213
-        ]);
213
+        ] );
214 214
     }
215 215
 
216 216
     /**
@@ -218,39 +218,39 @@  discard block
 block discarded – undo
218 218
      */
219 219
     protected function buildFormInputMultiChoice()
220 220
     {
221
-        if ('checkbox' == $this->args['type']) {
221
+        if( 'checkbox' == $this->args['type'] ) {
222 222
             $this->args['name'] .= '[]';
223 223
         }
224 224
         $index = 0;
225
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
226
-            return $carry.$this->li($this->{$this->args['type']}([
227
-                'checked' => in_array($key, (array) $this->args['value']),
225
+        $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) {
226
+            return $carry.$this->li( $this->{$this->args['type']}([
227
+                'checked' => in_array( $key, (array)$this->args['value'] ),
228 228
                 'id' => $this->args['id'].'-'.$index++,
229 229
                 'name' => $this->args['name'],
230 230
                 'text' => $this->args['options'][$key],
231 231
                 'value' => $key,
232
-            ]));
232
+            ]) );
233 233
         });
234
-        return $this->ul($options, [
234
+        return $this->ul( $options, [
235 235
             'class' => $this->args['class'],
236 236
             'id' => $this->args['id'],
237
-        ]);
237
+        ] );
238 238
     }
239 239
 
240 240
     /**
241 241
      * @return void|string
242 242
      */
243
-    protected function buildFormLabel(array $customArgs = [])
243
+    protected function buildFormLabel( array $customArgs = [] )
244 244
     {
245
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
245
+        if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) {
246 246
             return;
247 247
         }
248
-        return $this->label(wp_parse_args($customArgs, [
248
+        return $this->label( wp_parse_args( $customArgs, [
249 249
             'for' => $this->args['id'],
250 250
             'is_public' => $this->args['is_public'],
251 251
             'text' => $this->args['label'],
252 252
             'type' => $this->args['type'],
253
-        ]));
253
+        ] ) );
254 254
     }
255 255
 
256 256
     /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     protected function buildFormSelect()
260 260
     {
261
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
261
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() );
262 262
     }
263 263
 
264 264
     /**
@@ -266,12 +266,12 @@  discard block
 block discarded – undo
266 266
      */
267 267
     protected function buildFormSelectOptions()
268 268
     {
269
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
270
-            return $carry.$this->option([
271
-                'selected' => $this->args['value'] === (string) $key,
269
+        return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) {
270
+            return $carry.$this->option( [
271
+                'selected' => $this->args['value'] === (string)$key,
272 272
                 'text' => $this->args['options'][$key],
273 273
                 'value' => $key,
274
-            ]);
274
+            ] );
275 275
         });
276 276
     }
277 277
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      */
281 281
     protected function buildFormTextarea()
282 282
     {
283
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
283
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] );
284 284
     }
285 285
 
286 286
     /**
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
      */
298 298
     protected function getCustomFieldClassName()
299 299
     {
300
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
301
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
300
+        $classname = Helper::buildClassName( $this->tag, __NAMESPACE__.'\Fields' );
301
+        return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname );
302 302
     }
303 303
 
304 304
     /**
@@ -307,29 +307,29 @@  discard block
 block discarded – undo
307 307
     protected function mergeArgsWithRequiredDefaults()
308 308
     {
309 309
         $className = $this->getCustomFieldClassName();
310
-        if (class_exists($className)) {
311
-            $this->args = $className::merge($this->args);
310
+        if( class_exists( $className ) ) {
311
+            $this->args = $className::merge( $this->args );
312 312
         }
313
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
313
+        $this->args = glsr( BuilderDefaults::class )->merge( $this->args );
314 314
     }
315 315
 
316 316
     /**
317 317
      * @param string|array ...$params
318 318
      * @return void
319 319
      */
320
-    protected function normalize(...$params)
320
+    protected function normalize( ...$params )
321 321
     {
322
-        $parameter1 = Arr::get($params, 0);
323
-        $parameter2 = Arr::get($params, 1);
324
-        if (is_string($parameter1) || is_numeric($parameter1)) {
325
-            $this->setNameOrTextAttributeForTag($parameter1);
322
+        $parameter1 = Arr::get( $params, 0 );
323
+        $parameter2 = Arr::get( $params, 1 );
324
+        if( is_string( $parameter1 ) || is_numeric( $parameter1 ) ) {
325
+            $this->setNameOrTextAttributeForTag( $parameter1 );
326 326
         }
327
-        if (is_array($parameter1)) {
327
+        if( is_array( $parameter1 ) ) {
328 328
             $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
329
+        } elseif( is_array( $parameter2 ) ) {
330 330
             $this->args += $parameter2;
331 331
         }
332
-        if (!isset($this->args['is_public'])) {
332
+        if( !isset($this->args['is_public']) ) {
333 333
             $this->args['is_public'] = false;
334 334
         }
335 335
     }
@@ -338,9 +338,9 @@  discard block
 block discarded – undo
338 338
      * @param string $value
339 339
      * @return void
340 340
      */
341
-    protected function setNameOrTextAttributeForTag($value)
341
+    protected function setNameOrTextAttributeForTag( $value )
342 342
     {
343
-        $attribute = in_array($this->tag, static::TAGS_FORM)
343
+        $attribute = in_array( $this->tag, static::TAGS_FORM )
344 344
             ? 'name'
345 345
             : 'text';
346 346
         $this->args[$attribute] = $value;
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
      * @param string $method
351 351
      * @return void
352 352
      */
353
-    protected function setTagFromMethod($method)
353
+    protected function setTagFromMethod( $method )
354 354
     {
355
-        $this->tag = strtolower($method);
356
-        if (in_array($this->tag, static::INPUT_TYPES)) {
355
+        $this->tag = strtolower( $method );
356
+        if( in_array( $this->tag, static::INPUT_TYPES ) ) {
357 357
             $this->args['type'] = $this->tag;
358 358
             $this->tag = 'input';
359 359
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -326,7 +326,8 @@
 block discarded – undo
326 326
         }
327 327
         if (is_array($parameter1)) {
328 328
             $this->args += $parameter1;
329
-        } elseif (is_array($parameter2)) {
329
+        }
330
+        elseif (is_array($parameter2)) {
330 331
             $this->args += $parameter2;
331 332
         }
332 333
         if (!isset($this->args['is_public'])) {
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -11,239 +11,239 @@
 block discarded – undo
11 11
 
12 12
 class Settings
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    public $settings;
18
-
19
-    /**
20
-     * @param string $id
21
-     * @return string
22
-     */
23
-    public function buildFields($id)
24
-    {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
-    }
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    protected function getFieldDefault(array $field)
37
-    {
38
-        return Arr::get($field, 'default');
39
-    }
40
-
41
-    /**
42
-     * @return string
43
-     */
44
-    protected function getFieldNameForDependsOn($path)
45
-    {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
48
-            ? $fieldName.'[]'
49
-            : $fieldName;
50
-    }
51
-
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function getSettingFields($path)
56
-    {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
60
-    }
61
-
62
-    /**
63
-     * @return string
64
-     */
65
-    protected function getSettingRows(array $fields)
66
-    {
67
-        $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
70
-                'is_setting' => true,
71
-                'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
74
-        }
75
-        return $rows;
76
-    }
77
-
78
-    /**
79
-     * @param string $id
80
-     * @return array
81
-     */
82
-    protected function getTemplateData($id)
83
-    {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
-        return [
86
-            'context' => [
87
-                'rows' => $this->getSettingRows($fields),
88
-            ],
89
-        ];
90
-    }
91
-
92
-    /**
93
-     * @param string $id
94
-     * @return array
95
-     */
96
-    protected function getTemplateDataForAddons($id)
97
-    {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertFromDotNotation($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
101
-        $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
107
-        }
108
-        ksort($results);
109
-        return [
110
-            'settings' => $results,
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * @param string $id
116
-     * @return array
117
-     */
118
-    protected function getTemplateDataForLicenses($id)
119
-    {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
122
-        return [
123
-            'context' => [
124
-                'rows' => $this->getSettingRows($fields),
125
-            ],
126
-        ];
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function getTemplateDataForTranslations()
133
-    {
134
-        $translations = glsr(Translation::class)->renderAll();
135
-        $class = empty($translations)
136
-            ? 'glsr-hidden'
137
-            : '';
138
-        return [
139
-            'context' => [
140
-                'class' => $class,
141
-                'database_key' => OptionManager::databaseKey(),
142
-                'translations' => $translations,
143
-            ],
144
-        ];
145
-    }
146
-
147
-    /**
148
-     * @param string $path
149
-     * @param string|array $expectedValue
150
-     * @return bool
151
-     */
152
-    protected function isFieldHidden($path, $expectedValue)
153
-    {
154
-        $optionValue = glsr(OptionManager::class)->get(
155
-            $path,
156
-            Arr::get(glsr()->defaults, $path)
157
-        );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
162
-        }
163
-        return $optionValue != $expectedValue;
164
-    }
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    protected function isMultiDependency($path)
170
-    {
171
-        if (isset($this->settings[$path])) {
172
-            $field = $this->settings[$path];
173
-            return ('checkbox' == $field['type'] && !empty($field['options']))
174
-                || !empty($field['multiple']);
175
-        }
176
-        return false;
177
-    }
178
-
179
-    /**
180
-     * @return array
181
-     */
182
-    protected function normalize(array $field)
183
-    {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
187
-        return $field;
188
-    }
189
-
190
-    /**
191
-     * @return array
192
-     */
193
-    protected function normalizeDependsOn(array $field)
194
-    {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
-            $isFieldHidden = false;
197
-            $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
199
-                $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
201
-                    'value' => $value,
202
-                ];
203
-                if ($this->isFieldHidden($path, $value)) {
204
-                    $isFieldHidden = true;
205
-                }
206
-            }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
-            $field['is_hidden'] = $isFieldHidden;
209
-        }
210
-        return $field;
211
-    }
212
-
213
-    /**
214
-     * @return array
215
-     */
216
-    protected function normalizeLabelAndLegend(array $field)
217
-    {
218
-        if (!empty($field['label'])) {
219
-            $field['legend'] = $field['label'];
220
-            unset($field['label']);
221
-        } else {
222
-            $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
224
-        }
225
-        return $field;
226
-    }
227
-
228
-    /**
229
-     * @return array
230
-     */
231
-    protected function normalizeValue(array $field)
232
-    {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
235
-                $field['name'],
236
-                $this->getFieldDefault($field)
237
-            );
238
-        }
239
-        return $field;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    protected function normalizeSettingPath($path)
246
-    {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
248
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	public $settings;
18
+
19
+	/**
20
+	 * @param string $id
21
+	 * @return string
22
+	 */
23
+	public function buildFields($id)
24
+	{
25
+		$this->settings = glsr(DefaultsManager::class)->settings();
26
+		$method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
+		$data = !method_exists($this, $method)
28
+			? $this->getTemplateData($id)
29
+			: $this->$method($id);
30
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
+	}
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	protected function getFieldDefault(array $field)
37
+	{
38
+		return Arr::get($field, 'default');
39
+	}
40
+
41
+	/**
42
+	 * @return string
43
+	 */
44
+	protected function getFieldNameForDependsOn($path)
45
+	{
46
+		$fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
+		return $this->isMultiDependency($path)
48
+			? $fieldName.'[]'
49
+			: $fieldName;
50
+	}
51
+
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function getSettingFields($path)
56
+	{
57
+		return array_filter($this->settings, function ($key) use ($path) {
58
+			return Str::startsWith($path, $key);
59
+		}, ARRAY_FILTER_USE_KEY);
60
+	}
61
+
62
+	/**
63
+	 * @return string
64
+	 */
65
+	protected function getSettingRows(array $fields)
66
+	{
67
+		$rows = '';
68
+		foreach ($fields as $name => $field) {
69
+			$field = wp_parse_args($field, [
70
+				'is_setting' => true,
71
+				'name' => $name,
72
+			]);
73
+			$rows.= new Field($this->normalize($field));
74
+		}
75
+		return $rows;
76
+	}
77
+
78
+	/**
79
+	 * @param string $id
80
+	 * @return array
81
+	 */
82
+	protected function getTemplateData($id)
83
+	{
84
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
+		return [
86
+			'context' => [
87
+				'rows' => $this->getSettingRows($fields),
88
+			],
89
+		];
90
+	}
91
+
92
+	/**
93
+	 * @param string $id
94
+	 * @return array
95
+	 */
96
+	protected function getTemplateDataForAddons($id)
97
+	{
98
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
+		$settings = Arr::convertFromDotNotation($fields);
100
+		$settingKeys = array_keys($settings['settings']['addons']);
101
+		$results = [];
102
+		foreach ($settingKeys as $key) {
103
+			$addonFields = array_filter($fields, function ($path) use ($key) {
104
+				return Str::startsWith('settings.addons.'.$key, $path);
105
+			}, ARRAY_FILTER_USE_KEY);
106
+			$results[$key] = $this->getSettingRows($addonFields);
107
+		}
108
+		ksort($results);
109
+		return [
110
+			'settings' => $results,
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * @param string $id
116
+	 * @return array
117
+	 */
118
+	protected function getTemplateDataForLicenses($id)
119
+	{
120
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
+		ksort($fields);
122
+		return [
123
+			'context' => [
124
+				'rows' => $this->getSettingRows($fields),
125
+			],
126
+		];
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function getTemplateDataForTranslations()
133
+	{
134
+		$translations = glsr(Translation::class)->renderAll();
135
+		$class = empty($translations)
136
+			? 'glsr-hidden'
137
+			: '';
138
+		return [
139
+			'context' => [
140
+				'class' => $class,
141
+				'database_key' => OptionManager::databaseKey(),
142
+				'translations' => $translations,
143
+			],
144
+		];
145
+	}
146
+
147
+	/**
148
+	 * @param string $path
149
+	 * @param string|array $expectedValue
150
+	 * @return bool
151
+	 */
152
+	protected function isFieldHidden($path, $expectedValue)
153
+	{
154
+		$optionValue = glsr(OptionManager::class)->get(
155
+			$path,
156
+			Arr::get(glsr()->defaults, $path)
157
+		);
158
+		if (is_array($expectedValue)) {
159
+			return is_array($optionValue)
160
+				? 0 === count(array_intersect($optionValue, $expectedValue))
161
+				: !in_array($optionValue, $expectedValue);
162
+		}
163
+		return $optionValue != $expectedValue;
164
+	}
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	protected function isMultiDependency($path)
170
+	{
171
+		if (isset($this->settings[$path])) {
172
+			$field = $this->settings[$path];
173
+			return ('checkbox' == $field['type'] && !empty($field['options']))
174
+				|| !empty($field['multiple']);
175
+		}
176
+		return false;
177
+	}
178
+
179
+	/**
180
+	 * @return array
181
+	 */
182
+	protected function normalize(array $field)
183
+	{
184
+		$field = $this->normalizeDependsOn($field);
185
+		$field = $this->normalizeLabelAndLegend($field);
186
+		$field = $this->normalizeValue($field);
187
+		return $field;
188
+	}
189
+
190
+	/**
191
+	 * @return array
192
+	 */
193
+	protected function normalizeDependsOn(array $field)
194
+	{
195
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
+			$isFieldHidden = false;
197
+			$conditions = [];
198
+			foreach ($field['depends_on'] as $path => $value) {
199
+				$conditions[] = [
200
+					'name' => $this->getFieldNameForDependsOn($path),
201
+					'value' => $value,
202
+				];
203
+				if ($this->isFieldHidden($path, $value)) {
204
+					$isFieldHidden = true;
205
+				}
206
+			}
207
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
+			$field['is_hidden'] = $isFieldHidden;
209
+		}
210
+		return $field;
211
+	}
212
+
213
+	/**
214
+	 * @return array
215
+	 */
216
+	protected function normalizeLabelAndLegend(array $field)
217
+	{
218
+		if (!empty($field['label'])) {
219
+			$field['legend'] = $field['label'];
220
+			unset($field['label']);
221
+		} else {
222
+			$field['is_valid'] = false;
223
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
224
+		}
225
+		return $field;
226
+	}
227
+
228
+	/**
229
+	 * @return array
230
+	 */
231
+	protected function normalizeValue(array $field)
232
+	{
233
+		if (!isset($field['value'])) {
234
+			$field['value'] = glsr(OptionManager::class)->get(
235
+				$field['name'],
236
+				$this->getFieldDefault($field)
237
+			);
238
+		}
239
+		return $field;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	protected function normalizeSettingPath($path)
246
+	{
247
+		return Str::prefix('settings.', rtrim($path, '.'));
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
      * @param string $id
21 21
      * @return string
22 22
      */
23
-    public function buildFields($id)
23
+    public function buildFields( $id )
24 24
     {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
25
+        $this->settings = glsr( DefaultsManager::class )->settings();
26
+        $method = Helper::buildMethodName( $id, 'getTemplateDataFor' );
27
+        $data = !method_exists( $this, $method )
28
+            ? $this->getTemplateData( $id )
29
+            : $this->$method( $id );
30
+        return glsr( Template::class )->build( 'pages/settings/'.$id, $data );
31 31
     }
32 32
 
33 33
     /**
34 34
      * @return string
35 35
      */
36
-    protected function getFieldDefault(array $field)
36
+    protected function getFieldDefault( array $field )
37 37
     {
38
-        return Arr::get($field, 'default');
38
+        return Arr::get( $field, 'default' );
39 39
     }
40 40
 
41 41
     /**
42 42
      * @return string
43 43
      */
44
-    protected function getFieldNameForDependsOn($path)
44
+    protected function getFieldNameForDependsOn( $path )
45 45
     {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
46
+        $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() );
47
+        return $this->isMultiDependency( $path )
48 48
             ? $fieldName.'[]'
49 49
             : $fieldName;
50 50
     }
@@ -52,25 +52,25 @@  discard block
 block discarded – undo
52 52
     /**
53 53
      * @return array
54 54
      */
55
-    protected function getSettingFields($path)
55
+    protected function getSettingFields( $path )
56 56
     {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
57
+        return array_filter( $this->settings, function( $key ) use ($path) {
58
+            return Str::startsWith( $path, $key );
59
+        }, ARRAY_FILTER_USE_KEY );
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return string
64 64
      */
65
-    protected function getSettingRows(array $fields)
65
+    protected function getSettingRows( array $fields )
66 66
     {
67 67
         $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
68
+        foreach( $fields as $name => $field ) {
69
+            $field = wp_parse_args( $field, [
70 70
                 'is_setting' => true,
71 71
                 'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
72
+            ] );
73
+            $rows .= new Field( $this->normalize( $field ) );
74 74
         }
75 75
         return $rows;
76 76
     }
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
      * @param string $id
80 80
      * @return array
81 81
      */
82
-    protected function getTemplateData($id)
82
+    protected function getTemplateData( $id )
83 83
     {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
84
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
85 85
         return [
86 86
             'context' => [
87
-                'rows' => $this->getSettingRows($fields),
87
+                'rows' => $this->getSettingRows( $fields ),
88 88
             ],
89 89
         ];
90 90
     }
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
      * @param string $id
94 94
      * @return array
95 95
      */
96
-    protected function getTemplateDataForAddons($id)
96
+    protected function getTemplateDataForAddons( $id )
97 97
     {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertFromDotNotation($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
98
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
99
+        $settings = Arr::convertFromDotNotation( $fields );
100
+        $settingKeys = array_keys( $settings['settings']['addons'] );
101 101
         $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
102
+        foreach( $settingKeys as $key ) {
103
+            $addonFields = array_filter( $fields, function( $path ) use ($key) {
104
+                return Str::startsWith( 'settings.addons.'.$key, $path );
105
+            }, ARRAY_FILTER_USE_KEY );
106
+            $results[$key] = $this->getSettingRows( $addonFields );
107 107
         }
108
-        ksort($results);
108
+        ksort( $results );
109 109
         return [
110 110
             'settings' => $results,
111 111
         ];
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
      * @param string $id
116 116
      * @return array
117 117
      */
118
-    protected function getTemplateDataForLicenses($id)
118
+    protected function getTemplateDataForLicenses( $id )
119 119
     {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
120
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
121
+        ksort( $fields );
122 122
         return [
123 123
             'context' => [
124
-                'rows' => $this->getSettingRows($fields),
124
+                'rows' => $this->getSettingRows( $fields ),
125 125
             ],
126 126
         ];
127 127
     }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function getTemplateDataForTranslations()
133 133
     {
134
-        $translations = glsr(Translation::class)->renderAll();
134
+        $translations = glsr( Translation::class )->renderAll();
135 135
         $class = empty($translations)
136 136
             ? 'glsr-hidden'
137 137
             : '';
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
      * @param string|array $expectedValue
150 150
      * @return bool
151 151
      */
152
-    protected function isFieldHidden($path, $expectedValue)
152
+    protected function isFieldHidden( $path, $expectedValue )
153 153
     {
154
-        $optionValue = glsr(OptionManager::class)->get(
154
+        $optionValue = glsr( OptionManager::class )->get(
155 155
             $path,
156
-            Arr::get(glsr()->defaults, $path)
156
+            Arr::get( glsr()->defaults, $path )
157 157
         );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
158
+        if( is_array( $expectedValue ) ) {
159
+            return is_array( $optionValue )
160
+                ? 0 === count( array_intersect( $optionValue, $expectedValue ) )
161
+                : !in_array( $optionValue, $expectedValue );
162 162
         }
163 163
         return $optionValue != $expectedValue;
164 164
     }
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return bool
168 168
      */
169
-    protected function isMultiDependency($path)
169
+    protected function isMultiDependency( $path )
170 170
     {
171
-        if (isset($this->settings[$path])) {
171
+        if( isset($this->settings[$path]) ) {
172 172
             $field = $this->settings[$path];
173 173
             return ('checkbox' == $field['type'] && !empty($field['options']))
174 174
                 || !empty($field['multiple']);
@@ -179,32 +179,32 @@  discard block
 block discarded – undo
179 179
     /**
180 180
      * @return array
181 181
      */
182
-    protected function normalize(array $field)
182
+    protected function normalize( array $field )
183 183
     {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
184
+        $field = $this->normalizeDependsOn( $field );
185
+        $field = $this->normalizeLabelAndLegend( $field );
186
+        $field = $this->normalizeValue( $field );
187 187
         return $field;
188 188
     }
189 189
 
190 190
     /**
191 191
      * @return array
192 192
      */
193
-    protected function normalizeDependsOn(array $field)
193
+    protected function normalizeDependsOn( array $field )
194 194
     {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
195
+        if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) {
196 196
             $isFieldHidden = false;
197 197
             $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
198
+            foreach( $field['depends_on'] as $path => $value ) {
199 199
                 $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
200
+                    'name' => $this->getFieldNameForDependsOn( $path ),
201 201
                     'value' => $value,
202 202
                 ];
203
-                if ($this->isFieldHidden($path, $value)) {
203
+                if( $this->isFieldHidden( $path, $value ) ) {
204 204
                     $isFieldHidden = true;
205 205
                 }
206 206
             }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
207
+            $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT );
208 208
             $field['is_hidden'] = $isFieldHidden;
209 209
         }
210 210
         return $field;
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
     /**
214 214
      * @return array
215 215
      */
216
-    protected function normalizeLabelAndLegend(array $field)
216
+    protected function normalizeLabelAndLegend( array $field )
217 217
     {
218
-        if (!empty($field['label'])) {
218
+        if( !empty($field['label']) ) {
219 219
             $field['legend'] = $field['label'];
220 220
             unset($field['label']);
221 221
         } else {
222 222
             $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
223
+            glsr_log()->warning( 'Setting field is missing a label' )->debug( $field );
224 224
         }
225 225
         return $field;
226 226
     }
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
     /**
229 229
      * @return array
230 230
      */
231
-    protected function normalizeValue(array $field)
231
+    protected function normalizeValue( array $field )
232 232
     {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
233
+        if( !isset($field['value']) ) {
234
+            $field['value'] = glsr( OptionManager::class )->get(
235 235
                 $field['name'],
236
-                $this->getFieldDefault($field)
236
+                $this->getFieldDefault( $field )
237 237
             );
238 238
         }
239 239
         return $field;
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
     /**
243 243
      * @return string
244 244
      */
245
-    protected function normalizeSettingPath($path)
245
+    protected function normalizeSettingPath( $path )
246 246
     {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
247
+        return Str::prefix( 'settings.', rtrim( $path, '.' ) );
248 248
     }
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Attributes.php 2 patches
Indentation   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -7,292 +7,292 @@
 block discarded – undo
7 7
 
8 8
 class Attributes
9 9
 {
10
-    const ATTRIBUTES_A = [
11
-        'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type',
12
-    ];
13
-
14
-    const ATTRIBUTES_BUTTON = [
15
-        'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod',
16
-        'formnovalidate', 'formtarget', 'name', 'type', 'value',
17
-    ];
18
-
19
-    const ATTRIBUTES_FORM = [
20
-        'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method',
21
-        'name', 'novalidate', 'target',
22
-    ];
23
-
24
-    const ATTRIBUTES_IMG = [
25
-        'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src',
26
-        'srcset', 'width', 'usemap',
27
-    ];
28
-
29
-    const ATTRIBUTES_INPUT = [
30
-        'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled',
31
-        'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height',
32
-        'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple',
33
-        'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection',
34
-        'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type',
35
-        'value', 'webkitdirectory', 'width',
36
-    ];
37
-
38
-    const ATTRIBUTES_LABEL = [
39
-        'for',
40
-    ];
41
-
42
-    const ATTRIBUTES_OPTION = [
43
-        'disabled', 'label', 'selected', 'value',
44
-    ];
45
-
46
-    const ATTRIBUTES_SELECT = [
47
-        'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size',
48
-    ];
49
-
50
-    const ATTRIBUTES_TEXTAREA = [
51
-        'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength',
52
-        'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap',
53
-    ];
54
-
55
-    const BOOLEAN_ATTRIBUTES = [
56
-        'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden',
57
-        'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck',
58
-        'webkitdirectory',
59
-    ];
60
-
61
-    const GLOBAL_ATTRIBUTES = [
62
-        'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone',
63
-        'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title',
64
-    ];
65
-
66
-    const GLOBAL_WILDCARD_ATTRIBUTES = [
67
-        'aria-', 'data-', 'item', 'on',
68
-    ];
69
-
70
-    const INPUT_TYPES = [
71
-        'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image',
72
-        'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text',
73
-        'time', 'url', 'week',
74
-    ];
75
-
76
-    /**
77
-     * @var array
78
-     */
79
-    protected $attributes = [];
80
-
81
-    /**
82
-     * @param string $method
83
-     * @param array $args
84
-     * @return static
85
-     */
86
-    public function __call($method, $args)
87
-    {
88
-        $constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
-        $allowedAttributeKeys = defined($constant)
90
-            ? constant($constant)
91
-            : [];
92
-        $this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
-        $this->normalizeInputType($method);
94
-        return $this;
95
-    }
96
-
97
-    /**
98
-     * @return static
99
-     */
100
-    public function set(array $attributes)
101
-    {
102
-        $this->normalize($attributes);
103
-        return $this;
104
-    }
105
-
106
-    /**
107
-     * @return array
108
-     */
109
-    public function toArray()
110
-    {
111
-        return $this->attributes;
112
-    }
113
-
114
-    /**
115
-     * @return string
116
-     */
117
-    public function toString()
118
-    {
119
-        $attributes = [];
120
-        foreach ($this->attributes as $attribute => $value) {
121
-            $quote = $this->getQuoteChar($attribute);
122
-            $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
123
-                ? $attribute
124
-                : $attribute.'='.$quote.implode(',', (array) $value).$quote;
125
-        }
126
-        return implode(' ', $attributes);
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function filterAttributes(array $allowedAttributeKeys)
133
-    {
134
-        return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
135
-    }
136
-
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function filterGlobalAttributes()
141
-    {
142
-        $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
143
-        $wildcards = [];
144
-        foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
-            $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
-                return Str::startsWith($wildcard, $key);
147
-            }, ARRAY_FILTER_USE_KEY);
148
-            $wildcards = array_merge($wildcards, $newWildcards);
149
-        }
150
-        return array_merge($globalAttributes, $wildcards);
151
-    }
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    protected function getPermanentAttributes()
157
-    {
158
-        $permanentAttributes = [];
159
-        if (array_key_exists('value', $this->attributes)) {
160
-            $permanentAttributes['value'] = $this->attributes['value'];
161
-        }
162
-        return $permanentAttributes;
163
-    }
164
-
165
-    /**
166
-     * @param string $attribute
167
-     * @return string
168
-     */
169
-    protected function getQuoteChar($attribute)
170
-    {
171
-        return Str::startsWith('data-', $attribute)
172
-            ? '\''
173
-            : '"';
174
-    }
175
-
176
-    /**
177
-     * @param string $key
178
-     * @param mixed $value
179
-     * @return bool
180
-     */
181
-    protected function isAttributeKeyNumeric($key, $value)
182
-    {
183
-        return is_string($value)
184
-            && is_numeric($key)
185
-            && !array_key_exists($value, $this->attributes);
186
-    }
187
-
188
-    /**
189
-     * @return void
190
-     */
191
-    protected function normalize(array $args, array $allowedAttributeKeys = [])
192
-    {
193
-        $this->attributes = array_change_key_case($args, CASE_LOWER);
194
-        $this->normalizeBooleanAttributes();
195
-        $this->normalizeDataAttributes();
196
-        $this->normalizeStringAttributes();
197
-        $this->removeEmptyAttributes();
198
-        $this->removeIndexedAttributes();
199
-        $this->attributes = array_merge(
200
-            $this->filterGlobalAttributes(),
201
-            $this->filterAttributes($allowedAttributeKeys)
202
-        );
203
-    }
204
-
205
-    /**
206
-     * @return void
207
-     */
208
-    protected function normalizeBooleanAttributes()
209
-    {
210
-        foreach ($this->attributes as $key => $value) {
211
-            if ($this->isAttributeKeyNumeric($key, $value)) {
212
-                $key = $value;
213
-                $value = true;
214
-            }
215
-            if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
216
-                continue;
217
-            }
218
-            $this->attributes[$key] = wp_validate_boolean($value);
219
-        }
220
-    }
221
-
222
-    /**
223
-     * @return void
224
-     */
225
-    protected function normalizeDataAttributes()
226
-    {
227
-        foreach ($this->attributes as $key => $value) {
228
-            if ($this->isAttributeKeyNumeric($key, $value)) {
229
-                $key = $value;
230
-                $value = '';
231
-            }
232
-            if (!Str::startsWith('data-', $key)) {
233
-                continue;
234
-            }
235
-            if (is_array($value)) {
236
-                $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
237
-            }
238
-            $this->attributes[$key] = $value;
239
-        }
240
-    }
241
-
242
-    /**
243
-     * @return void
244
-     */
245
-    protected function normalizeStringAttributes()
246
-    {
247
-        foreach ($this->attributes as $key => $value) {
248
-            if (is_string($value)) {
249
-                $this->attributes[$key] = trim($value);
250
-            }
251
-        }
252
-    }
253
-
254
-    /**
255
-     * @param string $method
256
-     * @return void
257
-     */
258
-    protected function normalizeInputType($method)
259
-    {
260
-        if ('input' != $method) {
261
-            return;
262
-        }
263
-        $attributes = wp_parse_args($this->attributes, ['type' => '']);
264
-        if (!in_array($attributes['type'], static::INPUT_TYPES)) {
265
-            $this->attributes['type'] = 'text';
266
-        }
267
-    }
268
-
269
-    /**
270
-     * @return void
271
-     */
272
-    protected function removeEmptyAttributes()
273
-    {
274
-        $attributes = $this->attributes;
275
-        $permanentAttributes = $this->getPermanentAttributes();
276
-        foreach ($this->attributes as $key => $value) {
277
-            if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
278
-                unset($attributes[$key]);
279
-            }
280
-            if (Str::startsWith('data-', $key)) {
281
-                $permanentAttributes[$key] = $value;
282
-                unset($attributes[$key]);
283
-            }
284
-        }
285
-        $this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
286
-    }
287
-
288
-    /**
289
-     * @return void
290
-     */
291
-    protected function removeIndexedAttributes()
292
-    {
293
-        $this->attributes = array_diff_key(
294
-            $this->attributes,
295
-            array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
296
-        );
297
-    }
10
+	const ATTRIBUTES_A = [
11
+		'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type',
12
+	];
13
+
14
+	const ATTRIBUTES_BUTTON = [
15
+		'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod',
16
+		'formnovalidate', 'formtarget', 'name', 'type', 'value',
17
+	];
18
+
19
+	const ATTRIBUTES_FORM = [
20
+		'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method',
21
+		'name', 'novalidate', 'target',
22
+	];
23
+
24
+	const ATTRIBUTES_IMG = [
25
+		'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src',
26
+		'srcset', 'width', 'usemap',
27
+	];
28
+
29
+	const ATTRIBUTES_INPUT = [
30
+		'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled',
31
+		'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height',
32
+		'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple',
33
+		'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection',
34
+		'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type',
35
+		'value', 'webkitdirectory', 'width',
36
+	];
37
+
38
+	const ATTRIBUTES_LABEL = [
39
+		'for',
40
+	];
41
+
42
+	const ATTRIBUTES_OPTION = [
43
+		'disabled', 'label', 'selected', 'value',
44
+	];
45
+
46
+	const ATTRIBUTES_SELECT = [
47
+		'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size',
48
+	];
49
+
50
+	const ATTRIBUTES_TEXTAREA = [
51
+		'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength',
52
+		'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap',
53
+	];
54
+
55
+	const BOOLEAN_ATTRIBUTES = [
56
+		'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden',
57
+		'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck',
58
+		'webkitdirectory',
59
+	];
60
+
61
+	const GLOBAL_ATTRIBUTES = [
62
+		'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone',
63
+		'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title',
64
+	];
65
+
66
+	const GLOBAL_WILDCARD_ATTRIBUTES = [
67
+		'aria-', 'data-', 'item', 'on',
68
+	];
69
+
70
+	const INPUT_TYPES = [
71
+		'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image',
72
+		'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text',
73
+		'time', 'url', 'week',
74
+	];
75
+
76
+	/**
77
+	 * @var array
78
+	 */
79
+	protected $attributes = [];
80
+
81
+	/**
82
+	 * @param string $method
83
+	 * @param array $args
84
+	 * @return static
85
+	 */
86
+	public function __call($method, $args)
87
+	{
88
+		$constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
+		$allowedAttributeKeys = defined($constant)
90
+			? constant($constant)
91
+			: [];
92
+		$this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
+		$this->normalizeInputType($method);
94
+		return $this;
95
+	}
96
+
97
+	/**
98
+	 * @return static
99
+	 */
100
+	public function set(array $attributes)
101
+	{
102
+		$this->normalize($attributes);
103
+		return $this;
104
+	}
105
+
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function toArray()
110
+	{
111
+		return $this->attributes;
112
+	}
113
+
114
+	/**
115
+	 * @return string
116
+	 */
117
+	public function toString()
118
+	{
119
+		$attributes = [];
120
+		foreach ($this->attributes as $attribute => $value) {
121
+			$quote = $this->getQuoteChar($attribute);
122
+			$attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
123
+				? $attribute
124
+				: $attribute.'='.$quote.implode(',', (array) $value).$quote;
125
+		}
126
+		return implode(' ', $attributes);
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function filterAttributes(array $allowedAttributeKeys)
133
+	{
134
+		return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
135
+	}
136
+
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function filterGlobalAttributes()
141
+	{
142
+		$globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
143
+		$wildcards = [];
144
+		foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
+			$newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
+				return Str::startsWith($wildcard, $key);
147
+			}, ARRAY_FILTER_USE_KEY);
148
+			$wildcards = array_merge($wildcards, $newWildcards);
149
+		}
150
+		return array_merge($globalAttributes, $wildcards);
151
+	}
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	protected function getPermanentAttributes()
157
+	{
158
+		$permanentAttributes = [];
159
+		if (array_key_exists('value', $this->attributes)) {
160
+			$permanentAttributes['value'] = $this->attributes['value'];
161
+		}
162
+		return $permanentAttributes;
163
+	}
164
+
165
+	/**
166
+	 * @param string $attribute
167
+	 * @return string
168
+	 */
169
+	protected function getQuoteChar($attribute)
170
+	{
171
+		return Str::startsWith('data-', $attribute)
172
+			? '\''
173
+			: '"';
174
+	}
175
+
176
+	/**
177
+	 * @param string $key
178
+	 * @param mixed $value
179
+	 * @return bool
180
+	 */
181
+	protected function isAttributeKeyNumeric($key, $value)
182
+	{
183
+		return is_string($value)
184
+			&& is_numeric($key)
185
+			&& !array_key_exists($value, $this->attributes);
186
+	}
187
+
188
+	/**
189
+	 * @return void
190
+	 */
191
+	protected function normalize(array $args, array $allowedAttributeKeys = [])
192
+	{
193
+		$this->attributes = array_change_key_case($args, CASE_LOWER);
194
+		$this->normalizeBooleanAttributes();
195
+		$this->normalizeDataAttributes();
196
+		$this->normalizeStringAttributes();
197
+		$this->removeEmptyAttributes();
198
+		$this->removeIndexedAttributes();
199
+		$this->attributes = array_merge(
200
+			$this->filterGlobalAttributes(),
201
+			$this->filterAttributes($allowedAttributeKeys)
202
+		);
203
+	}
204
+
205
+	/**
206
+	 * @return void
207
+	 */
208
+	protected function normalizeBooleanAttributes()
209
+	{
210
+		foreach ($this->attributes as $key => $value) {
211
+			if ($this->isAttributeKeyNumeric($key, $value)) {
212
+				$key = $value;
213
+				$value = true;
214
+			}
215
+			if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
216
+				continue;
217
+			}
218
+			$this->attributes[$key] = wp_validate_boolean($value);
219
+		}
220
+	}
221
+
222
+	/**
223
+	 * @return void
224
+	 */
225
+	protected function normalizeDataAttributes()
226
+	{
227
+		foreach ($this->attributes as $key => $value) {
228
+			if ($this->isAttributeKeyNumeric($key, $value)) {
229
+				$key = $value;
230
+				$value = '';
231
+			}
232
+			if (!Str::startsWith('data-', $key)) {
233
+				continue;
234
+			}
235
+			if (is_array($value)) {
236
+				$value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
237
+			}
238
+			$this->attributes[$key] = $value;
239
+		}
240
+	}
241
+
242
+	/**
243
+	 * @return void
244
+	 */
245
+	protected function normalizeStringAttributes()
246
+	{
247
+		foreach ($this->attributes as $key => $value) {
248
+			if (is_string($value)) {
249
+				$this->attributes[$key] = trim($value);
250
+			}
251
+		}
252
+	}
253
+
254
+	/**
255
+	 * @param string $method
256
+	 * @return void
257
+	 */
258
+	protected function normalizeInputType($method)
259
+	{
260
+		if ('input' != $method) {
261
+			return;
262
+		}
263
+		$attributes = wp_parse_args($this->attributes, ['type' => '']);
264
+		if (!in_array($attributes['type'], static::INPUT_TYPES)) {
265
+			$this->attributes['type'] = 'text';
266
+		}
267
+	}
268
+
269
+	/**
270
+	 * @return void
271
+	 */
272
+	protected function removeEmptyAttributes()
273
+	{
274
+		$attributes = $this->attributes;
275
+		$permanentAttributes = $this->getPermanentAttributes();
276
+		foreach ($this->attributes as $key => $value) {
277
+			if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
278
+				unset($attributes[$key]);
279
+			}
280
+			if (Str::startsWith('data-', $key)) {
281
+				$permanentAttributes[$key] = $value;
282
+				unset($attributes[$key]);
283
+			}
284
+		}
285
+		$this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
286
+	}
287
+
288
+	/**
289
+	 * @return void
290
+	 */
291
+	protected function removeIndexedAttributes()
292
+	{
293
+		$this->attributes = array_diff_key(
294
+			$this->attributes,
295
+			array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
296
+		);
297
+	}
298 298
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
      * @param array $args
84 84
      * @return static
85 85
      */
86
-    public function __call($method, $args)
86
+    public function __call( $method, $args )
87 87
     {
88
-        $constant = 'static::ATTRIBUTES_'.strtoupper($method);
89
-        $allowedAttributeKeys = defined($constant)
90
-            ? constant($constant)
88
+        $constant = 'static::ATTRIBUTES_'.strtoupper( $method );
89
+        $allowedAttributeKeys = defined( $constant )
90
+            ? constant( $constant )
91 91
             : [];
92
-        $this->normalize(Arr::consolidate(Arr::get($args, 0)), $allowedAttributeKeys);
93
-        $this->normalizeInputType($method);
92
+        $this->normalize( Arr::consolidate( Arr::get( $args, 0 ) ), $allowedAttributeKeys );
93
+        $this->normalizeInputType( $method );
94 94
         return $this;
95 95
     }
96 96
 
97 97
     /**
98 98
      * @return static
99 99
      */
100
-    public function set(array $attributes)
100
+    public function set( array $attributes )
101 101
     {
102
-        $this->normalize($attributes);
102
+        $this->normalize( $attributes );
103 103
         return $this;
104 104
     }
105 105
 
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
     public function toString()
118 118
     {
119 119
         $attributes = [];
120
-        foreach ($this->attributes as $attribute => $value) {
121
-            $quote = $this->getQuoteChar($attribute);
122
-            $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES)
120
+        foreach( $this->attributes as $attribute => $value ) {
121
+            $quote = $this->getQuoteChar( $attribute );
122
+            $attributes[] = in_array( $attribute, static::BOOLEAN_ATTRIBUTES )
123 123
                 ? $attribute
124
-                : $attribute.'='.$quote.implode(',', (array) $value).$quote;
124
+                : $attribute.'='.$quote.implode( ',', (array)$value ).$quote;
125 125
         }
126
-        return implode(' ', $attributes);
126
+        return implode( ' ', $attributes );
127 127
     }
128 128
 
129 129
     /**
130 130
      * @return array
131 131
      */
132
-    protected function filterAttributes(array $allowedAttributeKeys)
132
+    protected function filterAttributes( array $allowedAttributeKeys )
133 133
     {
134
-        return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys));
134
+        return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) );
135 135
     }
136 136
 
137 137
     /**
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function filterGlobalAttributes()
141 141
     {
142
-        $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES);
142
+        $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES );
143 143
         $wildcards = [];
144
-        foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
145
-            $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) {
146
-                return Str::startsWith($wildcard, $key);
147
-            }, ARRAY_FILTER_USE_KEY);
148
-            $wildcards = array_merge($wildcards, $newWildcards);
144
+        foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) {
145
+            $newWildcards = array_filter( $this->attributes, function( $key ) use ($wildcard) {
146
+                return Str::startsWith( $wildcard, $key );
147
+            }, ARRAY_FILTER_USE_KEY );
148
+            $wildcards = array_merge( $wildcards, $newWildcards );
149 149
         }
150
-        return array_merge($globalAttributes, $wildcards);
150
+        return array_merge( $globalAttributes, $wildcards );
151 151
     }
152 152
 
153 153
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     protected function getPermanentAttributes()
157 157
     {
158 158
         $permanentAttributes = [];
159
-        if (array_key_exists('value', $this->attributes)) {
159
+        if( array_key_exists( 'value', $this->attributes ) ) {
160 160
             $permanentAttributes['value'] = $this->attributes['value'];
161 161
         }
162 162
         return $permanentAttributes;
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
      * @param string $attribute
167 167
      * @return string
168 168
      */
169
-    protected function getQuoteChar($attribute)
169
+    protected function getQuoteChar( $attribute )
170 170
     {
171
-        return Str::startsWith('data-', $attribute)
171
+        return Str::startsWith( 'data-', $attribute )
172 172
             ? '\''
173 173
             : '"';
174 174
     }
@@ -178,19 +178,19 @@  discard block
 block discarded – undo
178 178
      * @param mixed $value
179 179
      * @return bool
180 180
      */
181
-    protected function isAttributeKeyNumeric($key, $value)
181
+    protected function isAttributeKeyNumeric( $key, $value )
182 182
     {
183
-        return is_string($value)
184
-            && is_numeric($key)
185
-            && !array_key_exists($value, $this->attributes);
183
+        return is_string( $value )
184
+            && is_numeric( $key )
185
+            && !array_key_exists( $value, $this->attributes );
186 186
     }
187 187
 
188 188
     /**
189 189
      * @return void
190 190
      */
191
-    protected function normalize(array $args, array $allowedAttributeKeys = [])
191
+    protected function normalize( array $args, array $allowedAttributeKeys = [] )
192 192
     {
193
-        $this->attributes = array_change_key_case($args, CASE_LOWER);
193
+        $this->attributes = array_change_key_case( $args, CASE_LOWER );
194 194
         $this->normalizeBooleanAttributes();
195 195
         $this->normalizeDataAttributes();
196 196
         $this->normalizeStringAttributes();
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         $this->removeIndexedAttributes();
199 199
         $this->attributes = array_merge(
200 200
             $this->filterGlobalAttributes(),
201
-            $this->filterAttributes($allowedAttributeKeys)
201
+            $this->filterAttributes( $allowedAttributeKeys )
202 202
         );
203 203
     }
204 204
 
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
      */
208 208
     protected function normalizeBooleanAttributes()
209 209
     {
210
-        foreach ($this->attributes as $key => $value) {
211
-            if ($this->isAttributeKeyNumeric($key, $value)) {
210
+        foreach( $this->attributes as $key => $value ) {
211
+            if( $this->isAttributeKeyNumeric( $key, $value ) ) {
212 212
                 $key = $value;
213 213
                 $value = true;
214 214
             }
215
-            if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) {
215
+            if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) ) {
216 216
                 continue;
217 217
             }
218
-            $this->attributes[$key] = wp_validate_boolean($value);
218
+            $this->attributes[$key] = wp_validate_boolean( $value );
219 219
         }
220 220
     }
221 221
 
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
      */
225 225
     protected function normalizeDataAttributes()
226 226
     {
227
-        foreach ($this->attributes as $key => $value) {
228
-            if ($this->isAttributeKeyNumeric($key, $value)) {
227
+        foreach( $this->attributes as $key => $value ) {
228
+            if( $this->isAttributeKeyNumeric( $key, $value ) ) {
229 229
                 $key = $value;
230 230
                 $value = '';
231 231
             }
232
-            if (!Str::startsWith('data-', $key)) {
232
+            if( !Str::startsWith( 'data-', $key ) ) {
233 233
                 continue;
234 234
             }
235
-            if (is_array($value)) {
236
-                $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
235
+            if( is_array( $value ) ) {
236
+                $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
237 237
             }
238 238
             $this->attributes[$key] = $value;
239 239
         }
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
      */
245 245
     protected function normalizeStringAttributes()
246 246
     {
247
-        foreach ($this->attributes as $key => $value) {
248
-            if (is_string($value)) {
249
-                $this->attributes[$key] = trim($value);
247
+        foreach( $this->attributes as $key => $value ) {
248
+            if( is_string( $value ) ) {
249
+                $this->attributes[$key] = trim( $value );
250 250
             }
251 251
         }
252 252
     }
@@ -255,13 +255,13 @@  discard block
 block discarded – undo
255 255
      * @param string $method
256 256
      * @return void
257 257
      */
258
-    protected function normalizeInputType($method)
258
+    protected function normalizeInputType( $method )
259 259
     {
260
-        if ('input' != $method) {
260
+        if( 'input' != $method ) {
261 261
             return;
262 262
         }
263
-        $attributes = wp_parse_args($this->attributes, ['type' => '']);
264
-        if (!in_array($attributes['type'], static::INPUT_TYPES)) {
263
+        $attributes = wp_parse_args( $this->attributes, ['type' => ''] );
264
+        if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) {
265 265
             $this->attributes['type'] = 'text';
266 266
         }
267 267
     }
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
     {
274 274
         $attributes = $this->attributes;
275 275
         $permanentAttributes = $this->getPermanentAttributes();
276
-        foreach ($this->attributes as $key => $value) {
277
-            if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) {
276
+        foreach( $this->attributes as $key => $value ) {
277
+            if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) {
278 278
                 unset($attributes[$key]);
279 279
             }
280
-            if (Str::startsWith('data-', $key)) {
280
+            if( Str::startsWith( 'data-', $key ) ) {
281 281
                 $permanentAttributes[$key] = $value;
282 282
                 unset($attributes[$key]);
283 283
             }
284 284
         }
285
-        $this->attributes = array_merge(array_filter($attributes), $permanentAttributes);
285
+        $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes );
286 286
     }
287 287
 
288 288
     /**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $this->attributes = array_diff_key(
294 294
             $this->attributes,
295
-            array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY)
295
+            array_filter( $this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY )
296 296
         );
297 297
     }
298 298
 }
Please login to merge, or discard this patch.
plugin/Modules/System.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -13,378 +13,378 @@
 block discarded – undo
13 13
 
14 14
 class System
15 15
 {
16
-    const PAD = 40;
16
+	const PAD = 40;
17 17
 
18
-    /**
19
-     * @return string
20
-     */
21
-    public function __toString()
22
-    {
23
-        return $this->get();
24
-    }
18
+	/**
19
+	 * @return string
20
+	 */
21
+	public function __toString()
22
+	{
23
+		return $this->get();
24
+	}
25 25
 
26
-    /**
27
-     * @return string
28
-     */
29
-    public function get()
30
-    {
31
-        $details = [
32
-            'plugin' => 'Plugin Details',
33
-            'addon' => 'Addon Details',
34
-            'browser' => 'Browser Details',
35
-            'server' => 'Server Details',
36
-            'php' => 'PHP Configuration',
37
-            'wordpress' => 'WordPress Configuration',
38
-            'mu-plugin' => 'Must-Use Plugins',
39
-            'multisite-plugin' => 'Network Active Plugins',
40
-            'active-plugin' => 'Active Plugins',
41
-            'inactive-plugin' => 'Inactive Plugins',
42
-            'setting' => 'Plugin Settings',
43
-            'reviews' => 'Review Counts',
44
-        ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
-                return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
51
-                );
52
-            }
53
-            return $carry;
54
-        });
55
-        return trim($systemInfo);
56
-    }
26
+	/**
27
+	 * @return string
28
+	 */
29
+	public function get()
30
+	{
31
+		$details = [
32
+			'plugin' => 'Plugin Details',
33
+			'addon' => 'Addon Details',
34
+			'browser' => 'Browser Details',
35
+			'server' => 'Server Details',
36
+			'php' => 'PHP Configuration',
37
+			'wordpress' => 'WordPress Configuration',
38
+			'mu-plugin' => 'Must-Use Plugins',
39
+			'multisite-plugin' => 'Network Active Plugins',
40
+			'active-plugin' => 'Active Plugins',
41
+			'inactive-plugin' => 'Inactive Plugins',
42
+			'setting' => 'Plugin Settings',
43
+			'reviews' => 'Review Counts',
44
+		];
45
+		$systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
+			$methodName = Helper::buildMethodName('get-'.$key.'-details');
47
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
+				return $carry.$this->implode(
49
+					strtoupper($details[$key]),
50
+					apply_filters('site-reviews/system/'.$key, $systemDetails)
51
+				);
52
+			}
53
+			return $carry;
54
+		});
55
+		return trim($systemInfo);
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function getActivePluginDetails()
62
-    {
63
-        $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
-    }
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function getActivePluginDetails()
62
+	{
63
+		$plugins = get_plugins();
64
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
66
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
+	}
68 68
 
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAddonDetails()
73
-    {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
76
-        return $details;
77
-    }
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAddonDetails()
73
+	{
74
+		$details = apply_filters('site-reviews/addon/system-info', []);
75
+		ksort($details);
76
+		return $details;
77
+	}
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getBrowserDetails()
83
-    {
84
-        $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
88
-        return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
90
-            'Browser UA' => $userAgent,
91
-        ];
92
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getBrowserDetails()
83
+	{
84
+		$browser = new Browser();
85
+		$name = esc_attr($browser->getName());
86
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
+		$version = esc_attr($browser->getVersion());
88
+		return [
89
+			'Browser Name' => sprintf('%s %s', $name, $version),
90
+			'Browser UA' => $userAgent,
91
+		];
92
+	}
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    public function getInactivePluginDetails()
98
-    {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
-        $multisitePlugins = $this->getMultisitePluginDetails();
102
-        return empty($multisitePlugins)
103
-            ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
105
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function getInactivePluginDetails()
98
+	{
99
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
+		$inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
+		$multisitePlugins = $this->getMultisitePluginDetails();
102
+		return empty($multisitePlugins)
103
+			? $inactivePlugins
104
+			: array_diff($inactivePlugins, $multisitePlugins);
105
+	}
106 106
 
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getMuPluginDetails()
111
-    {
112
-        if (empty($plugins = get_mu_plugins())) {
113
-            return [];
114
-        }
115
-        return $this->normalizePluginList($plugins);
116
-    }
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getMuPluginDetails()
111
+	{
112
+		if (empty($plugins = get_mu_plugins())) {
113
+			return [];
114
+		}
115
+		return $this->normalizePluginList($plugins);
116
+	}
117 117
 
118
-    /**
119
-     * @return array
120
-     */
121
-    public function getMultisitePluginDetails()
122
-    {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
125
-            return [];
126
-        }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
-    }
118
+	/**
119
+	 * @return array
120
+	 */
121
+	public function getMultisitePluginDetails()
122
+	{
123
+		$activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
+		if (!is_multisite() || empty($activePlugins)) {
125
+			return [];
126
+		}
127
+		return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
+	}
129 129
 
130
-    /**
131
-     * @return array
132
-     */
133
-    public function getPhpDetails()
134
-    {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
137
-            : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
140
-            : 'false';
141
-        return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
144
-            'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
146
-            'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
-        ];
161
-    }
130
+	/**
131
+	 * @return array
132
+	 */
133
+	public function getPhpDetails()
134
+	{
135
+		$displayErrors = $this->getINI('display_errors', null)
136
+			? 'On ('.$this->getINI('display_errors').')'
137
+			: 'N/A';
138
+		$intlSupport = extension_loaded('intl')
139
+			? phpversion('intl')
140
+			: 'false';
141
+		return [
142
+			'cURL' => var_export(function_exists('curl_init'), true),
143
+			'Default Charset' => $this->getINI('default_charset'),
144
+			'Display Errors' => $displayErrors,
145
+			'fsockopen' => var_export(function_exists('fsockopen'), true),
146
+			'Intl' => $intlSupport,
147
+			'IPv6' => var_export(defined('AF_INET6'), true),
148
+			'Max Execution Time' => $this->getINI('max_execution_time'),
149
+			'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
+			'Max Input Vars' => $this->getINI('max_input_vars'),
151
+			'Memory Limit' => $this->getINI('memory_limit'),
152
+			'Post Max Size' => $this->getINI('post_max_size'),
153
+			'Sendmail Path' => $this->getINI('sendmail_path'),
154
+			'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
+			'Session Name' => esc_html($this->getINI('session.name')),
156
+			'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
+			'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
+			'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
+			'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
+		];
161
+	}
162 162
 
163
-    /**
164
-     * @return array
165
-     */
166
-    public function getReviewsDetails()
167
-    {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flatten($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
-                return;
174
-            }
175
-            glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
179
-        });
180
-        ksort($counts);
181
-        return $counts;
182
-    }
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function getReviewsDetails()
167
+	{
168
+		$counts = glsr(CountsManager::class)->getCounts();
169
+		$counts = Arr::flatten($counts);
170
+		array_walk($counts, function (&$ratings) use ($counts) {
171
+			if (is_array($ratings)) {
172
+				$ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
+				return;
174
+			}
175
+			glsr_log()
176
+				->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
+				->debug($ratings)
178
+				->debug($counts);
179
+		});
180
+		ksort($counts);
181
+		return $counts;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     */
187
-    public function getServerDetails()
188
-    {
189
-        global $wpdb;
190
-        return [
191
-            'Host Name' => $this->getHostName(),
192
-            'MySQL Version' => $wpdb->db_version(),
193
-            'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
-        ];
196
-    }
184
+	/**
185
+	 * @return array
186
+	 */
187
+	public function getServerDetails()
188
+	{
189
+		global $wpdb;
190
+		return [
191
+			'Host Name' => $this->getHostName(),
192
+			'MySQL Version' => $wpdb->db_version(),
193
+			'PHP Version' => PHP_VERSION,
194
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
+		];
196
+	}
197 197
 
198
-    /**
199
-     * @return array
200
-     */
201
-    public function getSettingDetails()
202
-    {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flatten($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
207
-        $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
-                continue;
211
-            }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
-            $details[$key] = $value;
214
-        }
215
-        return $details;
216
-    }
198
+	/**
199
+	 * @return array
200
+	 */
201
+	public function getSettingDetails()
202
+	{
203
+		$settings = glsr(OptionManager::class)->get('settings', []);
204
+		$settings = Arr::flatten($settings, true);
205
+		$settings = $this->purgeSensitiveData($settings);
206
+		ksort($settings);
207
+		$details = [];
208
+		foreach ($settings as $key => $value) {
209
+			if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
+				continue;
211
+			}
212
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
+			$details[$key] = $value;
214
+		}
215
+		return $details;
216
+	}
217 217
 
218
-    /**
219
-     * @return array
220
-     */
221
-    public function getPluginDetails()
222
-    {
223
-        return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
-            'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
-        ];
231
-    }
218
+	/**
219
+	 * @return array
220
+	 */
221
+	public function getPluginDetails()
222
+	{
223
+		return [
224
+			'Console level' => glsr(Console::class)->humanLevel(),
225
+			'Console size' => glsr(Console::class)->humanSize('0'),
226
+			'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
+			'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
+			'Version (current)' => glsr()->version,
229
+			'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
+		];
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    public function getWordpressDetails()
237
-    {
238
-        global $wpdb;
239
-        $theme = wp_get_theme();
240
-        return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
-            'Home URL' => home_url(),
244
-            'Language' => get_locale(),
245
-            'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
-            'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
-            'WP Memory Limit' => WP_MEMORY_LIMIT,
259
-        ];
260
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	public function getWordpressDetails()
237
+	{
238
+		global $wpdb;
239
+		$theme = wp_get_theme();
240
+		return [
241
+			'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
+			'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
+			'Home URL' => home_url(),
244
+			'Language' => get_locale(),
245
+			'Memory Limit' => WP_MEMORY_LIMIT,
246
+			'Multisite' => var_export(is_multisite(), true),
247
+			'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
+			'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
+			'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
+			'Post Stati' => implode(', ', get_post_stati()),
251
+			'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
+			'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
+			'Site URL' => site_url(),
254
+			'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
+			'Version' => get_bloginfo('version'),
256
+			'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
+			'WP Memory Limit' => WP_MEMORY_LIMIT,
259
+		];
260
+	}
261 261
 
262
-    /**
263
-     * @return string
264
-     */
265
-    protected function detectWebhostProvider()
266
-    {
267
-        $checks = [
268
-            '.accountservergroup.com' => 'Site5',
269
-            '.gridserver.com' => 'MediaTemple Grid',
270
-            '.inmotionhosting.com' => 'InMotion Hosting',
271
-            '.ovh.net' => 'OVH',
272
-            '.pair.com' => 'pair Networks',
273
-            '.stabletransit.com' => 'Rackspace Cloud',
274
-            '.stratoserver.net' => 'STRATO',
275
-            '.sysfix.eu' => 'SysFix.eu Power Hosting',
276
-            'bluehost.com' => 'Bluehost',
277
-            'DH_USER' => 'DreamHost',
278
-            'Flywheel' => 'Flywheel',
279
-            'ipagemysql.com' => 'iPage',
280
-            'ipowermysql.com' => 'IPower',
281
-            'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
-            'mysqlv5' => 'NetworkSolutions',
283
-            'PAGELYBIN' => 'Pagely',
284
-            'secureserver.net' => 'GoDaddy',
285
-            'WPE_APIKEY' => 'WP Engine',
286
-        ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
289
-                continue;
290
-            }
291
-            return $value;
292
-        }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
-    }
262
+	/**
263
+	 * @return string
264
+	 */
265
+	protected function detectWebhostProvider()
266
+	{
267
+		$checks = [
268
+			'.accountservergroup.com' => 'Site5',
269
+			'.gridserver.com' => 'MediaTemple Grid',
270
+			'.inmotionhosting.com' => 'InMotion Hosting',
271
+			'.ovh.net' => 'OVH',
272
+			'.pair.com' => 'pair Networks',
273
+			'.stabletransit.com' => 'Rackspace Cloud',
274
+			'.stratoserver.net' => 'STRATO',
275
+			'.sysfix.eu' => 'SysFix.eu Power Hosting',
276
+			'bluehost.com' => 'Bluehost',
277
+			'DH_USER' => 'DreamHost',
278
+			'Flywheel' => 'Flywheel',
279
+			'ipagemysql.com' => 'iPage',
280
+			'ipowermysql.com' => 'IPower',
281
+			'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
+			'mysqlv5' => 'NetworkSolutions',
283
+			'PAGELYBIN' => 'Pagely',
284
+			'secureserver.net' => 'GoDaddy',
285
+			'WPE_APIKEY' => 'WP Engine',
286
+		];
287
+		foreach ($checks as $key => $value) {
288
+			if (!$this->isWebhostCheckValid($key)) {
289
+				continue;
290
+			}
291
+			return $value;
292
+		}
293
+		return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
+	}
295 295
 
296
-    /**
297
-     * @return string
298
-     */
299
-    protected function getHostName()
300
-    {
301
-        return sprintf('%s (%s)',
302
-            $this->detectWebhostProvider(),
303
-            Helper::getIpAddress()
304
-        );
305
-    }
296
+	/**
297
+	 * @return string
298
+	 */
299
+	protected function getHostName()
300
+	{
301
+		return sprintf('%s (%s)',
302
+			$this->detectWebhostProvider(),
303
+			Helper::getIpAddress()
304
+		);
305
+	}
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
-    {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
311
-            : $disabledValue;
312
-    }
307
+	protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
+	{
309
+		return function_exists('ini_get')
310
+			? ini_get($name)
311
+			: $disabledValue;
312
+	}
313 313
 
314
-    /**
315
-     * @return array
316
-     */
317
-    protected function getWordpressPlugins()
318
-    {
319
-        $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
-        return $active + $inactive;
324
-    }
314
+	/**
315
+	 * @return array
316
+	 */
317
+	protected function getWordpressPlugins()
318
+	{
319
+		$plugins = get_plugins();
320
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
+		return $active + $inactive;
324
+	}
325 325
 
326
-    /**
327
-     * @param string $title
328
-     * @return string
329
-     */
330
-    protected function implode($title, array $details)
331
-    {
332
-        $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
-                : ' - '.$value;
339
-        }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
-    }
326
+	/**
327
+	 * @param string $title
328
+	 * @return string
329
+	 */
330
+	protected function implode($title, array $details)
331
+	{
332
+		$strings = ['['.$title.']'];
333
+		$padding = max(array_map('strlen', array_keys($details)));
334
+		$padding = max([$padding, static::PAD]);
335
+		foreach ($details as $key => $value) {
336
+			$strings[] = is_string($key)
337
+				? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
+				: ' - '.$value;
339
+		}
340
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
+	}
342 342
 
343
-    /**
344
-     * @param string $key
345
-     * @return bool
346
-     */
347
-    protected function isWebhostCheckValid($key)
348
-    {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
354
-    }
343
+	/**
344
+	 * @param string $key
345
+	 * @return bool
346
+	 */
347
+	protected function isWebhostCheckValid($key)
348
+	{
349
+		return defined($key)
350
+			|| filter_input(INPUT_SERVER, $key)
351
+			|| Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
+			|| Str::contains(DB_HOST, $key)
353
+			|| Str::contains(php_uname(), $key);
354
+	}
355 355
 
356
-    /**
357
-     * @return array
358
-     */
359
-    protected function normalizePluginList(array $plugins)
360
-    {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
366
-    }
356
+	/**
357
+	 * @return array
358
+	 */
359
+	protected function normalizePluginList(array $plugins)
360
+	{
361
+		$plugins = array_map(function ($plugin) {
362
+			return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
+		}, $plugins);
364
+		natcasesort($plugins);
365
+		return array_flip($plugins);
366
+	}
367 367
 
368
-    /**
369
-     * @return array
370
-     */
371
-    protected function purgeSensitiveData(array $settings)
372
-    {
373
-        $keys = [
374
-            'general.trustalyze_serial',
375
-            'licenses.',
376
-            'submissions.recaptcha.key',
377
-            'submissions.recaptcha.secret',
378
-        ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
382
-                    continue;
383
-                }
384
-                $value = str_repeat('•', 13);
385
-                return;
386
-            }
387
-        });
388
-        return $settings;
389
-    }
368
+	/**
369
+	 * @return array
370
+	 */
371
+	protected function purgeSensitiveData(array $settings)
372
+	{
373
+		$keys = [
374
+			'general.trustalyze_serial',
375
+			'licenses.',
376
+			'submissions.recaptcha.key',
377
+			'submissions.recaptcha.secret',
378
+		];
379
+		array_walk($settings, function (&$value, $setting) use ($keys) {
380
+			foreach ($keys as $key) {
381
+				if (!Str::startsWith($key, $setting) || empty($value)) {
382
+					continue;
383
+				}
384
+				$value = str_repeat('•', 13);
385
+				return;
386
+			}
387
+		});
388
+		return $settings;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
             'setting' => 'Plugin Settings',
43 43
             'reviews' => 'Review Counts',
44 44
         ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
45
+        $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) {
46
+            $methodName = Helper::buildMethodName( 'get-'.$key.'-details' );
47
+            if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) {
48 48
                 return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
49
+                    strtoupper( $details[$key] ),
50
+                    apply_filters( 'site-reviews/system/'.$key, $systemDetails )
51 51
                 );
52 52
             }
53 53
             return $carry;
54 54
         });
55
-        return trim($systemInfo);
55
+        return trim( $systemInfo );
56 56
     }
57 57
 
58 58
     /**
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
     public function getActivePluginDetails()
62 62
     {
63 63
         $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
64
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
65
+        $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) );
66
+        return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
67 67
     }
68 68
 
69 69
     /**
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function getAddonDetails()
73 73
     {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
74
+        $details = apply_filters( 'site-reviews/addon/system-info', [] );
75
+        ksort( $details );
76 76
         return $details;
77 77
     }
78 78
 
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
     public function getBrowserDetails()
83 83
     {
84 84
         $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
85
+        $name = esc_attr( $browser->getName() );
86
+        $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() );
87
+        $version = esc_attr( $browser->getVersion() );
88 88
         return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
89
+            'Browser Name' => sprintf( '%s %s', $name, $version ),
90 90
             'Browser UA' => $userAgent,
91 91
         ];
92 92
     }
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public function getInactivePluginDetails()
98 98
     {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
99
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
100
+        $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) );
101 101
         $multisitePlugins = $this->getMultisitePluginDetails();
102 102
         return empty($multisitePlugins)
103 103
             ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
104
+            : array_diff( $inactivePlugins, $multisitePlugins );
105 105
     }
106 106
 
107 107
     /**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getMuPluginDetails()
111 111
     {
112
-        if (empty($plugins = get_mu_plugins())) {
112
+        if( empty($plugins = get_mu_plugins()) ) {
113 113
             return [];
114 114
         }
115
-        return $this->normalizePluginList($plugins);
115
+        return $this->normalizePluginList( $plugins );
116 116
     }
117 117
 
118 118
     /**
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function getMultisitePluginDetails()
122 122
     {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
123
+        $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] );
124
+        if( !is_multisite() || empty($activePlugins) ) {
125 125
             return [];
126 126
         }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
127
+        return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) );
128 128
     }
129 129
 
130 130
     /**
@@ -132,31 +132,31 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function getPhpDetails()
134 134
     {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
135
+        $displayErrors = $this->getINI( 'display_errors', null )
136
+            ? 'On ('.$this->getINI( 'display_errors' ).')'
137 137
             : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
138
+        $intlSupport = extension_loaded( 'intl' )
139
+            ? phpversion( 'intl' )
140 140
             : 'false';
141 141
         return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
142
+            'cURL' => var_export( function_exists( 'curl_init' ), true ),
143
+            'Default Charset' => $this->getINI( 'default_charset' ),
144 144
             'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
145
+            'fsockopen' => var_export( function_exists( 'fsockopen' ), true ),
146 146
             'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
147
+            'IPv6' => var_export( defined( 'AF_INET6' ), true ),
148
+            'Max Execution Time' => $this->getINI( 'max_execution_time' ),
149
+            'Max Input Nesting Level' => $this->getINI( 'max_input_nesting_level' ),
150
+            'Max Input Vars' => $this->getINI( 'max_input_vars' ),
151
+            'Memory Limit' => $this->getINI( 'memory_limit' ),
152
+            'Post Max Size' => $this->getINI( 'post_max_size' ),
153
+            'Sendmail Path' => $this->getINI( 'sendmail_path' ),
154
+            'Session Cookie Path' => esc_html( $this->getINI( 'session.cookie_path' ) ),
155
+            'Session Name' => esc_html( $this->getINI( 'session.name' ) ),
156
+            'Session Save Path' => esc_html( $this->getINI( 'session.save_path' ) ),
157
+            'Session Use Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_cookies', false ) ), true ),
158
+            'Session Use Only Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_only_cookies', false ) ), true ),
159
+            'Upload Max Filesize' => $this->getINI( 'upload_max_filesize' ),
160 160
         ];
161 161
     }
162 162
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function getReviewsDetails()
167 167
     {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flatten($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
168
+        $counts = glsr( CountsManager::class )->getCounts();
169
+        $counts = Arr::flatten( $counts );
170
+        array_walk( $counts, function( &$ratings ) use ($counts) {
171
+            if( is_array( $ratings ) ) {
172
+                $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')';
173 173
                 return;
174 174
             }
175 175
             glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
176
+                ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' )
177
+                ->debug( $ratings )
178
+                ->debug( $counts );
179 179
         });
180
-        ksort($counts);
180
+        ksort( $counts );
181 181
         return $counts;
182 182
     }
183 183
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             'Host Name' => $this->getHostName(),
192 192
             'MySQL Version' => $wpdb->db_version(),
193 193
             'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
194
+            'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ),
195 195
         ];
196 196
     }
197 197
 
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function getSettingDetails()
202 202
     {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flatten($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
203
+        $settings = glsr( OptionManager::class )->get( 'settings', [] );
204
+        $settings = Arr::flatten( $settings, true );
205
+        $settings = $this->purgeSensitiveData( $settings );
206
+        ksort( $settings );
207 207
         $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
208
+        foreach( $settings as $key => $value ) {
209
+            if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) {
210 210
                 continue;
211 211
             }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
212
+            $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' );
213 213
             $details[$key] = $value;
214 214
         }
215 215
         return $details;
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
     public function getPluginDetails()
222 222
     {
223 223
         return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
224
+            'Console level' => glsr( Console::class )->humanLevel(),
225
+            'Console size' => glsr( Console::class )->humanSize( '0' ),
226
+            'Last Migration Run' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_migration_run' ), 'unknown' ),
227
+            'Last Rating Count' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_review_count' ), 'unknown' ),
228 228
             'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
229
+            'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ),
230 230
         ];
231 231
     }
232 232
 
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
         global $wpdb;
239 239
         $theme = wp_get_theme();
240 240
         return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
241
+            'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ),
242
+            'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ),
243 243
             'Home URL' => home_url(),
244 244
             'Language' => get_locale(),
245 245
             'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
246
+            'Multisite' => var_export( is_multisite(), true ),
247
+            'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ),
248
+            'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ),
249
+            'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ),
250
+            'Post Stati' => implode( ', ', get_post_stati() ),
251
+            'Remote Post' => glsr( Cache::class )->getRemotePostTest(),
252
+            'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ),
253 253
             'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
254
+            'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', $this->getINI( 'date.timezone' ).' (PHP)' ),
255
+            'Version' => get_bloginfo( 'version' ),
256
+            'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ),
257
+            'WP Max Upload Size' => size_format( wp_max_upload_size() ),
258 258
             'WP Memory Limit' => WP_MEMORY_LIMIT,
259 259
         ];
260 260
     }
@@ -284,13 +284,13 @@  discard block
 block discarded – undo
284 284
             'secureserver.net' => 'GoDaddy',
285 285
             'WPE_APIKEY' => 'WP Engine',
286 286
         ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
287
+        foreach( $checks as $key => $value ) {
288
+            if( !$this->isWebhostCheckValid( $key ) ) {
289 289
                 continue;
290 290
             }
291 291
             return $value;
292 292
         }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
293
+        return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) );
294 294
     }
295 295
 
296 296
     /**
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function getHostName()
300 300
     {
301
-        return sprintf('%s (%s)',
301
+        return sprintf( '%s (%s)',
302 302
             $this->detectWebhostProvider(),
303 303
             Helper::getIpAddress()
304 304
         );
305 305
     }
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
307
+    protected function getINI( $name, $disabledValue = 'ini_get() is disabled.' )
308 308
     {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
309
+        return function_exists( 'ini_get' )
310
+            ? ini_get( $name )
311 311
             : $disabledValue;
312 312
     }
313 313
 
@@ -317,9 +317,9 @@  discard block
 block discarded – undo
317 317
     protected function getWordpressPlugins()
318 318
     {
319 319
         $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
320
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
321
+        $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) );
322
+        $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
323 323
         return $active + $inactive;
324 324
     }
325 325
 
@@ -327,48 +327,48 @@  discard block
 block discarded – undo
327 327
      * @param string $title
328 328
      * @return string
329 329
      */
330
-    protected function implode($title, array $details)
330
+    protected function implode( $title, array $details )
331 331
     {
332 332
         $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
333
+        $padding = max( array_map( 'strlen', array_keys( $details ) ) );
334
+        $padding = max( [$padding, static::PAD] );
335
+        foreach( $details as $key => $value ) {
336
+            $strings[] = is_string( $key )
337
+                ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value )
338 338
                 : ' - '.$value;
339 339
         }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
340
+        return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL;
341 341
     }
342 342
 
343 343
     /**
344 344
      * @param string $key
345 345
      * @return bool
346 346
      */
347
-    protected function isWebhostCheckValid($key)
347
+    protected function isWebhostCheckValid( $key )
348 348
     {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
349
+        return defined( $key )
350
+            || filter_input( INPUT_SERVER, $key )
351
+            || Str::contains( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key )
352
+            || Str::contains( DB_HOST, $key )
353
+            || Str::contains( php_uname(), $key );
354 354
     }
355 355
 
356 356
     /**
357 357
      * @return array
358 358
      */
359
-    protected function normalizePluginList(array $plugins)
359
+    protected function normalizePluginList( array $plugins )
360 360
     {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
361
+        $plugins = array_map( function( $plugin ) {
362
+            return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) );
363
+        }, $plugins );
364
+        natcasesort( $plugins );
365
+        return array_flip( $plugins );
366 366
     }
367 367
 
368 368
     /**
369 369
      * @return array
370 370
      */
371
-    protected function purgeSensitiveData(array $settings)
371
+    protected function purgeSensitiveData( array $settings )
372 372
     {
373 373
         $keys = [
374 374
             'general.trustalyze_serial',
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
             'submissions.recaptcha.key',
377 377
             'submissions.recaptcha.secret',
378 378
         ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
379
+        array_walk( $settings, function( &$value, $setting ) use ($keys) {
380
+            foreach( $keys as $key ) {
381
+                if( !Str::startsWith( $key, $setting ) || empty($value) ) {
382 382
                     continue;
383 383
                 }
384
-                $value = str_repeat('•', 13);
384
+                $value = str_repeat( '•', 13 );
385 385
                 return;
386 386
             }
387 387
         });
Please login to merge, or discard this patch.