Passed
Push — feature/rebusify ( 816514...289185 )
by Paul
07:17
created
plugin/Database/Cache.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,68 +6,68 @@
 block discarded – undo
6 6
 
7 7
 class Cache
8 8
 {
9
-    const EXPIRY_TIME = WEEK_IN_SECONDS;
9
+	const EXPIRY_TIME = WEEK_IN_SECONDS;
10 10
 
11
-    /**
12
-     * @return array
13
-     */
14
-    public function getCloudflareIps()
15
-    {
16
-        $ipAddresses = get_transient(Application::ID.'_cloudflare_ips');
17
-        if (false === $ipAddresses) {
18
-            $ipAddresses = array_fill_keys(['v4', 'v6'], []);
19
-            foreach (array_keys($ipAddresses) as $version) {
20
-                $url = 'https://www.cloudflare.com/ips-'.$version;
21
-                $response = wp_remote_get($url);
22
-                if (is_wp_error($response)) {
23
-                    glsr_log()->error($response->get_error_message());
24
-                    continue;
25
-                }
26
-                if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
27
-                    glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
28
-                    continue;
29
-                }
30
-                $ipAddresses[$version] = array_filter(
31
-                    (array) preg_split('/\R/', wp_remote_retrieve_body($response))
32
-                );
33
-            }
34
-            set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME);
35
-        }
36
-        return $ipAddresses;
37
-    }
11
+	/**
12
+	 * @return array
13
+	 */
14
+	public function getCloudflareIps()
15
+	{
16
+		$ipAddresses = get_transient(Application::ID.'_cloudflare_ips');
17
+		if (false === $ipAddresses) {
18
+			$ipAddresses = array_fill_keys(['v4', 'v6'], []);
19
+			foreach (array_keys($ipAddresses) as $version) {
20
+				$url = 'https://www.cloudflare.com/ips-'.$version;
21
+				$response = wp_remote_get($url);
22
+				if (is_wp_error($response)) {
23
+					glsr_log()->error($response->get_error_message());
24
+					continue;
25
+				}
26
+				if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
27
+					glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
28
+					continue;
29
+				}
30
+				$ipAddresses[$version] = array_filter(
31
+					(array) preg_split('/\R/', wp_remote_retrieve_body($response))
32
+				);
33
+			}
34
+			set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME);
35
+		}
36
+		return $ipAddresses;
37
+	}
38 38
 
39
-    /**
40
-     * @param string $metaKey
41
-     * @return array
42
-     */
43
-    public function getReviewCountsFor($metaKey)
44
-    {
45
-        $counts = wp_cache_get(Application::ID, $metaKey.'_count');
46
-        if (false === $counts) {
47
-            $counts = [];
48
-            $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
49
-            foreach ($results as $result) {
50
-                $counts[$result->name] = $result->num_posts;
51
-            }
52
-            wp_cache_set(Application::ID, $counts, $metaKey.'_count');
53
-        }
54
-        return $counts;
55
-    }
39
+	/**
40
+	 * @param string $metaKey
41
+	 * @return array
42
+	 */
43
+	public function getReviewCountsFor($metaKey)
44
+	{
45
+		$counts = wp_cache_get(Application::ID, $metaKey.'_count');
46
+		if (false === $counts) {
47
+			$counts = [];
48
+			$results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
49
+			foreach ($results as $result) {
50
+				$counts[$result->name] = $result->num_posts;
51
+			}
52
+			wp_cache_set(Application::ID, $counts, $metaKey.'_count');
53
+		}
54
+		return $counts;
55
+	}
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function getRemotePostTest()
61
-    {
62
-        $test = get_transient(Application::ID.'_remote_post_test');
63
-        if (false === $test) {
64
-            $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
65
-            $test = !is_wp_error($response)
66
-                && in_array($response['response']['code'], range(200, 299))
67
-                ? 'Works'
68
-                : 'Does not work';
69
-            set_transient(Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME);
70
-        }
71
-        return $test;
72
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function getRemotePostTest()
61
+	{
62
+		$test = get_transient(Application::ID.'_remote_post_test');
63
+		if (false === $test) {
64
+			$response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
65
+			$test = !is_wp_error($response)
66
+				&& in_array($response['response']['code'], range(200, 299))
67
+				? 'Works'
68
+				: 'Does not work';
69
+			set_transient(Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME);
70
+		}
71
+		return $test;
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@  discard block
 block discarded – undo
13 13
      */
14 14
     public function getCloudflareIps()
15 15
     {
16
-        $ipAddresses = get_transient(Application::ID.'_cloudflare_ips');
17
-        if (false === $ipAddresses) {
18
-            $ipAddresses = array_fill_keys(['v4', 'v6'], []);
19
-            foreach (array_keys($ipAddresses) as $version) {
16
+        $ipAddresses = get_transient( Application::ID.'_cloudflare_ips' );
17
+        if( false === $ipAddresses ) {
18
+            $ipAddresses = array_fill_keys( ['v4', 'v6'], [] );
19
+            foreach( array_keys( $ipAddresses ) as $version ) {
20 20
                 $url = 'https://www.cloudflare.com/ips-'.$version;
21
-                $response = wp_remote_get($url);
22
-                if (is_wp_error($response)) {
23
-                    glsr_log()->error($response->get_error_message());
21
+                $response = wp_remote_get( $url );
22
+                if( is_wp_error( $response ) ) {
23
+                    glsr_log()->error( $response->get_error_message() );
24 24
                     continue;
25 25
                 }
26
-                if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
27
-                    glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
26
+                if( '200' != ($statusCode = wp_remote_retrieve_response_code( $response )) ) {
27
+                    glsr_log()->error( 'Unable to connect to '.$url.' ['.$statusCode.']' );
28 28
                     continue;
29 29
                 }
30 30
                 $ipAddresses[$version] = array_filter(
31
-                    (array) preg_split('/\R/', wp_remote_retrieve_body($response))
31
+                    (array)preg_split( '/\R/', wp_remote_retrieve_body( $response ) )
32 32
                 );
33 33
             }
34
-            set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME);
34
+            set_transient( Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME );
35 35
         }
36 36
         return $ipAddresses;
37 37
     }
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
      * @param string $metaKey
41 41
      * @return array
42 42
      */
43
-    public function getReviewCountsFor($metaKey)
43
+    public function getReviewCountsFor( $metaKey )
44 44
     {
45
-        $counts = wp_cache_get(Application::ID, $metaKey.'_count');
46
-        if (false === $counts) {
45
+        $counts = wp_cache_get( Application::ID, $metaKey.'_count' );
46
+        if( false === $counts ) {
47 47
             $counts = [];
48
-            $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
49
-            foreach ($results as $result) {
48
+            $results = glsr( SqlQueries::class )->getReviewCountsFor( $metaKey );
49
+            foreach( $results as $result ) {
50 50
                 $counts[$result->name] = $result->num_posts;
51 51
             }
52
-            wp_cache_set(Application::ID, $counts, $metaKey.'_count');
52
+            wp_cache_set( Application::ID, $counts, $metaKey.'_count' );
53 53
         }
54 54
         return $counts;
55 55
     }
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function getRemotePostTest()
61 61
     {
62
-        $test = get_transient(Application::ID.'_remote_post_test');
63
-        if (false === $test) {
64
-            $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
65
-            $test = !is_wp_error($response)
66
-                && in_array($response['response']['code'], range(200, 299))
62
+        $test = get_transient( Application::ID.'_remote_post_test' );
63
+        if( false === $test ) {
64
+            $response = wp_remote_post( 'https://api.wordpress.org/stats/php/1.0/' );
65
+            $test = !is_wp_error( $response )
66
+                && in_array( $response['response']['code'], range( 200, 299 ) )
67 67
                 ? 'Works'
68 68
                 : 'Does not work';
69
-            set_transient(Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME);
69
+            set_transient( Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME );
70 70
         }
71 71
         return $test;
72 72
     }
Please login to merge, or discard this patch.
plugin/Database/DefaultsManager.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -6,60 +6,60 @@
 block discarded – undo
6 6
 
7 7
 class DefaultsManager
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function defaults()
13
-    {
14
-        $settings = $this->settings();
15
-        $defaults = array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
-        return wp_parse_args($defaults, [
17
-            'version' => '',
18
-            'version_upgraded_from' => '',
19
-        ]);
20
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function defaults()
13
+	{
14
+		$settings = $this->settings();
15
+		$defaults = array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
+		return wp_parse_args($defaults, [
17
+			'version' => '',
18
+			'version_upgraded_from' => '',
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function get()
26
-    {
27
-        return glsr(Helper::class)->convertDotNotationArray($this->defaults());
28
-    }
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function get()
26
+	{
27
+		return glsr(Helper::class)->convertDotNotationArray($this->defaults());
28
+	}
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function set()
34
-    {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
40
-        return $defaultSettings;
41
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function set()
34
+	{
35
+		$settings = glsr(OptionManager::class)->all();
36
+		$currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings);
37
+		$defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
+		$updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
+		update_option(OptionManager::databaseKey(), $updatedSettings);
40
+		return $defaultSettings;
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     */
46
-    public function settings()
47
-    {
48
-        $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
50
-    }
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function settings()
47
+	{
48
+		$settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
+		return $this->normalize($settings);
50
+	}
51 51
 
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function normalize(array $settings)
56
-    {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
59
-                return;
60
-            }
61
-            $setting['default'] = '';
62
-        });
63
-        return $settings;
64
-    }
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function normalize(array $settings)
56
+	{
57
+		array_walk($settings, function (&$setting) {
58
+			if (isset($setting['default'])) {
59
+				return;
60
+			}
61
+			$setting['default'] = '';
62
+		});
63
+		return $settings;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
     public function defaults()
13 13
     {
14 14
         $settings = $this->settings();
15
-        $defaults = array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
-        return wp_parse_args($defaults, [
15
+        $defaults = array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) );
16
+        return wp_parse_args( $defaults, [
17 17
             'version' => '',
18 18
             'version_upgraded_from' => '',
19
-        ]);
19
+        ] );
20 20
     }
21 21
 
22 22
     /**
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function get()
26 26
     {
27
-        return glsr(Helper::class)->convertDotNotationArray($this->defaults());
27
+        return glsr( Helper::class )->convertDotNotationArray( $this->defaults() );
28 28
     }
29 29
 
30 30
     /**
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function set()
34 34
     {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
35
+        $settings = glsr( OptionManager::class )->all();
36
+        $currentSettings = glsr( Helper::class )->removeEmptyArrayValues( $settings );
37
+        $defaultSettings = array_replace_recursive( $this->get(), $currentSettings );
38
+        $updatedSettings = array_replace_recursive( $settings, $defaultSettings );
39
+        update_option( OptionManager::databaseKey(), $updatedSettings );
40 40
         return $defaultSettings;
41 41
     }
42 42
 
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function settings()
47 47
     {
48
-        $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
48
+        $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) );
49
+        return $this->normalize( $settings );
50 50
     }
51 51
 
52 52
     /**
53 53
      * @return array
54 54
      */
55
-    protected function normalize(array $settings)
55
+    protected function normalize( array $settings )
56 56
     {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
57
+        array_walk( $settings, function( &$setting ) {
58
+            if( isset($setting['default']) ) {
59 59
                 return;
60 60
             }
61 61
             $setting['default'] = '';
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 3 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -20,27 +20,27 @@  discard block
 block discarded – undo
20 20
 	 * @return array
21 21
 	 * @todo verify the additional type checks are needed
22 22
 	 */
23
-    public function buildCounts(array $args = [])
23
+	public function buildCounts(array $args = [])
24 24
 	{
25 25
 		$counts = [];
26
-        $query = $this->queryReviews($args);
27
-        while ($query) {
26
+		$query = $this->queryReviews($args);
27
+		while ($query) {
28 28
 			// glsr_log($query);
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
34
-                    continue;
29
+			$types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
+			$types = array_unique(array_merge(['local'], $types));
31
+			foreach ($types as $type) {
32
+				$type = $this->normalizeType($type);
33
+				if (isset($counts[$type])) {
34
+					continue;
35 35
 			}
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
-            }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
40
-                ++$counts[$type][$review->rating];
36
+				$counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
+			}
38
+			foreach ($query->reviews as $review) {
39
+				$type = $this->normalizeType($review->type);
40
+				++$counts[$type][$review->rating];
41 41
 			}
42 42
 			$query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
43
+				? $this->queryReviews($args, end($query->reviews)->ID)
44 44
 				: false;
45 45
 		}
46 46
 		return $counts;
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 	 * @param int $postId
51 51
 	 * @return array
52 52
 	 */
53
-    public function buildPostCounts($postId)
53
+	public function buildPostCounts($postId)
54 54
 	{
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
55
+		return $this->buildCounts(['post_ids' => [$postId]]);
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * @param int $termTaxonomyId
60 60
 	 * @return array
61 61
 	 */
62
-    public function buildTermCounts($termTaxonomyId)
62
+	public function buildTermCounts($termTaxonomyId)
63 63
 	{
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
64
+		return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65 65
 	}
66 66
 
67 67
 	/**
@@ -69,33 +69,33 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function countAll()
71 71
 	{
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
72
+		$terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
+		foreach ($terms as $term) {
74
+			$this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75 75
 		}
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
76
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
+		foreach ($postIds as $postId) {
78
+			$this->setPostCounts($postId, $this->buildPostCounts($postId));
79 79
 		}
80
-        $this->setCounts($this->buildCounts());
80
+		$this->setCounts($this->buildCounts());
81 81
 	}
82 82
 
83 83
 	/**
84 84
 	 * @return void
85 85
 	 */
86
-    public function decrease(Review $review)
86
+	public function decrease(Review $review)
87 87
 	{
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
88
+		$this->decreaseCounts($review);
89
+		$this->decreasePostCounts($review);
90
+		$this->decreaseTermCounts($review);
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @return void
95 95
 	 */
96
-    public function decreaseCounts(Review $review)
96
+	public function decreaseCounts(Review $review)
97 97
 	{
98
-        $this->setCounts($this->decreaseRating(
98
+		$this->setCounts($this->decreaseRating(
99 99
 			$this->getCounts(),
100 100
 			$review->review_type,
101 101
 			$review->rating
@@ -105,46 +105,46 @@  discard block
 block discarded – undo
105 105
 	/**
106 106
 	 * @return void
107 107
 	 */
108
-    public function decreasePostCounts(Review $review)
108
+	public function decreasePostCounts(Review $review)
109 109
 	{
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
-            return;
112
-        }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
110
+		if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
+			return;
112
+		}
113
+		$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
+		$this->setPostCounts($review->assigned_to, $counts);
115 115
 	}
116 116
 
117 117
 	/**
118 118
 	 * @return void
119 119
 	 */
120
-    public function decreaseTermCounts(Review $review)
120
+	public function decreaseTermCounts(Review $review)
121 121
 	{
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
124
-                continue;
125
-            }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
122
+		foreach ($review->term_ids as $termId) {
123
+			if (empty($counts = $this->getTermCounts($termId))) {
124
+				continue;
125
+			}
126
+			$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
+			$this->setTermCounts($termId, $counts);
128 128
 		}
129 129
 	}
130 130
 
131 131
 	/**
132 132
 	 * @return array
133 133
 	 */
134
-    public function flatten(array $reviewCounts, array $args = [])
134
+	public function flatten(array $reviewCounts, array $args = [])
135 135
 	{
136 136
 		$counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(glsr_get($counts, $index, 0));
137
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
+			$counts[$index] = $num + intval(glsr_get($counts, $index, 0));
139 139
 		});
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
140
+		$args = wp_parse_args($args, [
141
+			'max' => glsr()->constant('MAX_RATING', Rating::class),
142
+			'min' => glsr()->constant('MIN_RATING', Rating::class),
143 143
 		]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
-                continue;
147
-            }
144
+		foreach ($counts as $index => &$num) {
145
+			if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
+				continue;
147
+			}
148 148
 			$num = 0;
149 149
 		}
150 150
 		return $counts;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
 	/**
154 154
 	 * @return array
155 155
 	 */
156
-    public function get(array $args = [])
156
+	public function get(array $args = [])
157 157
 	{
158
-        $args = $this->normalizeArgs($args);
158
+		$args = $this->normalizeArgs($args);
159 159
 		$counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
160
+		if ($this->isMixedCount($args)) {
161
+			$counts = [$this->buildCounts($args)]; // force query the database
162
+		} else {
163
+			foreach ($args['post_ids'] as $postId) {
164
+				$counts[] = $this->getPostCounts($postId);
165 165
 		}
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
166
+			foreach ($args['term_ids'] as $termId) {
167
+				$counts[] = $this->getTermCounts($termId);
168 168
 			}
169
-            if (empty($counts)) {
169
+			if (empty($counts)) {
170 170
 				$counts[] = $this->getCounts();
171 171
 			}
172 172
 		}
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
173
+		return in_array($args['type'], ['', 'all'])
174
+			? $this->normalize([$this->flatten($counts)])
175
+			: $this->normalize(glsr_array_column($counts, $args['type']));
176 176
 	}
177 177
 
178 178
 	/**
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 */
181 181
 	public function getCounts()
182 182
 	{
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('$counts is not an array')->debug($counts);
183
+		$counts = glsr(OptionManager::class)->get('counts', []);
184
+		if (!is_array($counts)) {
185
+			glsr_log()->error('$counts is not an array')->debug($counts);
186 186
 			return [];
187 187
 		}
188 188
 		return $counts;
@@ -192,105 +192,105 @@  discard block
 block discarded – undo
192 192
 	 * @param int $postId
193 193
 	 * @return array
194 194
 	 */
195
-    public function getPostCounts($postId)
195
+	public function getPostCounts($postId)
196 196
 	{
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
197
+		return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198 198
 	}
199 199
 
200 200
 	/**
201 201
 	 * @param int $termId
202 202
 	 * @return array
203 203
 	 */
204
-    public function getTermCounts($termId)
204
+	public function getTermCounts($termId)
205 205
 	{
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
206
+		return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207 207
 	}
208 208
 
209 209
 	/**
210 210
 	 * @return void
211 211
 	 */
212
-    public function increase(Review $review)
212
+	public function increase(Review $review)
213 213
 	{
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
214
+		$this->increaseCounts($review);
215
+		$this->increasePostCounts($review);
216
+		$this->increaseTermCounts($review);
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * @return void
221 221
 	 */
222
-    public function increaseCounts(Review $review)
222
+	public function increaseCounts(Review $review)
223 223
 	{
224
-        if (empty($counts = $this->getCounts())) {
224
+		if (empty($counts = $this->getCounts())) {
225 225
 			$counts = $this->buildCounts();
226 226
 		}
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
227
+		$this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * @return void
232 232
 	 */
233
-    public function increasePostCounts(Review $review)
233
+	public function increasePostCounts(Review $review)
234 234
 	{
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
-            return;
237
-        }
238
-        $counts = $this->getPostCounts($review->assigned_to);
239
-        $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
235
+		if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
+			return;
237
+		}
238
+		$counts = $this->getPostCounts($review->assigned_to);
239
+		$counts = empty($counts)
240
+			? $this->buildPostCounts($review->assigned_to)
241
+			: $this->increaseRating($counts, $review->review_type, $review->rating);
242
+		$this->setPostCounts($review->assigned_to, $counts);
243 243
 	}
244 244
 
245 245
 	/**
246 246
 	 * @return void
247 247
 	 */
248
-    public function increaseTermCounts(Review $review)
248
+	public function increaseTermCounts(Review $review)
249 249
 	{
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
253
-            $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
250
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
+		foreach ($terms as $term) {
252
+			$counts = $this->getTermCounts($term['term_id']);
253
+			$counts = empty($counts)
254
+				? $this->buildTermCounts($term['term_taxonomy_id'])
255
+				: $this->increaseRating($counts, $review->review_type, $review->rating);
256
+			$this->setTermCounts($term['term_id'], $counts);
257 257
 		}
258 258
 	}
259 259
 
260 260
 	/**
261 261
 	 * @return void
262 262
 	 */
263
-    public function setCounts(array $reviewCounts)
263
+	public function setCounts(array $reviewCounts)
264 264
 	{
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
265
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * @param int $postId
270 270
 	 * @return void
271 271
 	 */
272
-    public function setPostCounts($postId, array $reviewCounts)
272
+	public function setPostCounts($postId, array $reviewCounts)
273 273
 	{
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
274
+		$ratingCounts = $this->flatten($reviewCounts);
275
+		update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
+		update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
+		update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278 278
 	}
279 279
 
280 280
 	/**
281 281
 	 * @param int $termId
282 282
 	 * @return void
283 283
 	 */
284
-    public function setTermCounts($termId, array $reviewCounts)
284
+	public function setTermCounts($termId, array $reviewCounts)
285 285
 	{
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
288
-            return;
289
-        }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
286
+		$term = get_term($termId, Application::TAXONOMY);
287
+		if (!isset($term->term_id)) {
288
+			return;
289
+		}
290
+		$ratingCounts = $this->flatten($reviewCounts);
291
+		update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
+		update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
+		update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294 294
 	}
295 295
 
296 296
 	/**
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 	 * @param int $rating
299 299
 	 * @return array
300 300
 	 */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
301
+	protected function decreaseRating(array $reviewCounts, $type, $rating)
302 302
 	{
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
303
+		if (isset($reviewCounts[$type][$rating])) {
304
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305 305
 		}
306 306
 		return $reviewCounts;
307 307
 	}
@@ -311,43 +311,43 @@  discard block
 block discarded – undo
311 311
 	 * @param int $rating
312 312
 	 * @return array
313 313
 	 */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
314
+	protected function increaseRating(array $reviewCounts, $type, $rating)
315 315
 	{
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
316
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
317 317
 			return $reviewCounts;
318 318
 		}
319
-        if (!array_key_exists($type, $reviewCounts)) {
319
+		if (!array_key_exists($type, $reviewCounts)) {
320 320
 			$reviewCounts[$type] = [];
321 321
 		}
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
322
+		$reviewCounts = $this->normalize($reviewCounts);
323
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324 324
 		return $reviewCounts;
325 325
 	}
326 326
 
327 327
 	/**
328 328
 	 * @return bool
329 329
 	 */
330
-    protected function isMixedCount(array $args)
330
+	protected function isMixedCount(array $args)
331 331
 	{
332
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
332
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
333 333
 	}
334 334
 
335 335
 	/**
336 336
 	 * @return array
337 337
 	 */
338
-    protected function normalize(array $reviewCounts)
338
+	protected function normalize(array $reviewCounts)
339 339
 	{
340
-        if (empty($reviewCounts)) {
340
+		if (empty($reviewCounts)) {
341 341
 			$reviewCounts = [[]];
342 342
 		}
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
346
-                    continue;
347
-                }
343
+		foreach ($reviewCounts as &$counts) {
344
+			foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
+				if (isset($counts[$index])) {
346
+					continue;
347
+				}
348 348
 				$counts[$index] = 0;
349 349
 			}
350
-            ksort($counts);
350
+			ksort($counts);
351 351
 		}
352 352
 		return $reviewCounts;
353 353
 	}
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 	/**
356 356
 	 * @return array
357 357
 	 */
358
-    protected function normalizeArgs(array $args)
358
+	protected function normalizeArgs(array $args)
359 359
 	{
360
-        $args = wp_parse_args(array_filter($args), [
360
+		$args = wp_parse_args(array_filter($args), [
361 361
 			'post_ids' => [],
362 362
 			'term_ids' => [],
363 363
 			'type' => 'local',
364 364
 		]);
365
-        $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
365
+		$args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
+		$args['type'] = $this->normalizeType($args['type']);
367 367
 		return $args;
368 368
 	}
369 369
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 * @param string $type
372 372
 	 * @return string
373 373
 	 */
374
-    protected function normalizeType($type)
374
+	protected function normalizeType($type)
375 375
 	{
376
-        return empty($type) || !is_string($type)
376
+		return empty($type) || !is_string($type)
377 377
 			? 'local'
378 378
 			: $type;
379 379
 	}
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	 * @param int $lastPostId
383 383
 	 * @return object
384 384
 	 */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
385
+	protected function queryReviews(array $args = [], $lastPostId = 0)
386 386
 	{
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
387
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
+		$hasMore = is_array($reviews)
389
+			? count($reviews) == static::LIMIT
390 390
 			: false;
391 391
 		return (object) [
392 392
 			'has_more' => $hasMore,
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -20,27 +20,27 @@  discard block
 block discarded – undo
20 20
 	 * @return array
21 21
 	 * @todo verify the additional type checks are needed
22 22
 	 */
23
-    public function buildCounts(array $args = [])
23
+    public function buildCounts( array $args = [] )
24 24
 	{
25 25
 		$counts = [];
26
-        $query = $this->queryReviews($args);
27
-        while ($query) {
26
+        $query = $this->queryReviews( $args );
27
+        while( $query ) {
28 28
 			// glsr_log($query);
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
29
+            $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ) ) );
30
+            $types = array_unique( array_merge( ['local'], $types ) );
31
+            foreach( $types as $type ) {
32
+                $type = $this->normalizeType( $type );
33
+                if( isset($counts[$type]) ) {
34 34
                     continue;
35 35
 			}
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
36
+                $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 );
37 37
             }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
38
+            foreach( $query->reviews as $review ) {
39
+                $type = $this->normalizeType( $review->type );
40 40
                 ++$counts[$type][$review->rating];
41 41
 			}
42 42
 			$query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
43
+                ? $this->queryReviews( $args, end( $query->reviews )->ID )
44 44
 				: false;
45 45
 		}
46 46
 		return $counts;
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 	 * @param int $postId
51 51
 	 * @return array
52 52
 	 */
53
-    public function buildPostCounts($postId)
53
+    public function buildPostCounts( $postId )
54 54
 	{
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
55
+        return $this->buildCounts( ['post_ids' => [$postId]] );
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * @param int $termTaxonomyId
60 60
 	 * @return array
61 61
 	 */
62
-    public function buildTermCounts($termTaxonomyId)
62
+    public function buildTermCounts( $termTaxonomyId )
63 63
 	{
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
64
+        return $this->buildCounts( ['term_ids' => [$termTaxonomyId]] );
65 65
 	}
66 66
 
67 67
 	/**
@@ -69,80 +69,80 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function countAll()
71 71
 	{
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
72
+        $terms = glsr( Database::class )->getTerms( ['fields' => 'all'] );
73
+        foreach( $terms as $term ) {
74
+            $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id ) );
75 75
 		}
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
76
+        $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' );
77
+        foreach( $postIds as $postId ) {
78
+            $this->setPostCounts( $postId, $this->buildPostCounts( $postId ) );
79 79
 		}
80
-        $this->setCounts($this->buildCounts());
80
+        $this->setCounts( $this->buildCounts() );
81 81
 	}
82 82
 
83 83
 	/**
84 84
 	 * @return void
85 85
 	 */
86
-    public function decrease(Review $review)
86
+    public function decrease( Review $review )
87 87
 	{
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
88
+        $this->decreaseCounts( $review );
89
+        $this->decreasePostCounts( $review );
90
+        $this->decreaseTermCounts( $review );
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @return void
95 95
 	 */
96
-    public function decreaseCounts(Review $review)
96
+    public function decreaseCounts( Review $review )
97 97
 	{
98
-        $this->setCounts($this->decreaseRating(
98
+        $this->setCounts( $this->decreaseRating(
99 99
 			$this->getCounts(),
100 100
 			$review->review_type,
101 101
 			$review->rating
102
-		));
102
+		) );
103 103
 	}
104 104
 
105 105
 	/**
106 106
 	 * @return void
107 107
 	 */
108
-    public function decreasePostCounts(Review $review)
108
+    public function decreasePostCounts( Review $review )
109 109
 	{
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
110
+        if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) {
111 111
             return;
112 112
         }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
113
+        $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
114
+        $this->setPostCounts( $review->assigned_to, $counts );
115 115
 	}
116 116
 
117 117
 	/**
118 118
 	 * @return void
119 119
 	 */
120
-    public function decreaseTermCounts(Review $review)
120
+    public function decreaseTermCounts( Review $review )
121 121
 	{
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
122
+        foreach( $review->term_ids as $termId ) {
123
+            if( empty($counts = $this->getTermCounts( $termId )) ) {
124 124
                 continue;
125 125
             }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
126
+            $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating );
127
+            $this->setTermCounts( $termId, $counts );
128 128
 		}
129 129
 	}
130 130
 
131 131
 	/**
132 132
 	 * @return array
133 133
 	 */
134
-    public function flatten(array $reviewCounts, array $args = [])
134
+    public function flatten( array $reviewCounts, array $args = [] )
135 135
 	{
136 136
 		$counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(glsr_get($counts, $index, 0));
137
+        array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) {
138
+            $counts[$index] = $num + intval( glsr_get( $counts, $index, 0 ) );
139 139
 		});
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
143
-		]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
140
+        $args = wp_parse_args( $args, [
141
+            'max' => glsr()->constant( 'MAX_RATING', Rating::class ),
142
+            'min' => glsr()->constant( 'MIN_RATING', Rating::class ),
143
+		] );
144
+        foreach( $counts as $index => &$num ) {
145
+            if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) ) {
146 146
                 continue;
147 147
             }
148 148
 			$num = 0;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
 	/**
154 154
 	 * @return array
155 155
 	 */
156
-    public function get(array $args = [])
156
+    public function get( array $args = [] )
157 157
 	{
158
-        $args = $this->normalizeArgs($args);
158
+        $args = $this->normalizeArgs( $args );
159 159
 		$counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
160
+        if( $this->isMixedCount( $args ) ) {
161
+            $counts = [$this->buildCounts( $args )]; // force query the database
162 162
         } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
163
+            foreach( $args['post_ids'] as $postId ) {
164
+                $counts[] = $this->getPostCounts( $postId );
165 165
 		}
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
166
+            foreach( $args['term_ids'] as $termId ) {
167
+                $counts[] = $this->getTermCounts( $termId );
168 168
 			}
169
-            if (empty($counts)) {
169
+            if( empty($counts) ) {
170 170
 				$counts[] = $this->getCounts();
171 171
 			}
172 172
 		}
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
173
+        return in_array( $args['type'], ['', 'all'] )
174
+            ? $this->normalize( [$this->flatten( $counts )] )
175
+            : $this->normalize( glsr_array_column( $counts, $args['type'] ) );
176 176
 	}
177 177
 
178 178
 	/**
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 */
181 181
 	public function getCounts()
182 182
 	{
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('$counts is not an array')->debug($counts);
183
+        $counts = glsr( OptionManager::class )->get( 'counts', [] );
184
+        if( !is_array( $counts ) ) {
185
+            glsr_log()->error( '$counts is not an array' )->debug( $counts );
186 186
 			return [];
187 187
 		}
188 188
 		return $counts;
@@ -192,105 +192,105 @@  discard block
 block discarded – undo
192 192
 	 * @param int $postId
193 193
 	 * @return array
194 194
 	 */
195
-    public function getPostCounts($postId)
195
+    public function getPostCounts( $postId )
196 196
 	{
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
197
+        return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) );
198 198
 	}
199 199
 
200 200
 	/**
201 201
 	 * @param int $termId
202 202
 	 * @return array
203 203
 	 */
204
-    public function getTermCounts($termId)
204
+    public function getTermCounts( $termId )
205 205
 	{
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
206
+        return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) );
207 207
 	}
208 208
 
209 209
 	/**
210 210
 	 * @return void
211 211
 	 */
212
-    public function increase(Review $review)
212
+    public function increase( Review $review )
213 213
 	{
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
214
+        $this->increaseCounts( $review );
215
+        $this->increasePostCounts( $review );
216
+        $this->increaseTermCounts( $review );
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * @return void
221 221
 	 */
222
-    public function increaseCounts(Review $review)
222
+    public function increaseCounts( Review $review )
223 223
 	{
224
-        if (empty($counts = $this->getCounts())) {
224
+        if( empty($counts = $this->getCounts()) ) {
225 225
 			$counts = $this->buildCounts();
226 226
 		}
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
227
+        $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating ) );
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * @return void
232 232
 	 */
233
-    public function increasePostCounts(Review $review)
233
+    public function increasePostCounts( Review $review )
234 234
 	{
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
235
+        if( !(get_post( $review->assigned_to ) instanceof WP_Post) ) {
236 236
             return;
237 237
         }
238
-        $counts = $this->getPostCounts($review->assigned_to);
238
+        $counts = $this->getPostCounts( $review->assigned_to );
239 239
         $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
240
+            ? $this->buildPostCounts( $review->assigned_to )
241
+            : $this->increaseRating( $counts, $review->review_type, $review->rating );
242
+        $this->setPostCounts( $review->assigned_to, $counts );
243 243
 	}
244 244
 
245 245
 	/**
246 246
 	 * @return void
247 247
 	 */
248
-    public function increaseTermCounts(Review $review)
248
+    public function increaseTermCounts( Review $review )
249 249
 	{
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
250
+        $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) );
251
+        foreach( $terms as $term ) {
252
+            $counts = $this->getTermCounts( $term['term_id'] );
253 253
             $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
254
+                ? $this->buildTermCounts( $term['term_taxonomy_id'] )
255
+                : $this->increaseRating( $counts, $review->review_type, $review->rating );
256
+            $this->setTermCounts( $term['term_id'], $counts );
257 257
 		}
258 258
 	}
259 259
 
260 260
 	/**
261 261
 	 * @return void
262 262
 	 */
263
-    public function setCounts(array $reviewCounts)
263
+    public function setCounts( array $reviewCounts )
264 264
 	{
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
265
+        glsr( OptionManager::class )->set( 'counts', $reviewCounts );
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * @param int $postId
270 270
 	 * @return void
271 271
 	 */
272
-    public function setPostCounts($postId, array $reviewCounts)
272
+    public function setPostCounts( $postId, array $reviewCounts )
273 273
 	{
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
274
+        $ratingCounts = $this->flatten( $reviewCounts );
275
+        update_post_meta( $postId, static::META_COUNT, $reviewCounts );
276
+        update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
277
+        update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
278 278
 	}
279 279
 
280 280
 	/**
281 281
 	 * @param int $termId
282 282
 	 * @return void
283 283
 	 */
284
-    public function setTermCounts($termId, array $reviewCounts)
284
+    public function setTermCounts( $termId, array $reviewCounts )
285 285
 	{
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
286
+        $term = get_term( $termId, Application::TAXONOMY );
287
+        if( !isset($term->term_id) ) {
288 288
             return;
289 289
         }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
290
+        $ratingCounts = $this->flatten( $reviewCounts );
291
+        update_term_meta( $termId, static::META_COUNT, $reviewCounts );
292
+        update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) );
293
+        update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) );
294 294
 	}
295 295
 
296 296
 	/**
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 	 * @param int $rating
299 299
 	 * @return array
300 300
 	 */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
301
+    protected function decreaseRating( array $reviewCounts, $type, $rating )
302 302
 	{
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
303
+        if( isset($reviewCounts[$type][$rating]) ) {
304
+            $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 );
305 305
 		}
306 306
 		return $reviewCounts;
307 307
 	}
@@ -311,23 +311,23 @@  discard block
 block discarded – undo
311 311
 	 * @param int $rating
312 312
 	 * @return array
313 313
 	 */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
314
+    protected function increaseRating( array $reviewCounts, $type, $rating )
315 315
 	{
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
316
+        if( !array_key_exists( $type, glsr()->reviewTypes ) ) {
317 317
 			return $reviewCounts;
318 318
 		}
319
-        if (!array_key_exists($type, $reviewCounts)) {
319
+        if( !array_key_exists( $type, $reviewCounts ) ) {
320 320
 			$reviewCounts[$type] = [];
321 321
 		}
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
322
+        $reviewCounts = $this->normalize( $reviewCounts );
323
+        $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1;
324 324
 		return $reviewCounts;
325 325
 	}
326 326
 
327 327
 	/**
328 328
 	 * @return bool
329 329
 	 */
330
-    protected function isMixedCount(array $args)
330
+    protected function isMixedCount( array $args )
331 331
 	{
332 332
         return !empty($args['post_ids']) && !empty($args['term_ids']);
333 333
 	}
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
 	/**
336 336
 	 * @return array
337 337
 	 */
338
-    protected function normalize(array $reviewCounts)
338
+    protected function normalize( array $reviewCounts )
339 339
 	{
340
-        if (empty($reviewCounts)) {
340
+        if( empty($reviewCounts) ) {
341 341
 			$reviewCounts = [[]];
342 342
 		}
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
343
+        foreach( $reviewCounts as &$counts ) {
344
+            foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ) as $index ) {
345
+                if( isset($counts[$index]) ) {
346 346
                     continue;
347 347
                 }
348 348
 				$counts[$index] = 0;
349 349
 			}
350
-            ksort($counts);
350
+            ksort( $counts );
351 351
 		}
352 352
 		return $reviewCounts;
353 353
 	}
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 	/**
356 356
 	 * @return array
357 357
 	 */
358
-    protected function normalizeArgs(array $args)
358
+    protected function normalizeArgs( array $args )
359 359
 	{
360
-        $args = wp_parse_args(array_filter($args), [
360
+        $args = wp_parse_args( array_filter( $args ), [
361 361
 			'post_ids' => [],
362 362
 			'term_ids' => [],
363 363
 			'type' => 'local',
364
-		]);
365
-        $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
364
+		] );
365
+        $args['post_ids'] = glsr( Polylang::class )->getPostIds( $args['post_ids'] );
366
+        $args['type'] = $this->normalizeType( $args['type'] );
367 367
 		return $args;
368 368
 	}
369 369
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 * @param string $type
372 372
 	 * @return string
373 373
 	 */
374
-    protected function normalizeType($type)
374
+    protected function normalizeType( $type )
375 375
 	{
376
-        return empty($type) || !is_string($type)
376
+        return empty($type) || !is_string( $type )
377 377
 			? 'local'
378 378
 			: $type;
379 379
 	}
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
 	 * @param int $lastPostId
383 383
 	 * @return object
384 384
 	 */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
385
+    protected function queryReviews( array $args = [], $lastPostId = 0 )
386 386
 	{
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
387
+        $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT );
388
+        $hasMore = is_array( $reviews )
389
+            ? count( $reviews ) == static::LIMIT
390 390
 			: false;
391
-		return (object) [
391
+		return (object)[
392 392
 			'has_more' => $hasMore,
393 393
 			'reviews' => $reviews,
394 394
 		];
Please login to merge, or discard this patch.
Braces   +27 added lines, -26 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @todo verify the additional type checks are needed
22 22
 	 */
23 23
     public function buildCounts(array $args = [])
24
-	{
24
+    {
25 25
 		$counts = [];
26 26
         $query = $this->queryReviews($args);
27 27
         while ($query) {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @return array
52 52
 	 */
53 53
     public function buildPostCounts($postId)
54
-	{
54
+    {
55 55
         return $this->buildCounts(['post_ids' => [$postId]]);
56 56
 	}
57 57
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @return array
61 61
 	 */
62 62
     public function buildTermCounts($termTaxonomyId)
63
-	{
63
+    {
64 64
         return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65 65
 	}
66 66
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return void
85 85
 	 */
86 86
     public function decrease(Review $review)
87
-	{
87
+    {
88 88
         $this->decreaseCounts($review);
89 89
         $this->decreasePostCounts($review);
90 90
         $this->decreaseTermCounts($review);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @return void
95 95
 	 */
96 96
     public function decreaseCounts(Review $review)
97
-	{
97
+    {
98 98
         $this->setCounts($this->decreaseRating(
99 99
 			$this->getCounts(),
100 100
 			$review->review_type,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return void
107 107
 	 */
108 108
     public function decreasePostCounts(Review $review)
109
-	{
109
+    {
110 110
         if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111 111
             return;
112 112
         }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return void
119 119
 	 */
120 120
     public function decreaseTermCounts(Review $review)
121
-	{
121
+    {
122 122
         foreach ($review->term_ids as $termId) {
123 123
             if (empty($counts = $this->getTermCounts($termId))) {
124 124
                 continue;
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @return array
133 133
 	 */
134 134
     public function flatten(array $reviewCounts, array $args = [])
135
-	{
135
+    {
136 136
 		$counts = [];
137 137
         array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138 138
             $counts[$index] = $num + intval(glsr_get($counts, $index, 0));
@@ -154,12 +154,13 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
     public function get(array $args = [])
157
-	{
157
+    {
158 158
         $args = $this->normalizeArgs($args);
159 159
 		$counts = [];
160 160
         if ($this->isMixedCount($args)) {
161 161
             $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
162
+        }
163
+        else {
163 164
             foreach ($args['post_ids'] as $postId) {
164 165
                 $counts[] = $this->getPostCounts($postId);
165 166
 		}
@@ -193,7 +194,7 @@  discard block
 block discarded – undo
193 194
 	 * @return array
194 195
 	 */
195 196
     public function getPostCounts($postId)
196
-	{
197
+    {
197 198
         return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198 199
 	}
199 200
 
@@ -202,7 +203,7 @@  discard block
 block discarded – undo
202 203
 	 * @return array
203 204
 	 */
204 205
     public function getTermCounts($termId)
205
-	{
206
+    {
206 207
         return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207 208
 	}
208 209
 
@@ -210,7 +211,7 @@  discard block
 block discarded – undo
210 211
 	 * @return void
211 212
 	 */
212 213
     public function increase(Review $review)
213
-	{
214
+    {
214 215
         $this->increaseCounts($review);
215 216
         $this->increasePostCounts($review);
216 217
         $this->increaseTermCounts($review);
@@ -220,7 +221,7 @@  discard block
 block discarded – undo
220 221
 	 * @return void
221 222
 	 */
222 223
     public function increaseCounts(Review $review)
223
-	{
224
+    {
224 225
         if (empty($counts = $this->getCounts())) {
225 226
 			$counts = $this->buildCounts();
226 227
 		}
@@ -231,7 +232,7 @@  discard block
 block discarded – undo
231 232
 	 * @return void
232 233
 	 */
233 234
     public function increasePostCounts(Review $review)
234
-	{
235
+    {
235 236
         if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236 237
             return;
237 238
         }
@@ -246,7 +247,7 @@  discard block
 block discarded – undo
246 247
 	 * @return void
247 248
 	 */
248 249
     public function increaseTermCounts(Review $review)
249
-	{
250
+    {
250 251
         $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251 252
         foreach ($terms as $term) {
252 253
             $counts = $this->getTermCounts($term['term_id']);
@@ -261,7 +262,7 @@  discard block
 block discarded – undo
261 262
 	 * @return void
262 263
 	 */
263 264
     public function setCounts(array $reviewCounts)
264
-	{
265
+    {
265 266
         glsr(OptionManager::class)->set('counts', $reviewCounts);
266 267
 	}
267 268
 
@@ -270,7 +271,7 @@  discard block
 block discarded – undo
270 271
 	 * @return void
271 272
 	 */
272 273
     public function setPostCounts($postId, array $reviewCounts)
273
-	{
274
+    {
274 275
         $ratingCounts = $this->flatten($reviewCounts);
275 276
         update_post_meta($postId, static::META_COUNT, $reviewCounts);
276 277
         update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
@@ -282,7 +283,7 @@  discard block
 block discarded – undo
282 283
 	 * @return void
283 284
 	 */
284 285
     public function setTermCounts($termId, array $reviewCounts)
285
-	{
286
+    {
286 287
         $term = get_term($termId, Application::TAXONOMY);
287 288
         if (!isset($term->term_id)) {
288 289
             return;
@@ -299,7 +300,7 @@  discard block
 block discarded – undo
299 300
 	 * @return array
300 301
 	 */
301 302
     protected function decreaseRating(array $reviewCounts, $type, $rating)
302
-	{
303
+    {
303 304
         if (isset($reviewCounts[$type][$rating])) {
304 305
             $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305 306
 		}
@@ -312,7 +313,7 @@  discard block
 block discarded – undo
312 313
 	 * @return array
313 314
 	 */
314 315
     protected function increaseRating(array $reviewCounts, $type, $rating)
315
-	{
316
+    {
316 317
         if (!array_key_exists($type, glsr()->reviewTypes)) {
317 318
 			return $reviewCounts;
318 319
 		}
@@ -328,7 +329,7 @@  discard block
 block discarded – undo
328 329
 	 * @return bool
329 330
 	 */
330 331
     protected function isMixedCount(array $args)
331
-	{
332
+    {
332 333
         return !empty($args['post_ids']) && !empty($args['term_ids']);
333 334
 	}
334 335
 
@@ -336,7 +337,7 @@  discard block
 block discarded – undo
336 337
 	 * @return array
337 338
 	 */
338 339
     protected function normalize(array $reviewCounts)
339
-	{
340
+    {
340 341
         if (empty($reviewCounts)) {
341 342
 			$reviewCounts = [[]];
342 343
 		}
@@ -356,7 +357,7 @@  discard block
 block discarded – undo
356 357
 	 * @return array
357 358
 	 */
358 359
     protected function normalizeArgs(array $args)
359
-	{
360
+    {
360 361
         $args = wp_parse_args(array_filter($args), [
361 362
 			'post_ids' => [],
362 363
 			'term_ids' => [],
@@ -372,7 +373,7 @@  discard block
 block discarded – undo
372 373
 	 * @return string
373 374
 	 */
374 375
     protected function normalizeType($type)
375
-	{
376
+    {
376 377
         return empty($type) || !is_string($type)
377 378
 			? 'local'
378 379
 			: $type;
@@ -383,7 +384,7 @@  discard block
 block discarded – undo
383 384
 	 * @return object
384 385
 	 */
385 386
     protected function queryReviews(array $args = [], $lastPostId = 0)
386
-	{
387
+    {
387 388
         $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388 389
         $hasMore = is_array($reviews)
389 390
             ? count($reviews) == static::LIMIT
Please login to merge, or discard this patch.
plugin/Reviews.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -9,65 +9,65 @@
 block discarded – undo
9 9
 
10 10
 class Reviews extends ArrayObject
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $args;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $args;
16 16
 
17
-    /**
18
-     * @var int
19
-     */
20
-    public $max_num_pages;
17
+	/**
18
+	 * @var int
19
+	 */
20
+	public $max_num_pages;
21 21
 
22
-    /**
23
-     * @var array
24
-     */
25
-    public $reviews;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $reviews;
26 26
 
27
-    public function __construct(array $reviews, $maxPageCount, array $args)
28
-    {
29
-        $this->args = $args;
30
-        $this->max_num_pages = $maxPageCount;
31
-        $this->reviews = $reviews;
32
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
-    }
27
+	public function __construct(array $reviews, $maxPageCount, array $args)
28
+	{
29
+		$this->args = $args;
30
+		$this->max_num_pages = $maxPageCount;
31
+		$this->reviews = $reviews;
32
+		parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
+	}
34 34
 
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return (string) $this->build();
41
-    }
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return (string) $this->build();
41
+	}
42 42
 
43
-    /**
44
-     * @return ReviewsHtml
45
-     */
46
-    public function build()
47
-    {
48
-        $args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
-        return glsr(SiteReviewsPartial::class)->build($args, $this);
50
-    }
43
+	/**
44
+	 * @return ReviewsHtml
45
+	 */
46
+	public function build()
47
+	{
48
+		$args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
+		return glsr(SiteReviewsPartial::class)->build($args, $this);
50
+	}
51 51
 
52
-    /**
53
-     * @param mixed $key
54
-     * @return mixed
55
-     */
56
-    public function offsetGet($key)
57
-    {
58
-        if (property_exists($this, $key)) {
59
-            return $this->{$key};
60
-        }
61
-        return array_key_exists($key, $this->reviews)
62
-            ? $this->reviews[$key]
63
-            : null;
64
-    }
52
+	/**
53
+	 * @param mixed $key
54
+	 * @return mixed
55
+	 */
56
+	public function offsetGet($key)
57
+	{
58
+		if (property_exists($this, $key)) {
59
+			return $this->{$key};
60
+		}
61
+		return array_key_exists($key, $this->reviews)
62
+			? $this->reviews[$key]
63
+			: null;
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function render()
70
-    {
71
-        echo $this->build();
72
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function render()
70
+	{
71
+		echo $this->build();
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,12 +24,12 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public $reviews;
26 26
 
27
-    public function __construct(array $reviews, $maxPageCount, array $args)
27
+    public function __construct( array $reviews, $maxPageCount, array $args )
28 28
     {
29 29
         $this->args = $args;
30 30
         $this->max_num_pages = $maxPageCount;
31 31
         $this->reviews = $reviews;
32
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
32
+        parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS );
33 33
     }
34 34
 
35 35
     /**
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function __toString()
39 39
     {
40
-        return (string) $this->build();
40
+        return (string)$this->build();
41 41
     }
42 42
 
43 43
     /**
@@ -45,20 +45,20 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function build()
47 47
     {
48
-        $args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
-        return glsr(SiteReviewsPartial::class)->build($args, $this);
48
+        $args = glsr( SiteReviewsDefaults::class )->merge( $this->args );
49
+        return glsr( SiteReviewsPartial::class )->build( $args, $this );
50 50
     }
51 51
 
52 52
     /**
53 53
      * @param mixed $key
54 54
      * @return mixed
55 55
      */
56
-    public function offsetGet($key)
56
+    public function offsetGet( $key )
57 57
     {
58
-        if (property_exists($this, $key)) {
58
+        if( property_exists( $this, $key ) ) {
59 59
             return $this->{$key};
60 60
         }
61
-        return array_key_exists($key, $this->reviews)
61
+        return array_key_exists( $key, $this->reviews )
62 62
             ? $this->reviews[$key]
63 63
             : null;
64 64
     }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsSummaryBlock.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -6,83 +6,83 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsSummaryBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'hide' => [
28
-                'default' => '',
29
-                'type' => 'string',
30
-            ],
31
-            'post_id' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'rating' => [
36
-                'default' => '1',
37
-                'type' => 'number',
38
-            ],
39
-            'schema' => [
40
-                'default' => false,
41
-                'type' => 'boolean',
42
-            ],
43
-            'type' => [
44
-                'default' => 'local',
45
-                'type' => 'string',
46
-            ],
47
-        ];
48
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'hide' => [
28
+				'default' => '',
29
+				'type' => 'string',
30
+			],
31
+			'post_id' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'rating' => [
36
+				'default' => '1',
37
+				'type' => 'number',
38
+			],
39
+			'schema' => [
40
+				'default' => false,
41
+				'type' => 'boolean',
42
+			],
43
+			'type' => [
44
+				'default' => 'local',
45
+				'type' => 'string',
46
+			],
47
+		];
48
+	}
49 49
 
50
-    /**
51
-     * @return string
52
-     */
53
-    public function render(array $attributes)
54
-    {
55
-        $attributes['class'] = $attributes['className'];
56
-        $shortcode = glsr(Shortcode::class);
57
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
58
-            $attributes = $this->normalize($attributes);
59
-            $this->filterShortcodeClass();
60
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
-                $this->filterInterpolation();
62
-            }
63
-        }
64
-        return $shortcode->buildShortcode($attributes);
65
-    }
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function render(array $attributes)
54
+	{
55
+		$attributes['class'] = $attributes['className'];
56
+		$shortcode = glsr(Shortcode::class);
57
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
58
+			$attributes = $this->normalize($attributes);
59
+			$this->filterShortcodeClass();
60
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
+				$this->filterInterpolation();
62
+			}
63
+		}
64
+		return $shortcode->buildShortcode($attributes);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    protected function filterInterpolation()
71
-    {
72
-        add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
-            $context['class'] = 'glsr-default glsr-block-disabled';
74
-            $context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
-            return $context;
76
-        });
77
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	protected function filterInterpolation()
71
+	{
72
+		add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
+			$context['class'] = 'glsr-default glsr-block-disabled';
74
+			$context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
+			return $context;
76
+		});
77
+	}
78 78
 
79
-    /**
80
-     * @return void
81
-     */
82
-    protected function filterShortcodeClass()
83
-    {
84
-        add_filter('site-reviews/style', function () {
85
-            return 'default';
86
-        });
87
-    }
79
+	/**
80
+	 * @return void
81
+	 */
82
+	protected function filterShortcodeClass()
83
+	{
84
+		add_filter('site-reviews/style', function () {
85
+			return 'default';
86
+		});
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return string
52 52
      */
53
-    public function render(array $attributes)
53
+    public function render( array $attributes )
54 54
     {
55 55
         $attributes['class'] = $attributes['className'];
56
-        $shortcode = glsr(Shortcode::class);
57
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
58
-            $attributes = $this->normalize($attributes);
56
+        $shortcode = glsr( Shortcode::class );
57
+        if( 'edit' == filter_input( INPUT_GET, 'context' ) ) {
58
+            $attributes = $this->normalize( $attributes );
59 59
             $this->filterShortcodeClass();
60
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
60
+            if( !$this->hasVisibleFields( $shortcode, $attributes ) ) {
61 61
                 $this->filterInterpolation();
62 62
             }
63 63
         }
64
-        return $shortcode->buildShortcode($attributes);
64
+        return $shortcode->buildShortcode( $attributes );
65 65
     }
66 66
 
67 67
     /**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      */
70 70
     protected function filterInterpolation()
71 71
     {
72
-        add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
72
+        add_filter( 'site-reviews/interpolate/reviews-summary', function( $context ) {
73 73
             $context['class'] = 'glsr-default glsr-block-disabled';
74
-            $context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
74
+            $context['text'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' );
75 75
             return $context;
76 76
         });
77 77
     }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     protected function filterShortcodeClass()
83 83
     {
84
-        add_filter('site-reviews/style', function () {
84
+        add_filter( 'site-reviews/style', function() {
85 85
             return 'default';
86 86
         });
87 87
     }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsFormBlock.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -6,115 +6,115 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsFormBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assign_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'hide' => [
28
-                'default' => '',
29
-                'type' => 'string',
30
-            ],
31
-            'id' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-        ];
36
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assign_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'hide' => [
28
+				'default' => '',
29
+				'type' => 'string',
30
+			],
31
+			'id' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+		];
36
+	}
37 37
 
38
-    /**
39
-     * @return string
40
-     */
41
-    public function render(array $attributes)
42
-    {
43
-        $attributes['class'] = $attributes['className'];
44
-        $shortcode = glsr(Shortcode::class);
45
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
46
-            $this->filterFormFields();
47
-            $this->filterRatingField();
48
-            $this->filterShortcodeClass();
49
-            $this->filterSubmitButton();
50
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
51
-                $this->filterInterpolation();
52
-            }
53
-        }
54
-        return $shortcode->buildShortcode($attributes);
55
-    }
38
+	/**
39
+	 * @return string
40
+	 */
41
+	public function render(array $attributes)
42
+	{
43
+		$attributes['class'] = $attributes['className'];
44
+		$shortcode = glsr(Shortcode::class);
45
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
46
+			$this->filterFormFields();
47
+			$this->filterRatingField();
48
+			$this->filterShortcodeClass();
49
+			$this->filterSubmitButton();
50
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
51
+				$this->filterInterpolation();
52
+			}
53
+		}
54
+		return $shortcode->buildShortcode($attributes);
55
+	}
56 56
 
57
-    /**
58
-     * @return void
59
-     */
60
-    protected function filterFormFields()
61
-    {
62
-        add_filter('site-reviews/config/forms/submission-form', function (array $config) {
63
-            array_walk($config, function (&$field) {
64
-                $field['disabled'] = true;
65
-                $field['tabindex'] = '-1';
66
-            });
67
-            return $config;
68
-        });
69
-    }
57
+	/**
58
+	 * @return void
59
+	 */
60
+	protected function filterFormFields()
61
+	{
62
+		add_filter('site-reviews/config/forms/submission-form', function (array $config) {
63
+			array_walk($config, function (&$field) {
64
+				$field['disabled'] = true;
65
+				$field['tabindex'] = '-1';
66
+			});
67
+			return $config;
68
+		});
69
+	}
70 70
 
71
-    /**
72
-     * @return void
73
-     */
74
-    protected function filterInterpolation()
75
-    {
76
-        add_filter('site-reviews/interpolate/reviews-form', function ($context) {
77
-            $context['class'] = 'glsr-default glsr-block-disabled';
78
-            $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews');
79
-            $context['response'] = '';
80
-            $context['submit_button'] = '';
81
-            return $context;
82
-        });
83
-    }
71
+	/**
72
+	 * @return void
73
+	 */
74
+	protected function filterInterpolation()
75
+	{
76
+		add_filter('site-reviews/interpolate/reviews-form', function ($context) {
77
+			$context['class'] = 'glsr-default glsr-block-disabled';
78
+			$context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews');
79
+			$context['response'] = '';
80
+			$context['submit_button'] = '';
81
+			return $context;
82
+		});
83
+	}
84 84
 
85
-    /**
86
-     * @return void
87
-     */
88
-    protected function filterRatingField()
89
-    {
90
-        add_filter('site-reviews/rendered/field', function ($html, $type, $args) {
91
-            if ('rating' == $args['path']) {
92
-                $stars = '<span class="glsr-stars">';
93
-                $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5);
94
-                $stars.= '</span>';
95
-                $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html);
96
-            }
97
-            return $html;
98
-        }, 10, 3);
99
-    }
85
+	/**
86
+	 * @return void
87
+	 */
88
+	protected function filterRatingField()
89
+	{
90
+		add_filter('site-reviews/rendered/field', function ($html, $type, $args) {
91
+			if ('rating' == $args['path']) {
92
+				$stars = '<span class="glsr-stars">';
93
+				$stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5);
94
+				$stars.= '</span>';
95
+				$html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html);
96
+			}
97
+			return $html;
98
+		}, 10, 3);
99
+	}
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    protected function filterShortcodeClass()
105
-    {
106
-        add_filter('site-reviews/style', function () {
107
-            return 'default';
108
-        });
109
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	protected function filterShortcodeClass()
105
+	{
106
+		add_filter('site-reviews/style', function () {
107
+			return 'default';
108
+		});
109
+	}
110 110
 
111
-    /**
112
-     * @return void
113
-     */
114
-    protected function filterSubmitButton()
115
-    {
116
-        add_filter('site-reviews/rendered/template/form/submit-button', function ($template) {
117
-            return str_replace('type="submit"', 'tabindex="-1"', $template);
118
-        });
119
-    }
111
+	/**
112
+	 * @return void
113
+	 */
114
+	protected function filterSubmitButton()
115
+	{
116
+		add_filter('site-reviews/rendered/template/form/submit-button', function ($template) {
117
+			return str_replace('type="submit"', 'tabindex="-1"', $template);
118
+		});
119
+	}
120 120
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -38,20 +38,20 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @return string
40 40
      */
41
-    public function render(array $attributes)
41
+    public function render( array $attributes )
42 42
     {
43 43
         $attributes['class'] = $attributes['className'];
44
-        $shortcode = glsr(Shortcode::class);
45
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
44
+        $shortcode = glsr( Shortcode::class );
45
+        if( 'edit' == filter_input( INPUT_GET, 'context' ) ) {
46 46
             $this->filterFormFields();
47 47
             $this->filterRatingField();
48 48
             $this->filterShortcodeClass();
49 49
             $this->filterSubmitButton();
50
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
50
+            if( !$this->hasVisibleFields( $shortcode, $attributes ) ) {
51 51
                 $this->filterInterpolation();
52 52
             }
53 53
         }
54
-        return $shortcode->buildShortcode($attributes);
54
+        return $shortcode->buildShortcode( $attributes );
55 55
     }
56 56
 
57 57
     /**
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
      */
60 60
     protected function filterFormFields()
61 61
     {
62
-        add_filter('site-reviews/config/forms/submission-form', function (array $config) {
63
-            array_walk($config, function (&$field) {
62
+        add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) {
63
+            array_walk( $config, function( &$field ) {
64 64
                 $field['disabled'] = true;
65 65
                 $field['tabindex'] = '-1';
66 66
             });
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
      */
74 74
     protected function filterInterpolation()
75 75
     {
76
-        add_filter('site-reviews/interpolate/reviews-form', function ($context) {
76
+        add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) {
77 77
             $context['class'] = 'glsr-default glsr-block-disabled';
78
-            $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews');
78
+            $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' );
79 79
             $context['response'] = '';
80 80
             $context['submit_button'] = '';
81 81
             return $context;
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
      */
88 88
     protected function filterRatingField()
89 89
     {
90
-        add_filter('site-reviews/rendered/field', function ($html, $type, $args) {
91
-            if ('rating' == $args['path']) {
90
+        add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) {
91
+            if( 'rating' == $args['path'] ) {
92 92
                 $stars = '<span class="glsr-stars">';
93
-                $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5);
94
-                $stars.= '</span>';
95
-                $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html);
93
+                $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5 );
94
+                $stars .= '</span>';
95
+                $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html );
96 96
             }
97 97
             return $html;
98
-        }, 10, 3);
98
+        }, 10, 3 );
99 99
     }
100 100
 
101 101
     /**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     protected function filterShortcodeClass()
105 105
     {
106
-        add_filter('site-reviews/style', function () {
106
+        add_filter( 'site-reviews/style', function() {
107 107
             return 'default';
108 108
         });
109 109
     }
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
      */
114 114
     protected function filterSubmitButton()
115 115
     {
116
-        add_filter('site-reviews/rendered/template/form/submit-button', function ($template) {
117
-            return str_replace('type="submit"', 'tabindex="-1"', $template);
116
+        add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) {
117
+            return str_replace( 'type="submit"', 'tabindex="-1"', $template );
118 118
         });
119 119
     }
120 120
 }
Please login to merge, or discard this patch.
plugin/Blocks/BlockGenerator.php 3 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -6,65 +6,65 @@
 block discarded – undo
6 6
 
7 7
 abstract class BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [];
15
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [];
15
+	}
16 16
 
17
-    /**
18
-     * @return array
19
-     */
20
-    public function normalize(array $attributes)
21
-    {
22
-        $hide = array_flip(explode(',', $attributes['hide']));
23
-        unset($hide['if_empty']);
24
-        $attributes['hide'] = implode(',', array_keys($hide));
25
-        if (!isset($attributes['assigned_to'])) {
26
-            return $attributes;
27
-        }
28
-        if ('post_id' == $attributes['assigned_to']) {
29
-            $attributes['assigned_to'] = $attributes['post_id'];
30
-        } elseif ('parent_id' == $attributes['assigned_to']) {
31
-            $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
32
-        }
33
-        return $attributes;
34
-    }
17
+	/**
18
+	 * @return array
19
+	 */
20
+	public function normalize(array $attributes)
21
+	{
22
+		$hide = array_flip(explode(',', $attributes['hide']));
23
+		unset($hide['if_empty']);
24
+		$attributes['hide'] = implode(',', array_keys($hide));
25
+		if (!isset($attributes['assigned_to'])) {
26
+			return $attributes;
27
+		}
28
+		if ('post_id' == $attributes['assigned_to']) {
29
+			$attributes['assigned_to'] = $attributes['post_id'];
30
+		} elseif ('parent_id' == $attributes['assigned_to']) {
31
+			$attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
32
+		}
33
+		return $attributes;
34
+	}
35 35
 
36
-    /**
37
-     * @return void
38
-     */
39
-    public function register($block)
40
-    {
41
-        if (!function_exists('register_block_type')) {
42
-            return;
43
-        }
44
-        register_block_type(Application::ID.'/'.$block, [
45
-            'attributes' => $this->attributes(),
46
-            'editor_script' => Application::ID.'/blocks',
47
-            'editor_style' => Application::ID.'/blocks',
48
-            'render_callback' => [$this, 'render'],
49
-            'style' => Application::ID,
50
-        ]);
51
-    }
36
+	/**
37
+	 * @return void
38
+	 */
39
+	public function register($block)
40
+	{
41
+		if (!function_exists('register_block_type')) {
42
+			return;
43
+		}
44
+		register_block_type(Application::ID.'/'.$block, [
45
+			'attributes' => $this->attributes(),
46
+			'editor_script' => Application::ID.'/blocks',
47
+			'editor_style' => Application::ID.'/blocks',
48
+			'render_callback' => [$this, 'render'],
49
+			'style' => Application::ID,
50
+		]);
51
+	}
52 52
 
53
-    /**
54
-     * @return void
55
-     */
56
-    abstract public function render(array $attributes);
53
+	/**
54
+	 * @return void
55
+	 */
56
+	abstract public function render(array $attributes);
57 57
 
58
-    /**
59
-     * @param mixed $shortcode
60
-     * @return bool
61
-     */
62
-    protected function hasVisibleFields($shortcode, array $attributes)
63
-    {
64
-        $args = $shortcode->normalizeAtts($attributes);
65
-        $defaults = $shortcode->getHideOptions();
66
-        $hide = array_flip($args['hide']);
67
-        unset($defaults['if_empty'], $hide['if_empty']);
68
-        return !empty(array_diff_key($defaults, $hide));
69
-    }
58
+	/**
59
+	 * @param mixed $shortcode
60
+	 * @return bool
61
+	 */
62
+	protected function hasVisibleFields($shortcode, array $attributes)
63
+	{
64
+		$args = $shortcode->normalizeAtts($attributes);
65
+		$defaults = $shortcode->getHideOptions();
66
+		$hide = array_flip($args['hide']);
67
+		unset($defaults['if_empty'], $hide['if_empty']);
68
+		return !empty(array_diff_key($defaults, $hide));
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @return array
19 19
      */
20
-    public function normalize(array $attributes)
20
+    public function normalize( array $attributes )
21 21
     {
22
-        $hide = array_flip(explode(',', $attributes['hide']));
22
+        $hide = array_flip( explode( ',', $attributes['hide'] ) );
23 23
         unset($hide['if_empty']);
24
-        $attributes['hide'] = implode(',', array_keys($hide));
25
-        if (!isset($attributes['assigned_to'])) {
24
+        $attributes['hide'] = implode( ',', array_keys( $hide ) );
25
+        if( !isset($attributes['assigned_to']) ) {
26 26
             return $attributes;
27 27
         }
28
-        if ('post_id' == $attributes['assigned_to']) {
28
+        if( 'post_id' == $attributes['assigned_to'] ) {
29 29
             $attributes['assigned_to'] = $attributes['post_id'];
30
-        } elseif ('parent_id' == $attributes['assigned_to']) {
31
-            $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
30
+        } elseif( 'parent_id' == $attributes['assigned_to'] ) {
31
+            $attributes['assigned_to'] = wp_get_post_parent_id( $attributes['post_id'] );
32 32
         }
33 33
         return $attributes;
34 34
     }
@@ -36,35 +36,35 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * @return void
38 38
      */
39
-    public function register($block)
39
+    public function register( $block )
40 40
     {
41
-        if (!function_exists('register_block_type')) {
41
+        if( !function_exists( 'register_block_type' ) ) {
42 42
             return;
43 43
         }
44
-        register_block_type(Application::ID.'/'.$block, [
44
+        register_block_type( Application::ID.'/'.$block, [
45 45
             'attributes' => $this->attributes(),
46 46
             'editor_script' => Application::ID.'/blocks',
47 47
             'editor_style' => Application::ID.'/blocks',
48 48
             'render_callback' => [$this, 'render'],
49 49
             'style' => Application::ID,
50
-        ]);
50
+        ] );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @return void
55 55
      */
56
-    abstract public function render(array $attributes);
56
+    abstract public function render( array $attributes );
57 57
 
58 58
     /**
59 59
      * @param mixed $shortcode
60 60
      * @return bool
61 61
      */
62
-    protected function hasVisibleFields($shortcode, array $attributes)
62
+    protected function hasVisibleFields( $shortcode, array $attributes )
63 63
     {
64
-        $args = $shortcode->normalizeAtts($attributes);
64
+        $args = $shortcode->normalizeAtts( $attributes );
65 65
         $defaults = $shortcode->getHideOptions();
66
-        $hide = array_flip($args['hide']);
66
+        $hide = array_flip( $args['hide'] );
67 67
         unset($defaults['if_empty'], $hide['if_empty']);
68
-        return !empty(array_diff_key($defaults, $hide));
68
+        return !empty(array_diff_key( $defaults, $hide ));
69 69
     }
70 70
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,8 @@
 block discarded – undo
27 27
         }
28 28
         if ('post_id' == $attributes['assigned_to']) {
29 29
             $attributes['assigned_to'] = $attributes['post_id'];
30
-        } elseif ('parent_id' == $attributes['assigned_to']) {
30
+        }
31
+        elseif ('parent_id' == $attributes['assigned_to']) {
31 32
             $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
32 33
         }
33 34
         return $attributes;
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsBlock.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -6,124 +6,124 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'count' => [
28
-                'default' => 5,
29
-                'type' => 'number',
30
-            ],
31
-            'hide' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'id' => [
36
-                'default' => '',
37
-                'type' => 'string',
38
-            ],
39
-            'pagination' => [
40
-                'default' => '',
41
-                'type' => 'string',
42
-            ],
43
-            'post_id' => [
44
-                'default' => '',
45
-                'type' => 'string',
46
-            ],
47
-            'rating' => [
48
-                'default' => 1,
49
-                'type' => 'number',
50
-            ],
51
-            'schema' => [
52
-                'default' => false,
53
-                'type' => 'boolean',
54
-            ],
55
-            'type' => [
56
-                'default' => 'local',
57
-                'type' => 'string',
58
-            ],
59
-        ];
60
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'count' => [
28
+				'default' => 5,
29
+				'type' => 'number',
30
+			],
31
+			'hide' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'id' => [
36
+				'default' => '',
37
+				'type' => 'string',
38
+			],
39
+			'pagination' => [
40
+				'default' => '',
41
+				'type' => 'string',
42
+			],
43
+			'post_id' => [
44
+				'default' => '',
45
+				'type' => 'string',
46
+			],
47
+			'rating' => [
48
+				'default' => 1,
49
+				'type' => 'number',
50
+			],
51
+			'schema' => [
52
+				'default' => false,
53
+				'type' => 'boolean',
54
+			],
55
+			'type' => [
56
+				'default' => 'local',
57
+				'type' => 'string',
58
+			],
59
+		];
60
+	}
61 61
 
62
-    /**
63
-     * @return string
64
-     */
65
-    public function render(array $attributes)
66
-    {
67
-        $attributes['class'] = $attributes['className'];
68
-        $shortcode = glsr(Shortcode::class);
69
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
70
-            $attributes = $this->normalize($attributes);
71
-            $this->filterReviewLinks();
72
-            $this->filterShortcodeClass();
73
-            $this->filterShowMoreLinks('content');
74
-            $this->filterShowMoreLinks('response');
75
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
-                $this->filterInterpolation();
77
-            }
78
-        }
79
-        return $shortcode->buildShortcode($attributes);
80
-    }
62
+	/**
63
+	 * @return string
64
+	 */
65
+	public function render(array $attributes)
66
+	{
67
+		$attributes['class'] = $attributes['className'];
68
+		$shortcode = glsr(Shortcode::class);
69
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
70
+			$attributes = $this->normalize($attributes);
71
+			$this->filterReviewLinks();
72
+			$this->filterShortcodeClass();
73
+			$this->filterShowMoreLinks('content');
74
+			$this->filterShowMoreLinks('response');
75
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
+				$this->filterInterpolation();
77
+			}
78
+		}
79
+		return $shortcode->buildShortcode($attributes);
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function filterInterpolation()
86
-    {
87
-        add_filter('site-reviews/interpolate/reviews', function ($context) {
88
-            $context['class'] = 'glsr-default glsr-block-disabled';
89
-            $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
-            return $context;
91
-        });
92
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function filterInterpolation()
86
+	{
87
+		add_filter('site-reviews/interpolate/reviews', function ($context) {
88
+			$context['class'] = 'glsr-default glsr-block-disabled';
89
+			$context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
+			return $context;
91
+		});
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    protected function filterReviewLinks()
98
-    {
99
-        add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
-            return str_replace('<a', '<a tabindex="-1"', $template);
101
-        });
102
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	protected function filterReviewLinks()
98
+	{
99
+		add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
+			return str_replace('<a', '<a tabindex="-1"', $template);
101
+		});
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    protected function filterShortcodeClass()
108
-    {
109
-        add_filter('site-reviews/style', function () {
110
-            return 'default';
111
-        });
112
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	protected function filterShortcodeClass()
108
+	{
109
+		add_filter('site-reviews/style', function () {
110
+			return 'default';
111
+		});
112
+	}
113 113
 
114
-    /**
115
-     * @param string $field
116
-     * @return void
117
-     */
118
-    protected function filterShowMoreLinks($field)
119
-    {
120
-        add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
-            $value = preg_replace(
122
-                '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
123
-                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
-                $value
125
-            );
126
-            return $value;
127
-        });
128
-    }
114
+	/**
115
+	 * @param string $field
116
+	 * @return void
117
+	 */
118
+	protected function filterShowMoreLinks($field)
119
+	{
120
+		add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
+			$value = preg_replace(
122
+				'/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
123
+				'$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
+				$value
125
+			);
126
+			return $value;
127
+		});
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -62,21 +62,21 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @return string
64 64
      */
65
-    public function render(array $attributes)
65
+    public function render( array $attributes )
66 66
     {
67 67
         $attributes['class'] = $attributes['className'];
68
-        $shortcode = glsr(Shortcode::class);
69
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
70
-            $attributes = $this->normalize($attributes);
68
+        $shortcode = glsr( Shortcode::class );
69
+        if( 'edit' == filter_input( INPUT_GET, 'context' ) ) {
70
+            $attributes = $this->normalize( $attributes );
71 71
             $this->filterReviewLinks();
72 72
             $this->filterShortcodeClass();
73
-            $this->filterShowMoreLinks('content');
74
-            $this->filterShowMoreLinks('response');
75
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
73
+            $this->filterShowMoreLinks( 'content' );
74
+            $this->filterShowMoreLinks( 'response' );
75
+            if( !$this->hasVisibleFields( $shortcode, $attributes ) ) {
76 76
                 $this->filterInterpolation();
77 77
             }
78 78
         }
79
-        return $shortcode->buildShortcode($attributes);
79
+        return $shortcode->buildShortcode( $attributes );
80 80
     }
81 81
 
82 82
     /**
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
      */
85 85
     protected function filterInterpolation()
86 86
     {
87
-        add_filter('site-reviews/interpolate/reviews', function ($context) {
87
+        add_filter( 'site-reviews/interpolate/reviews', function( $context ) {
88 88
             $context['class'] = 'glsr-default glsr-block-disabled';
89
-            $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
89
+            $context['reviews'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' );
90 90
             return $context;
91 91
         });
92 92
     }
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      */
97 97
     protected function filterReviewLinks()
98 98
     {
99
-        add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
-            return str_replace('<a', '<a tabindex="-1"', $template);
99
+        add_filter( 'site-reviews/rendered/template/reviews', function( $template ) {
100
+            return str_replace( '<a', '<a tabindex="-1"', $template );
101 101
         });
102 102
     }
103 103
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     protected function filterShortcodeClass()
108 108
     {
109
-        add_filter('site-reviews/style', function () {
109
+        add_filter( 'site-reviews/style', function() {
110 110
             return 'default';
111 111
         });
112 112
     }
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
      * @param string $field
116 116
      * @return void
117 117
      */
118
-    protected function filterShowMoreLinks($field)
118
+    protected function filterShowMoreLinks( $field )
119 119
     {
120
-        add_filter('site-reviews/review/wrap/'.$field, function ($value) {
120
+        add_filter( 'site-reviews/review/wrap/'.$field, function( $value ) {
121 121
             $value = preg_replace(
122 122
                 '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
123
-                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
123
+                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__( 'Show more', 'site-reviews' ).'</a>$5',
124 124
                 $value
125 125
             );
126 126
             return $value;
Please login to merge, or discard this patch.
plugin/Helper.php 3 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -221,7 +221,8 @@
 block discarded – undo
221 221
                 if ($flattenValue) {
222 222
                     $value = '['.implode(', ', $value).']';
223 223
                 }
224
-            } elseif (is_array($value)) {
224
+            }
225
+            elseif (is_array($value)) {
225 226
                 $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
226 227
                 continue;
227 228
             }
Please login to merge, or discard this patch.
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -7,409 +7,409 @@
 block discarded – undo
7 7
 
8 8
 class Helper
9 9
 {
10
-    /**
11
-     * @param string $name
12
-     * @param string $path
13
-     * @return string
14
-     */
15
-    public function buildClassName($name, $path = '')
16
-    {
17
-        $className = $this->camelCase($name);
18
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
19
-        return !empty($path)
20
-            ? __NAMESPACE__.'\\'.$path.'\\'.$className
21
-            : $className;
22
-    }
10
+	/**
11
+	 * @param string $name
12
+	 * @param string $path
13
+	 * @return string
14
+	 */
15
+	public function buildClassName($name, $path = '')
16
+	{
17
+		$className = $this->camelCase($name);
18
+		$path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
19
+		return !empty($path)
20
+			? __NAMESPACE__.'\\'.$path.'\\'.$className
21
+			: $className;
22
+	}
23 23
 
24
-    /**
25
-     * @param string $name
26
-     * @param string $prefix
27
-     * @return string
28
-     */
29
-    public function buildMethodName($name, $prefix = '')
30
-    {
31
-        return lcfirst($prefix.$this->buildClassName($name));
32
-    }
24
+	/**
25
+	 * @param string $name
26
+	 * @param string $prefix
27
+	 * @return string
28
+	 */
29
+	public function buildMethodName($name, $prefix = '')
30
+	{
31
+		return lcfirst($prefix.$this->buildClassName($name));
32
+	}
33 33
 
34
-    /**
35
-     * @param string $name
36
-     * @return string
37
-     */
38
-    public function buildPropertyName($name)
39
-    {
40
-        return lcfirst($this->buildClassName($name));
41
-    }
34
+	/**
35
+	 * @param string $name
36
+	 * @return string
37
+	 */
38
+	public function buildPropertyName($name)
39
+	{
40
+		return lcfirst($this->buildClassName($name));
41
+	}
42 42
 
43
-    /**
44
-     * @param string $string
45
-     * @return string
46
-     */
47
-    public function camelCase($string)
48
-    {
49
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
50
-        return str_replace(' ', '', $string);
51
-    }
43
+	/**
44
+	 * @param string $string
45
+	 * @return string
46
+	 */
47
+	public function camelCase($string)
48
+	{
49
+		$string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
50
+		return str_replace(' ', '', $string);
51
+	}
52 52
 
53
-    /**
54
-     * @param string $cast
55
-     * @param mixed $value
56
-     * @return mixed
57
-     */
58
-    public function castTo($cast = '', $value)
59
-    {
60
-        switch ($cast) {
61
-            case 'array':
62
-                return (array) $value;
63
-            case 'boolean':
64
-                if ('no' === $value) {
65
-                    return false;
66
-                }
67
-                return (bool) $value;
68
-            case 'integer':
69
-                if (is_numeric($value) || is_string($value)) {
70
-                    return (int) $value;
71
-                }
72
-                // no break
73
-            case 'object':
74
-                return (object) (array) $value;
75
-            case 'string':
76
-                if (!is_array($value) && !is_object($value)) {
77
-                    return (string) $value;
78
-                }
79
-                // no break
80
-            default:
81
-                return $value;
82
-        }
83
-    }
53
+	/**
54
+	 * @param string $cast
55
+	 * @param mixed $value
56
+	 * @return mixed
57
+	 */
58
+	public function castTo($cast = '', $value)
59
+	{
60
+		switch ($cast) {
61
+			case 'array':
62
+				return (array) $value;
63
+			case 'boolean':
64
+				if ('no' === $value) {
65
+					return false;
66
+				}
67
+				return (bool) $value;
68
+			case 'integer':
69
+				if (is_numeric($value) || is_string($value)) {
70
+					return (int) $value;
71
+				}
72
+				// no break
73
+			case 'object':
74
+				return (object) (array) $value;
75
+			case 'string':
76
+				if (!is_array($value) && !is_object($value)) {
77
+					return (string) $value;
78
+				}
79
+				// no break
80
+			default:
81
+				return $value;
82
+		}
83
+	}
84 84
 
85
-    /**
86
-     * @return bool
87
-     */
88
-    public function compareArrays(array $arr1, array $arr2)
89
-    {
90
-        sort($arr1);
91
-        sort($arr2);
92
-        return $arr1 == $arr2;
93
-    }
85
+	/**
86
+	 * @return bool
87
+	 */
88
+	public function compareArrays(array $arr1, array $arr2)
89
+	{
90
+		sort($arr1);
91
+		sort($arr2);
92
+		return $arr1 == $arr2;
93
+	}
94 94
 
95
-    /**
96
-     * @param mixed $array
97
-     * @return array
98
-     */
99
-    public function consolidateArray($array)
100
-    {
101
-        return is_array($array) || is_object($array)
102
-            ? (array) $array
103
-            : [];
104
-    }
95
+	/**
96
+	 * @param mixed $array
97
+	 * @return array
98
+	 */
99
+	public function consolidateArray($array)
100
+	{
101
+		return is_array($array) || is_object($array)
102
+			? (array) $array
103
+			: [];
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    public function convertDotNotationArray(array $array)
110
-    {
111
-        $results = [];
112
-        foreach ($array as $path => $value) {
113
-            $results = $this->dataSet($results, $path, $value);
114
-        }
115
-        return $results;
116
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function convertDotNotationArray(array $array)
110
+	{
111
+		$results = [];
112
+		foreach ($array as $path => $value) {
113
+			$results = $this->dataSet($results, $path, $value);
114
+		}
115
+		return $results;
116
+	}
117 117
 
118
-    /**
119
-     * @param string $name
120
-     * @return string
121
-     */
122
-    public function convertPathToId($path, $prefix = '')
123
-    {
124
-        return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix));
125
-    }
118
+	/**
119
+	 * @param string $name
120
+	 * @return string
121
+	 */
122
+	public function convertPathToId($path, $prefix = '')
123
+	{
124
+		return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix));
125
+	}
126 126
 
127
-    /**
128
-     * @param string $path
129
-     * @return string
130
-     */
131
-    public function convertPathToName($path, $prefix = '')
132
-    {
133
-        $levels = explode('.', $path);
134
-        return array_reduce($levels, function ($result, $value) {
135
-            return $result.= '['.$value.']';
136
-        }, $prefix);
137
-    }
127
+	/**
128
+	 * @param string $path
129
+	 * @return string
130
+	 */
131
+	public function convertPathToName($path, $prefix = '')
132
+	{
133
+		$levels = explode('.', $path);
134
+		return array_reduce($levels, function ($result, $value) {
135
+			return $result.= '['.$value.']';
136
+		}, $prefix);
137
+	}
138 138
 
139
-    /**
140
-     * @param string $string
141
-     * @param mixed $callback
142
-     * @return array
143
-     */
144
-    public function convertStringToArray($string, $callback = null)
145
-    {
146
-        $array = array_map('trim', explode(',', $string));
147
-        return $callback
148
-            ? array_filter($array, $callback)
149
-            : array_filter($array);
150
-    }
139
+	/**
140
+	 * @param string $string
141
+	 * @param mixed $callback
142
+	 * @return array
143
+	 */
144
+	public function convertStringToArray($string, $callback = null)
145
+	{
146
+		$array = array_map('trim', explode(',', $string));
147
+		return $callback
148
+			? array_filter($array, $callback)
149
+			: array_filter($array);
150
+	}
151 151
 
152
-    /**
153
-     * @param string $string
154
-     * @return string
155
-     */
156
-    public function dashCase($string)
157
-    {
158
-        return str_replace('_', '-', $this->snakeCase($string));
159
-    }
152
+	/**
153
+	 * @param string $string
154
+	 * @return string
155
+	 */
156
+	public function dashCase($string)
157
+	{
158
+		return str_replace('_', '-', $this->snakeCase($string));
159
+	}
160 160
 
161
-    /**
162
-     * Get a value from an array of values using a dot-notation path as reference.
163
-     * @param array $data
164
-     * @param string $path
165
-     * @param mixed $fallback
166
-     * @return mixed
167
-     */
168
-    public function dataGet($data, $path = '', $fallback = '')
169
-    {
170
-        $data = $this->consolidateArray($data);
171
-        $keys = explode('.', $path);
172
-        foreach ($keys as $key) {
173
-            if (!isset($data[$key])) {
174
-                return $fallback;
175
-            }
176
-            $data = $data[$key];
177
-        }
178
-        return $data;
179
-    }
161
+	/**
162
+	 * Get a value from an array of values using a dot-notation path as reference.
163
+	 * @param array $data
164
+	 * @param string $path
165
+	 * @param mixed $fallback
166
+	 * @return mixed
167
+	 */
168
+	public function dataGet($data, $path = '', $fallback = '')
169
+	{
170
+		$data = $this->consolidateArray($data);
171
+		$keys = explode('.', $path);
172
+		foreach ($keys as $key) {
173
+			if (!isset($data[$key])) {
174
+				return $fallback;
175
+			}
176
+			$data = $data[$key];
177
+		}
178
+		return $data;
179
+	}
180 180
 
181
-    /**
182
-     * Set a value to an array of values using a dot-notation path as reference.
183
-     * @param string $path
184
-     * @param mixed $value
185
-     * @return array
186
-     */
187
-    public function dataSet(array $data, $path, $value)
188
-    {
189
-        $token = strtok($path, '.');
190
-        $ref = &$data;
191
-        while (false !== $token) {
192
-            $ref = $this->consolidateArray($ref);
193
-            $ref = &$ref[$token];
194
-            $token = strtok('.');
195
-        }
196
-        $ref = $value;
197
-        return $data;
198
-    }
181
+	/**
182
+	 * Set a value to an array of values using a dot-notation path as reference.
183
+	 * @param string $path
184
+	 * @param mixed $value
185
+	 * @return array
186
+	 */
187
+	public function dataSet(array $data, $path, $value)
188
+	{
189
+		$token = strtok($path, '.');
190
+		$ref = &$data;
191
+		while (false !== $token) {
192
+			$ref = $this->consolidateArray($ref);
193
+			$ref = &$ref[$token];
194
+			$token = strtok('.');
195
+		}
196
+		$ref = $value;
197
+		return $data;
198
+	}
199 199
 
200
-    /**
201
-     * @param string $needle
202
-     * @param string $haystack
203
-     * @return bool
204
-     */
205
-    public function endsWith($needle, $haystack)
206
-    {
207
-        $length = strlen($needle);
208
-        return 0 != $length
209
-            ? substr($haystack, -$length) === $needle
210
-            : true;
211
-    }
200
+	/**
201
+	 * @param string $needle
202
+	 * @param string $haystack
203
+	 * @return bool
204
+	 */
205
+	public function endsWith($needle, $haystack)
206
+	{
207
+		$length = strlen($needle);
208
+		return 0 != $length
209
+			? substr($haystack, -$length) === $needle
210
+			: true;
211
+	}
212 212
 
213
-    /**
214
-     * @param string $key
215
-     * @return mixed
216
-     */
217
-    public function filterInput($key, array $request = [])
218
-    {
219
-        if (isset($request[$key])) {
220
-            return $request[$key];
221
-        }
222
-        $variable = filter_input(INPUT_POST, $key);
223
-        if (is_null($variable) && isset($_POST[$key])) {
224
-            $variable = $_POST[$key];
225
-        }
226
-        return $variable;
227
-    }
213
+	/**
214
+	 * @param string $key
215
+	 * @return mixed
216
+	 */
217
+	public function filterInput($key, array $request = [])
218
+	{
219
+		if (isset($request[$key])) {
220
+			return $request[$key];
221
+		}
222
+		$variable = filter_input(INPUT_POST, $key);
223
+		if (is_null($variable) && isset($_POST[$key])) {
224
+			$variable = $_POST[$key];
225
+		}
226
+		return $variable;
227
+	}
228 228
 
229
-    /**
230
-     * @param string $key
231
-     * @return array
232
-     */
233
-    public function filterInputArray($key)
234
-    {
235
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
236
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
237
-            $variable = $_POST[$key];
238
-        }
239
-        return (array) $variable;
240
-    }
229
+	/**
230
+	 * @param string $key
231
+	 * @return array
232
+	 */
233
+	public function filterInputArray($key)
234
+	{
235
+		$variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
236
+		if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
237
+			$variable = $_POST[$key];
238
+		}
239
+		return (array) $variable;
240
+	}
241 241
 
242
-    /**
243
-     * @param bool $flattenValue
244
-     * @param string $prefix
245
-     * @return array
246
-     */
247
-    public function flattenArray(array $array, $flattenValue = false, $prefix = '')
248
-    {
249
-        $result = [];
250
-        foreach ($array as $key => $value) {
251
-            $newKey = ltrim($prefix.'.'.$key, '.');
252
-            if ($this->isIndexedFlatArray($value)) {
253
-                if ($flattenValue) {
254
-                    $value = '['.implode(', ', $value).']';
255
-                }
256
-            } elseif (is_array($value)) {
257
-                $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
258
-                continue;
259
-            }
260
-            $result[$newKey] = $value;
261
-        }
262
-        return $result;
263
-    }
242
+	/**
243
+	 * @param bool $flattenValue
244
+	 * @param string $prefix
245
+	 * @return array
246
+	 */
247
+	public function flattenArray(array $array, $flattenValue = false, $prefix = '')
248
+	{
249
+		$result = [];
250
+		foreach ($array as $key => $value) {
251
+			$newKey = ltrim($prefix.'.'.$key, '.');
252
+			if ($this->isIndexedFlatArray($value)) {
253
+				if ($flattenValue) {
254
+					$value = '['.implode(', ', $value).']';
255
+				}
256
+			} elseif (is_array($value)) {
257
+				$result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
258
+				continue;
259
+			}
260
+			$result[$newKey] = $value;
261
+		}
262
+		return $result;
263
+	}
264 264
 
265
-    /**
266
-     * @return string
267
-     */
268
-    public function getIpAddress()
269
-    {
270
-        $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
271
-        $ipv6 = defined('AF_INET6')
272
-            ? $cloudflareIps['v6']
273
-            : [];
274
-        $whitelist = apply_filters('site-reviews/whip/whitelist', [
275
-            Whip::CLOUDFLARE_HEADERS => [
276
-                Whip::IPV4 => $cloudflareIps['v4'],
277
-                Whip::IPV6 => $ipv6,
278
-            ],
279
-            Whip::CUSTOM_HEADERS => [
280
-                Whip::IPV4 => ['127.0.0.1'],
281
-                Whip::IPV6 => ['::1'],
282
-            ],
283
-        ]);
284
-        $methods = Whip::CUSTOM_HEADERS | Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR;
285
-        $methods = apply_filters('site-reviews/whip/methods', $methods);
286
-        $whip = new Whip($methods, $whitelist);
287
-        do_action_ref_array('site-reviews/whip', [$whip]);
288
-        return (string) $whip->getValidIpAddress();
289
-    }
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function getIpAddress()
269
+	{
270
+		$cloudflareIps = glsr(Cache::class)->getCloudflareIps();
271
+		$ipv6 = defined('AF_INET6')
272
+			? $cloudflareIps['v6']
273
+			: [];
274
+		$whitelist = apply_filters('site-reviews/whip/whitelist', [
275
+			Whip::CLOUDFLARE_HEADERS => [
276
+				Whip::IPV4 => $cloudflareIps['v4'],
277
+				Whip::IPV6 => $ipv6,
278
+			],
279
+			Whip::CUSTOM_HEADERS => [
280
+				Whip::IPV4 => ['127.0.0.1'],
281
+				Whip::IPV6 => ['::1'],
282
+			],
283
+		]);
284
+		$methods = Whip::CUSTOM_HEADERS | Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR;
285
+		$methods = apply_filters('site-reviews/whip/methods', $methods);
286
+		$whip = new Whip($methods, $whitelist);
287
+		do_action_ref_array('site-reviews/whip', [$whip]);
288
+		return (string) $whip->getValidIpAddress();
289
+	}
290 290
 
291
-    /**
292
-     * @param string $key
293
-     * @param string $position
294
-     * @return array
295
-     */
296
-    public function insertInArray(array $array, array $insert, $key, $position = 'before')
297
-    {
298
-        $keyPosition = intval(array_search($key, array_keys($array)));
299
-        if ('after' == $position) {
300
-            ++$keyPosition;
301
-        }
302
-        if (false !== $keyPosition) {
303
-            $result = array_slice($array, 0, $keyPosition);
304
-            $result = array_merge($result, $insert);
305
-            return array_merge($result, array_slice($array, $keyPosition));
306
-        }
307
-        return array_merge($array, $insert);
308
-    }
291
+	/**
292
+	 * @param string $key
293
+	 * @param string $position
294
+	 * @return array
295
+	 */
296
+	public function insertInArray(array $array, array $insert, $key, $position = 'before')
297
+	{
298
+		$keyPosition = intval(array_search($key, array_keys($array)));
299
+		if ('after' == $position) {
300
+			++$keyPosition;
301
+		}
302
+		if (false !== $keyPosition) {
303
+			$result = array_slice($array, 0, $keyPosition);
304
+			$result = array_merge($result, $insert);
305
+			return array_merge($result, array_slice($array, $keyPosition));
306
+		}
307
+		return array_merge($array, $insert);
308
+	}
309 309
 
310
-    /**
311
-     * @param mixed $array
312
-     * @return bool
313
-     */
314
-    public function isIndexedFlatArray($array)
315
-    {
316
-        if (!is_array($array) || array_filter($array, 'is_array')) {
317
-            return false;
318
-        }
319
-        return wp_is_numeric_array($array);
320
-    }
310
+	/**
311
+	 * @param mixed $array
312
+	 * @return bool
313
+	 */
314
+	public function isIndexedFlatArray($array)
315
+	{
316
+		if (!is_array($array) || array_filter($array, 'is_array')) {
317
+			return false;
318
+		}
319
+		return wp_is_numeric_array($array);
320
+	}
321 321
 
322
-    /**
323
-     * @param bool $prefixed
324
-     * @return array
325
-     */
326
-    public function prefixArrayKeys(array $values, $prefixed = true)
327
-    {
328
-        $prefix = $prefixed
329
-            ? '_'
330
-            : '';
331
-        $prefixed = [];
332
-        foreach ($values as $key => $value) {
333
-            $key = $this->prefixString($key, $prefix, '_');
334
-            $prefixed[$key] = $value;
335
-        }
336
-        return $prefixed;
337
-    }
322
+	/**
323
+	 * @param bool $prefixed
324
+	 * @return array
325
+	 */
326
+	public function prefixArrayKeys(array $values, $prefixed = true)
327
+	{
328
+		$prefix = $prefixed
329
+			? '_'
330
+			: '';
331
+		$prefixed = [];
332
+		foreach ($values as $key => $value) {
333
+			$key = $this->prefixString($key, $prefix, '_');
334
+			$prefixed[$key] = $value;
335
+		}
336
+		return $prefixed;
337
+	}
338 338
 
339
-    /**
340
-     * @param string $string
341
-     * @param string $prefix
342
-     * @param null|string $trim
343
-     * @return string
344
-     */
345
-    public function prefixString($string, $prefix = '', $trim = null)
346
-    {
347
-        if (null === $trim) {
348
-            $trim = $prefix;
349
-        }
350
-        return $prefix.ltrim(trim($string), $trim);
351
-    }
339
+	/**
340
+	 * @param string $string
341
+	 * @param string $prefix
342
+	 * @param null|string $trim
343
+	 * @return string
344
+	 */
345
+	public function prefixString($string, $prefix = '', $trim = null)
346
+	{
347
+		if (null === $trim) {
348
+			$trim = $prefix;
349
+		}
350
+		return $prefix.ltrim(trim($string), $trim);
351
+	}
352 352
 
353
-    /**
354
-     * @return array
355
-     */
356
-    public function removeEmptyArrayValues(array $array)
357
-    {
358
-        $result = [];
359
-        foreach ($array as $key => $value) {
360
-            if (!$value) {
361
-                continue;
362
-            }
363
-            $result[$key] = is_array($value)
364
-                ? $this->removeEmptyArrayValues($value)
365
-                : $value;
366
-        }
367
-        return $result;
368
-    }
353
+	/**
354
+	 * @return array
355
+	 */
356
+	public function removeEmptyArrayValues(array $array)
357
+	{
358
+		$result = [];
359
+		foreach ($array as $key => $value) {
360
+			if (!$value) {
361
+				continue;
362
+			}
363
+			$result[$key] = is_array($value)
364
+				? $this->removeEmptyArrayValues($value)
365
+				: $value;
366
+		}
367
+		return $result;
368
+	}
369 369
 
370
-    /**
371
-     * @param string $prefix
372
-     * @param string $text
373
-     * @return string
374
-     */
375
-    public function removePrefix($prefix, $text)
376
-    {
377
-        return 0 === strpos($text, $prefix)
378
-            ? substr($text, strlen($prefix))
379
-            : $text;
380
-    }
370
+	/**
371
+	 * @param string $prefix
372
+	 * @param string $text
373
+	 * @return string
374
+	 */
375
+	public function removePrefix($prefix, $text)
376
+	{
377
+		return 0 === strpos($text, $prefix)
378
+			? substr($text, strlen($prefix))
379
+			: $text;
380
+	}
381 381
 
382
-    /**
383
-     * @param string $string
384
-     * @return string
385
-     */
386
-    public function snakeCase($string)
387
-    {
388
-        if (!ctype_lower($string)) {
389
-            $string = preg_replace('/\s+/u', '', $string);
390
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
391
-            $string = function_exists('mb_strtolower')
392
-                ? mb_strtolower($string, 'UTF-8')
393
-                : strtolower($string);
394
-        }
395
-        return str_replace('-', '_', $string);
396
-    }
382
+	/**
383
+	 * @param string $string
384
+	 * @return string
385
+	 */
386
+	public function snakeCase($string)
387
+	{
388
+		if (!ctype_lower($string)) {
389
+			$string = preg_replace('/\s+/u', '', $string);
390
+			$string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
391
+			$string = function_exists('mb_strtolower')
392
+				? mb_strtolower($string, 'UTF-8')
393
+				: strtolower($string);
394
+		}
395
+		return str_replace('-', '_', $string);
396
+	}
397 397
 
398
-    /**
399
-     * @param string $needle
400
-     * @param string $haystack
401
-     * @return bool
402
-     */
403
-    public function startsWith($needle, $haystack)
404
-    {
405
-        return substr($haystack, 0, strlen($needle)) === $needle;
406
-    }
398
+	/**
399
+	 * @param string $needle
400
+	 * @param string $haystack
401
+	 * @return bool
402
+	 */
403
+	public function startsWith($needle, $haystack)
404
+	{
405
+		return substr($haystack, 0, strlen($needle)) === $needle;
406
+	}
407 407
 
408
-    /**
409
-     * @return array
410
-     */
411
-    public function unprefixArrayKeys(array $values)
412
-    {
413
-        return $this->prefixArrayKeys($values, false);
414
-    }
408
+	/**
409
+	 * @return array
410
+	 */
411
+	public function unprefixArrayKeys(array $values)
412
+	{
413
+		return $this->prefixArrayKeys($values, false);
414
+	}
415 415
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
      * @param string $path
13 13
      * @return string
14 14
      */
15
-    public function buildClassName($name, $path = '')
15
+    public function buildClassName( $name, $path = '' )
16 16
     {
17
-        $className = $this->camelCase($name);
18
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
17
+        $className = $this->camelCase( $name );
18
+        $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' );
19 19
         return !empty($path)
20 20
             ? __NAMESPACE__.'\\'.$path.'\\'.$className
21 21
             : $className;
@@ -26,28 +26,28 @@  discard block
 block discarded – undo
26 26
      * @param string $prefix
27 27
      * @return string
28 28
      */
29
-    public function buildMethodName($name, $prefix = '')
29
+    public function buildMethodName( $name, $prefix = '' )
30 30
     {
31
-        return lcfirst($prefix.$this->buildClassName($name));
31
+        return lcfirst( $prefix.$this->buildClassName( $name ) );
32 32
     }
33 33
 
34 34
     /**
35 35
      * @param string $name
36 36
      * @return string
37 37
      */
38
-    public function buildPropertyName($name)
38
+    public function buildPropertyName( $name )
39 39
     {
40
-        return lcfirst($this->buildClassName($name));
40
+        return lcfirst( $this->buildClassName( $name ) );
41 41
     }
42 42
 
43 43
     /**
44 44
      * @param string $string
45 45
      * @return string
46 46
      */
47
-    public function camelCase($string)
47
+    public function camelCase( $string )
48 48
     {
49
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
50
-        return str_replace(' ', '', $string);
49
+        $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) );
50
+        return str_replace( ' ', '', $string );
51 51
     }
52 52
 
53 53
     /**
@@ -55,26 +55,26 @@  discard block
 block discarded – undo
55 55
      * @param mixed $value
56 56
      * @return mixed
57 57
      */
58
-    public function castTo($cast = '', $value)
58
+    public function castTo( $cast = '', $value )
59 59
     {
60
-        switch ($cast) {
60
+        switch( $cast ) {
61 61
             case 'array':
62
-                return (array) $value;
62
+                return (array)$value;
63 63
             case 'boolean':
64
-                if ('no' === $value) {
64
+                if( 'no' === $value ) {
65 65
                     return false;
66 66
                 }
67
-                return (bool) $value;
67
+                return (bool)$value;
68 68
             case 'integer':
69
-                if (is_numeric($value) || is_string($value)) {
70
-                    return (int) $value;
69
+                if( is_numeric( $value ) || is_string( $value ) ) {
70
+                    return (int)$value;
71 71
                 }
72 72
                 // no break
73 73
             case 'object':
74
-                return (object) (array) $value;
74
+                return (object)(array)$value;
75 75
             case 'string':
76
-                if (!is_array($value) && !is_object($value)) {
77
-                    return (string) $value;
76
+                if( !is_array( $value ) && !is_object( $value ) ) {
77
+                    return (string)$value;
78 78
                 }
79 79
                 // no break
80 80
             default:
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
     /**
86 86
      * @return bool
87 87
      */
88
-    public function compareArrays(array $arr1, array $arr2)
88
+    public function compareArrays( array $arr1, array $arr2 )
89 89
     {
90
-        sort($arr1);
91
-        sort($arr2);
90
+        sort( $arr1 );
91
+        sort( $arr2 );
92 92
         return $arr1 == $arr2;
93 93
     }
94 94
 
@@ -96,21 +96,21 @@  discard block
 block discarded – undo
96 96
      * @param mixed $array
97 97
      * @return array
98 98
      */
99
-    public function consolidateArray($array)
99
+    public function consolidateArray( $array )
100 100
     {
101
-        return is_array($array) || is_object($array)
102
-            ? (array) $array
101
+        return is_array( $array ) || is_object( $array )
102
+            ? (array)$array
103 103
             : [];
104 104
     }
105 105
 
106 106
     /**
107 107
      * @return array
108 108
      */
109
-    public function convertDotNotationArray(array $array)
109
+    public function convertDotNotationArray( array $array )
110 110
     {
111 111
         $results = [];
112
-        foreach ($array as $path => $value) {
113
-            $results = $this->dataSet($results, $path, $value);
112
+        foreach( $array as $path => $value ) {
113
+            $results = $this->dataSet( $results, $path, $value );
114 114
         }
115 115
         return $results;
116 116
     }
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
      * @param string $name
120 120
      * @return string
121 121
      */
122
-    public function convertPathToId($path, $prefix = '')
122
+    public function convertPathToId( $path, $prefix = '' )
123 123
     {
124
-        return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix));
124
+        return str_replace( ['[', ']'], ['-', ''], $this->convertPathToName( $path, $prefix ) );
125 125
     }
126 126
 
127 127
     /**
128 128
      * @param string $path
129 129
      * @return string
130 130
      */
131
-    public function convertPathToName($path, $prefix = '')
131
+    public function convertPathToName( $path, $prefix = '' )
132 132
     {
133
-        $levels = explode('.', $path);
134
-        return array_reduce($levels, function ($result, $value) {
135
-            return $result.= '['.$value.']';
136
-        }, $prefix);
133
+        $levels = explode( '.', $path );
134
+        return array_reduce( $levels, function( $result, $value ) {
135
+            return $result .= '['.$value.']';
136
+        }, $prefix );
137 137
     }
138 138
 
139 139
     /**
@@ -141,21 +141,21 @@  discard block
 block discarded – undo
141 141
      * @param mixed $callback
142 142
      * @return array
143 143
      */
144
-    public function convertStringToArray($string, $callback = null)
144
+    public function convertStringToArray( $string, $callback = null )
145 145
     {
146
-        $array = array_map('trim', explode(',', $string));
146
+        $array = array_map( 'trim', explode( ',', $string ) );
147 147
         return $callback
148
-            ? array_filter($array, $callback)
149
-            : array_filter($array);
148
+            ? array_filter( $array, $callback )
149
+            : array_filter( $array );
150 150
     }
151 151
 
152 152
     /**
153 153
      * @param string $string
154 154
      * @return string
155 155
      */
156
-    public function dashCase($string)
156
+    public function dashCase( $string )
157 157
     {
158
-        return str_replace('_', '-', $this->snakeCase($string));
158
+        return str_replace( '_', '-', $this->snakeCase( $string ) );
159 159
     }
160 160
 
161 161
     /**
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
      * @param mixed $fallback
166 166
      * @return mixed
167 167
      */
168
-    public function dataGet($data, $path = '', $fallback = '')
168
+    public function dataGet( $data, $path = '', $fallback = '' )
169 169
     {
170
-        $data = $this->consolidateArray($data);
171
-        $keys = explode('.', $path);
172
-        foreach ($keys as $key) {
173
-            if (!isset($data[$key])) {
170
+        $data = $this->consolidateArray( $data );
171
+        $keys = explode( '.', $path );
172
+        foreach( $keys as $key ) {
173
+            if( !isset($data[$key]) ) {
174 174
                 return $fallback;
175 175
             }
176 176
             $data = $data[$key];
@@ -184,14 +184,14 @@  discard block
 block discarded – undo
184 184
      * @param mixed $value
185 185
      * @return array
186 186
      */
187
-    public function dataSet(array $data, $path, $value)
187
+    public function dataSet( array $data, $path, $value )
188 188
     {
189
-        $token = strtok($path, '.');
189
+        $token = strtok( $path, '.' );
190 190
         $ref = &$data;
191
-        while (false !== $token) {
192
-            $ref = $this->consolidateArray($ref);
191
+        while( false !== $token ) {
192
+            $ref = $this->consolidateArray( $ref );
193 193
             $ref = &$ref[$token];
194
-            $token = strtok('.');
194
+            $token = strtok( '.' );
195 195
         }
196 196
         $ref = $value;
197 197
         return $data;
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
      * @param string $haystack
203 203
      * @return bool
204 204
      */
205
-    public function endsWith($needle, $haystack)
205
+    public function endsWith( $needle, $haystack )
206 206
     {
207
-        $length = strlen($needle);
207
+        $length = strlen( $needle );
208 208
         return 0 != $length
209
-            ? substr($haystack, -$length) === $needle
209
+            ? substr( $haystack, -$length ) === $needle
210 210
             : true;
211 211
     }
212 212
 
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
      * @param string $key
215 215
      * @return mixed
216 216
      */
217
-    public function filterInput($key, array $request = [])
217
+    public function filterInput( $key, array $request = [] )
218 218
     {
219
-        if (isset($request[$key])) {
219
+        if( isset($request[$key]) ) {
220 220
             return $request[$key];
221 221
         }
222
-        $variable = filter_input(INPUT_POST, $key);
223
-        if (is_null($variable) && isset($_POST[$key])) {
222
+        $variable = filter_input( INPUT_POST, $key );
223
+        if( is_null( $variable ) && isset($_POST[$key]) ) {
224 224
             $variable = $_POST[$key];
225 225
         }
226 226
         return $variable;
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
      * @param string $key
231 231
      * @return array
232 232
      */
233
-    public function filterInputArray($key)
233
+    public function filterInputArray( $key )
234 234
     {
235
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
236
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
235
+        $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
236
+        if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) {
237 237
             $variable = $_POST[$key];
238 238
         }
239
-        return (array) $variable;
239
+        return (array)$variable;
240 240
     }
241 241
 
242 242
     /**
@@ -244,17 +244,17 @@  discard block
 block discarded – undo
244 244
      * @param string $prefix
245 245
      * @return array
246 246
      */
247
-    public function flattenArray(array $array, $flattenValue = false, $prefix = '')
247
+    public function flattenArray( array $array, $flattenValue = false, $prefix = '' )
248 248
     {
249 249
         $result = [];
250
-        foreach ($array as $key => $value) {
251
-            $newKey = ltrim($prefix.'.'.$key, '.');
252
-            if ($this->isIndexedFlatArray($value)) {
253
-                if ($flattenValue) {
254
-                    $value = '['.implode(', ', $value).']';
250
+        foreach( $array as $key => $value ) {
251
+            $newKey = ltrim( $prefix.'.'.$key, '.' );
252
+            if( $this->isIndexedFlatArray( $value ) ) {
253
+                if( $flattenValue ) {
254
+                    $value = '['.implode( ', ', $value ).']';
255 255
                 }
256
-            } elseif (is_array($value)) {
257
-                $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey));
256
+            } elseif( is_array( $value ) ) {
257
+                $result = array_merge( $result, $this->flattenArray( $value, $flattenValue, $newKey ) );
258 258
                 continue;
259 259
             }
260 260
             $result[$newKey] = $value;
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public function getIpAddress()
269 269
     {
270
-        $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
271
-        $ipv6 = defined('AF_INET6')
270
+        $cloudflareIps = glsr( Cache::class )->getCloudflareIps();
271
+        $ipv6 = defined( 'AF_INET6' )
272 272
             ? $cloudflareIps['v6']
273 273
             : [];
274
-        $whitelist = apply_filters('site-reviews/whip/whitelist', [
274
+        $whitelist = apply_filters( 'site-reviews/whip/whitelist', [
275 275
             Whip::CLOUDFLARE_HEADERS => [
276 276
                 Whip::IPV4 => $cloudflareIps['v4'],
277 277
                 Whip::IPV6 => $ipv6,
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
                 Whip::IPV4 => ['127.0.0.1'],
281 281
                 Whip::IPV6 => ['::1'],
282 282
             ],
283
-        ]);
283
+        ] );
284 284
         $methods = Whip::CUSTOM_HEADERS | Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR;
285
-        $methods = apply_filters('site-reviews/whip/methods', $methods);
286
-        $whip = new Whip($methods, $whitelist);
287
-        do_action_ref_array('site-reviews/whip', [$whip]);
288
-        return (string) $whip->getValidIpAddress();
285
+        $methods = apply_filters( 'site-reviews/whip/methods', $methods );
286
+        $whip = new Whip( $methods, $whitelist );
287
+        do_action_ref_array( 'site-reviews/whip', [$whip] );
288
+        return (string)$whip->getValidIpAddress();
289 289
     }
290 290
 
291 291
     /**
@@ -293,44 +293,44 @@  discard block
 block discarded – undo
293 293
      * @param string $position
294 294
      * @return array
295 295
      */
296
-    public function insertInArray(array $array, array $insert, $key, $position = 'before')
296
+    public function insertInArray( array $array, array $insert, $key, $position = 'before' )
297 297
     {
298
-        $keyPosition = intval(array_search($key, array_keys($array)));
299
-        if ('after' == $position) {
298
+        $keyPosition = intval( array_search( $key, array_keys( $array ) ) );
299
+        if( 'after' == $position ) {
300 300
             ++$keyPosition;
301 301
         }
302
-        if (false !== $keyPosition) {
303
-            $result = array_slice($array, 0, $keyPosition);
304
-            $result = array_merge($result, $insert);
305
-            return array_merge($result, array_slice($array, $keyPosition));
302
+        if( false !== $keyPosition ) {
303
+            $result = array_slice( $array, 0, $keyPosition );
304
+            $result = array_merge( $result, $insert );
305
+            return array_merge( $result, array_slice( $array, $keyPosition ) );
306 306
         }
307
-        return array_merge($array, $insert);
307
+        return array_merge( $array, $insert );
308 308
     }
309 309
 
310 310
     /**
311 311
      * @param mixed $array
312 312
      * @return bool
313 313
      */
314
-    public function isIndexedFlatArray($array)
314
+    public function isIndexedFlatArray( $array )
315 315
     {
316
-        if (!is_array($array) || array_filter($array, 'is_array')) {
316
+        if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) {
317 317
             return false;
318 318
         }
319
-        return wp_is_numeric_array($array);
319
+        return wp_is_numeric_array( $array );
320 320
     }
321 321
 
322 322
     /**
323 323
      * @param bool $prefixed
324 324
      * @return array
325 325
      */
326
-    public function prefixArrayKeys(array $values, $prefixed = true)
326
+    public function prefixArrayKeys( array $values, $prefixed = true )
327 327
     {
328 328
         $prefix = $prefixed
329 329
             ? '_'
330 330
             : '';
331 331
         $prefixed = [];
332
-        foreach ($values as $key => $value) {
333
-            $key = $this->prefixString($key, $prefix, '_');
332
+        foreach( $values as $key => $value ) {
333
+            $key = $this->prefixString( $key, $prefix, '_' );
334 334
             $prefixed[$key] = $value;
335 335
         }
336 336
         return $prefixed;
@@ -342,26 +342,26 @@  discard block
 block discarded – undo
342 342
      * @param null|string $trim
343 343
      * @return string
344 344
      */
345
-    public function prefixString($string, $prefix = '', $trim = null)
345
+    public function prefixString( $string, $prefix = '', $trim = null )
346 346
     {
347
-        if (null === $trim) {
347
+        if( null === $trim ) {
348 348
             $trim = $prefix;
349 349
         }
350
-        return $prefix.ltrim(trim($string), $trim);
350
+        return $prefix.ltrim( trim( $string ), $trim );
351 351
     }
352 352
 
353 353
     /**
354 354
      * @return array
355 355
      */
356
-    public function removeEmptyArrayValues(array $array)
356
+    public function removeEmptyArrayValues( array $array )
357 357
     {
358 358
         $result = [];
359
-        foreach ($array as $key => $value) {
360
-            if (!$value) {
359
+        foreach( $array as $key => $value ) {
360
+            if( !$value ) {
361 361
                 continue;
362 362
             }
363
-            $result[$key] = is_array($value)
364
-                ? $this->removeEmptyArrayValues($value)
363
+            $result[$key] = is_array( $value )
364
+                ? $this->removeEmptyArrayValues( $value )
365 365
                 : $value;
366 366
         }
367 367
         return $result;
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
      * @param string $text
373 373
      * @return string
374 374
      */
375
-    public function removePrefix($prefix, $text)
375
+    public function removePrefix( $prefix, $text )
376 376
     {
377
-        return 0 === strpos($text, $prefix)
378
-            ? substr($text, strlen($prefix))
377
+        return 0 === strpos( $text, $prefix )
378
+            ? substr( $text, strlen( $prefix ) )
379 379
             : $text;
380 380
     }
381 381
 
@@ -383,16 +383,16 @@  discard block
 block discarded – undo
383 383
      * @param string $string
384 384
      * @return string
385 385
      */
386
-    public function snakeCase($string)
386
+    public function snakeCase( $string )
387 387
     {
388
-        if (!ctype_lower($string)) {
389
-            $string = preg_replace('/\s+/u', '', $string);
390
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
391
-            $string = function_exists('mb_strtolower')
392
-                ? mb_strtolower($string, 'UTF-8')
393
-                : strtolower($string);
388
+        if( !ctype_lower( $string ) ) {
389
+            $string = preg_replace( '/\s+/u', '', $string );
390
+            $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string );
391
+            $string = function_exists( 'mb_strtolower' )
392
+                ? mb_strtolower( $string, 'UTF-8' )
393
+                : strtolower( $string );
394 394
         }
395
-        return str_replace('-', '_', $string);
395
+        return str_replace( '-', '_', $string );
396 396
     }
397 397
 
398 398
     /**
@@ -400,16 +400,16 @@  discard block
 block discarded – undo
400 400
      * @param string $haystack
401 401
      * @return bool
402 402
      */
403
-    public function startsWith($needle, $haystack)
403
+    public function startsWith( $needle, $haystack )
404 404
     {
405
-        return substr($haystack, 0, strlen($needle)) === $needle;
405
+        return substr( $haystack, 0, strlen( $needle ) ) === $needle;
406 406
     }
407 407
 
408 408
     /**
409 409
      * @return array
410 410
      */
411
-    public function unprefixArrayKeys(array $values)
411
+    public function unprefixArrayKeys( array $values )
412 412
     {
413
-        return $this->prefixArrayKeys($values, false);
413
+        return $this->prefixArrayKeys( $values, false );
414 414
     }
415 415
 }
Please login to merge, or discard this patch.