Passed
Push — master ( e0a59a...75b6ac )
by Paul
06:30 queued 02:41
created
plugin/Defaults/DefaultsAbstract.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
 
9 9
 abstract class DefaultsAbstract
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    protected $callable = [
15
-        'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
-    ];
17
-
18
-    /**
19
-     * @var array
20
-     */
21
-    protected $guarded = [];
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $mapped = [];
27
-
28
-    /**
29
-     * @param string $name
30
-     * @return void|array
31
-     */
32
-    public function __call($name, array $args = [])
33
-    {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
-            return;
36
-        }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
-    }
44
-
45
-    /**
46
-     * @return array
47
-     */
48
-    abstract protected function defaults();
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function filter(array $values = [])
54
-    {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
56
-    }
57
-
58
-    /**
59
-     * @return string
60
-     */
61
-    protected function filteredJson(array $values = [])
62
-    {
63
-        $defaults = $this->flattenArray(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
65
-        );
66
-        $values = $this->flattenArray(
67
-            shortcode_atts($defaults, $values)
68
-        );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
71
-        });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
-    }
74
-
75
-    /**
76
-     * @return array
77
-     */
78
-    protected function flattenArray(array $values)
79
-    {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
82
-                return;
83
-            }
84
-            $value = implode(',', $value);
85
-        });
86
-        return $values;
87
-    }
88
-
89
-    /**
90
-     * @param mixed $var
91
-     * @return bool
92
-     */
93
-    protected function isEmpty($var)
94
-    {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
96
-    }
97
-
98
-    /**
99
-     * @return array
100
-     */
101
-    protected function mapKeys(array $args)
102
-    {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
105
-                $args[$new] = $args[$old];
106
-                unset($args[$old]);
107
-            }
108
-        }
109
-        return $args;
110
-    }
111
-
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function merge(array $values = [])
116
-    {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
-    }
119
-
120
-    /**
121
-     * @return array
122
-     */
123
-    protected function normalize(array $values, array $originalValues)
124
-    {
125
-        $values['json'] = $this->filteredJson($originalValues);
126
-        return $values;
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function restrict(array $values = [])
133
-    {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
-    }
136
-
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function unguarded()
141
-    {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
143
-    }
11
+	/**
12
+	 * @var array
13
+	 */
14
+	protected $callable = [
15
+		'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
+	];
17
+
18
+	/**
19
+	 * @var array
20
+	 */
21
+	protected $guarded = [];
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $mapped = [];
27
+
28
+	/**
29
+	 * @param string $name
30
+	 * @return void|array
31
+	 */
32
+	public function __call($name, array $args = [])
33
+	{
34
+		if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
+			return;
36
+		}
37
+		$args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
+		$defaults = call_user_func_array([$this, $name], $args);
39
+		$hookName = (new ReflectionClass($this))->getShortName();
40
+		$hookName = str_replace('Defaults', '', $hookName);
41
+		$hookName = Str::dashCase($hookName);
42
+		return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
+	}
44
+
45
+	/**
46
+	 * @return array
47
+	 */
48
+	abstract protected function defaults();
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function filter(array $values = [])
54
+	{
55
+		return $this->normalize($this->merge(array_filter($values)), $values);
56
+	}
57
+
58
+	/**
59
+	 * @return string
60
+	 */
61
+	protected function filteredJson(array $values = [])
62
+	{
63
+		$defaults = $this->flattenArray(
64
+			array_diff_key($this->defaults(), array_flip($this->guarded))
65
+		);
66
+		$values = $this->flattenArray(
67
+			shortcode_atts($defaults, $values)
68
+		);
69
+		$filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
+			return !$this->isEmpty($value);
71
+		});
72
+		return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
+	}
74
+
75
+	/**
76
+	 * @return array
77
+	 */
78
+	protected function flattenArray(array $values)
79
+	{
80
+		array_walk($values, function (&$value) {
81
+			if (!is_array($value)) {
82
+				return;
83
+			}
84
+			$value = implode(',', $value);
85
+		});
86
+		return $values;
87
+	}
88
+
89
+	/**
90
+	 * @param mixed $var
91
+	 * @return bool
92
+	 */
93
+	protected function isEmpty($var)
94
+	{
95
+		return !is_numeric($var) && !is_bool($var) && empty($var);
96
+	}
97
+
98
+	/**
99
+	 * @return array
100
+	 */
101
+	protected function mapKeys(array $args)
102
+	{
103
+		foreach ($this->mapped as $old => $new) {
104
+			if (array_key_exists($old, $args)) {
105
+				$args[$new] = $args[$old];
106
+				unset($args[$old]);
107
+			}
108
+		}
109
+		return $args;
110
+	}
111
+
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function merge(array $values = [])
116
+	{
117
+		return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
+	}
119
+
120
+	/**
121
+	 * @return array
122
+	 */
123
+	protected function normalize(array $values, array $originalValues)
124
+	{
125
+		$values['json'] = $this->filteredJson($originalValues);
126
+		return $values;
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function restrict(array $values = [])
133
+	{
134
+		return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
+	}
136
+
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function unguarded()
141
+	{
142
+		return array_diff_key($this->defaults(), array_flip($this->guarded));
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
      * @param string $name
30 30
      * @return void|array
31 31
      */
32
-    public function __call($name, array $args = [])
32
+    public function __call( $name, array $args = [] )
33 33
     {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
34
+        if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) {
35 35
             return;
36 36
         }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
37
+        $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) );
38
+        $defaults = call_user_func_array( [$this, $name], $args );
39
+        $hookName = (new ReflectionClass( $this ))->getShortName();
40
+        $hookName = str_replace( 'Defaults', '', $hookName );
41
+        $hookName = Str::dashCase( $hookName );
42
+        return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name );
43 43
     }
44 44
 
45 45
     /**
@@ -50,38 +50,38 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return array
52 52
      */
53
-    protected function filter(array $values = [])
53
+    protected function filter( array $values = [] )
54 54
     {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
55
+        return $this->normalize( $this->merge( array_filter( $values ) ), $values );
56 56
     }
57 57
 
58 58
     /**
59 59
      * @return string
60 60
      */
61
-    protected function filteredJson(array $values = [])
61
+    protected function filteredJson( array $values = [] )
62 62
     {
63 63
         $defaults = $this->flattenArray(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
64
+            array_diff_key( $this->defaults(), array_flip( $this->guarded ) )
65 65
         );
66 66
         $values = $this->flattenArray(
67
-            shortcode_atts($defaults, $values)
67
+            shortcode_atts( $defaults, $values )
68 68
         );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
69
+        $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) {
70
+            return !$this->isEmpty( $value );
71 71
         });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
72
+        return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
73 73
     }
74 74
 
75 75
     /**
76 76
      * @return array
77 77
      */
78
-    protected function flattenArray(array $values)
78
+    protected function flattenArray( array $values )
79 79
     {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
80
+        array_walk( $values, function( &$value ) {
81
+            if( !is_array( $value ) ) {
82 82
                 return;
83 83
             }
84
-            $value = implode(',', $value);
84
+            $value = implode( ',', $value );
85 85
         });
86 86
         return $values;
87 87
     }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
      * @param mixed $var
91 91
      * @return bool
92 92
      */
93
-    protected function isEmpty($var)
93
+    protected function isEmpty( $var )
94 94
     {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
95
+        return !is_numeric( $var ) && !is_bool( $var ) && empty($var);
96 96
     }
97 97
 
98 98
     /**
99 99
      * @return array
100 100
      */
101
-    protected function mapKeys(array $args)
101
+    protected function mapKeys( array $args )
102 102
     {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
103
+        foreach( $this->mapped as $old => $new ) {
104
+            if( array_key_exists( $old, $args ) ) {
105 105
                 $args[$new] = $args[$old];
106 106
                 unset($args[$old]);
107 107
             }
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return array
114 114
      */
115
-    protected function merge(array $values = [])
115
+    protected function merge( array $values = [] )
116 116
     {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
117
+        return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values );
118 118
     }
119 119
 
120 120
     /**
121 121
      * @return array
122 122
      */
123
-    protected function normalize(array $values, array $originalValues)
123
+    protected function normalize( array $values, array $originalValues )
124 124
     {
125
-        $values['json'] = $this->filteredJson($originalValues);
125
+        $values['json'] = $this->filteredJson( $originalValues );
126 126
         return $values;
127 127
     }
128 128
 
129 129
     /**
130 130
      * @return array
131 131
      */
132
-    protected function restrict(array $values = [])
132
+    protected function restrict( array $values = [] )
133 133
     {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
134
+        return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values );
135 135
     }
136 136
 
137 137
     /**
@@ -139,6 +139,6 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function unguarded()
141 141
     {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
142
+        return array_diff_key( $this->defaults(), array_flip( $this->guarded ) );
143 143
     }
144 144
 }
Please login to merge, or discard this patch.
plugin/Database/ReviewManager.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -16,204 +16,204 @@
 block discarded – undo
16 16
 
17 17
 class ReviewManager
18 18
 {
19
-    /**
20
-     * @return false|Review
21
-     */
22
-    public function create(CreateReview $command)
23
-    {
24
-        $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
25
-        $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
26
-        $reviewValues = Arr::prefixArrayKeys($reviewValues);
27
-        unset($reviewValues['json']); // @todo remove the need for this
28
-        $postValues = [
29
-            'comment_status' => 'closed',
30
-            'meta_input' => $reviewValues,
31
-            'ping_status' => 'closed',
32
-            'post_content' => $reviewValues['_content'],
33
-            'post_date' => $reviewValues['_date'],
34
-            'post_date_gmt' => get_gmt_from_date($reviewValues['_date']),
35
-            'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'],
36
-            'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
37
-            'post_title' => $reviewValues['_title'],
38
-            'post_type' => Application::POST_TYPE,
39
-        ];
40
-        $postId = wp_insert_post($postValues, true);
41
-        if (is_wp_error($postId)) {
42
-            glsr_log()->error($postId->get_error_message())->debug($postValues);
43
-            return false;
44
-        }
45
-        $this->setTerms($postId, $command->category);
46
-        $review = $this->single(get_post($postId));
47
-        do_action('site-reviews/review/created', $review, $command);
48
-        return $review;
49
-    }
19
+	/**
20
+	 * @return false|Review
21
+	 */
22
+	public function create(CreateReview $command)
23
+	{
24
+		$reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
25
+		$reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
26
+		$reviewValues = Arr::prefixArrayKeys($reviewValues);
27
+		unset($reviewValues['json']); // @todo remove the need for this
28
+		$postValues = [
29
+			'comment_status' => 'closed',
30
+			'meta_input' => $reviewValues,
31
+			'ping_status' => 'closed',
32
+			'post_content' => $reviewValues['_content'],
33
+			'post_date' => $reviewValues['_date'],
34
+			'post_date_gmt' => get_gmt_from_date($reviewValues['_date']),
35
+			'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'],
36
+			'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
37
+			'post_title' => $reviewValues['_title'],
38
+			'post_type' => Application::POST_TYPE,
39
+		];
40
+		$postId = wp_insert_post($postValues, true);
41
+		if (is_wp_error($postId)) {
42
+			glsr_log()->error($postId->get_error_message())->debug($postValues);
43
+			return false;
44
+		}
45
+		$this->setTerms($postId, $command->category);
46
+		$review = $this->single(get_post($postId));
47
+		do_action('site-reviews/review/created', $review, $command);
48
+		return $review;
49
+	}
50 50
 
51
-    /**
52
-     * @param string $metaReviewId
53
-     * @return void
54
-     */
55
-    public function delete($metaReviewId)
56
-    {
57
-        if ($postId = $this->getPostId($metaReviewId)) {
58
-            wp_delete_post($postId, true);
59
-        }
60
-    }
51
+	/**
52
+	 * @param string $metaReviewId
53
+	 * @return void
54
+	 */
55
+	public function delete($metaReviewId)
56
+	{
57
+		if ($postId = $this->getPostId($metaReviewId)) {
58
+			wp_delete_post($postId, true);
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @return object
64
-     */
65
-    public function get(array $args = [])
66
-    {
67
-        $args = glsr(ReviewsDefaults::class)->merge($args);
68
-        $metaQuery = glsr(QueryBuilder::class)->buildQuery(
69
-            ['assigned_to', 'email', 'ip_address', 'type', 'rating'],
70
-            $args
71
-        );
72
-        $taxQuery = glsr(QueryBuilder::class)->buildQuery(
73
-            ['category'],
74
-            ['category' => $this->normalizeTermIds($args['category'])]
75
-        );
76
-        $paged = glsr(QueryBuilder::class)->getPaged(
77
-            wp_validate_boolean($args['pagination'])
78
-        );
79
-        $parameters = [
80
-            'meta_key' => '_pinned',
81
-            'meta_query' => $metaQuery,
82
-            'offset' => $args['offset'],
83
-            'order' => $args['order'],
84
-            'orderby' => 'meta_value '.$args['orderby'],
85
-            'paged' => Arr::get($args, 'paged', $paged),
86
-            'post__in' => $args['post__in'],
87
-            'post__not_in' => $args['post__not_in'],
88
-            'post_status' => 'publish',
89
-            'post_type' => Application::POST_TYPE,
90
-            'posts_per_page' => $args['per_page'],
91
-            'tax_query' => $taxQuery,
92
-        ];
93
-        $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
94
-        $query = new WP_Query($parameters);
95
-        $results = array_map([$this, 'single'], $query->posts);
96
-        $reviews = new Reviews($results, $query->max_num_pages, $args);
97
-        return apply_filters('site-reviews/get/reviews', $reviews, $query);
98
-    }
62
+	/**
63
+	 * @return object
64
+	 */
65
+	public function get(array $args = [])
66
+	{
67
+		$args = glsr(ReviewsDefaults::class)->merge($args);
68
+		$metaQuery = glsr(QueryBuilder::class)->buildQuery(
69
+			['assigned_to', 'email', 'ip_address', 'type', 'rating'],
70
+			$args
71
+		);
72
+		$taxQuery = glsr(QueryBuilder::class)->buildQuery(
73
+			['category'],
74
+			['category' => $this->normalizeTermIds($args['category'])]
75
+		);
76
+		$paged = glsr(QueryBuilder::class)->getPaged(
77
+			wp_validate_boolean($args['pagination'])
78
+		);
79
+		$parameters = [
80
+			'meta_key' => '_pinned',
81
+			'meta_query' => $metaQuery,
82
+			'offset' => $args['offset'],
83
+			'order' => $args['order'],
84
+			'orderby' => 'meta_value '.$args['orderby'],
85
+			'paged' => Arr::get($args, 'paged', $paged),
86
+			'post__in' => $args['post__in'],
87
+			'post__not_in' => $args['post__not_in'],
88
+			'post_status' => 'publish',
89
+			'post_type' => Application::POST_TYPE,
90
+			'posts_per_page' => $args['per_page'],
91
+			'tax_query' => $taxQuery,
92
+		];
93
+		$parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
94
+		$query = new WP_Query($parameters);
95
+		$results = array_map([$this, 'single'], $query->posts);
96
+		$reviews = new Reviews($results, $query->max_num_pages, $args);
97
+		return apply_filters('site-reviews/get/reviews', $reviews, $query);
98
+	}
99 99
 
100
-    /**
101
-     * @param string $metaReviewId
102
-     * @return int
103
-     */
104
-    public function getPostId($metaReviewId)
105
-    {
106
-        return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
107
-    }
100
+	/**
101
+	 * @param string $metaReviewId
102
+	 * @return int
103
+	 */
104
+	public function getPostId($metaReviewId)
105
+	{
106
+		return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
107
+	}
108 108
 
109
-    /**
110
-     * @return array
111
-     */
112
-    public function getRatingCounts(array $args = [])
113
-    {
114
-        $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
115
-        $counts = glsr(CountsManager::class)->get([
116
-            'post_ids' => Arr::convertStringToArray($args['assigned_to']),
117
-            'term_ids' => $this->normalizeTermIds($args['category']),
118
-            'type' => $args['type'],
119
-        ]);
120
-        return glsr(CountsManager::class)->flatten($counts, [
121
-            'min' => $args['rating'],
122
-        ]);
123
-    }
109
+	/**
110
+	 * @return array
111
+	 */
112
+	public function getRatingCounts(array $args = [])
113
+	{
114
+		$args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
115
+		$counts = glsr(CountsManager::class)->get([
116
+			'post_ids' => Arr::convertStringToArray($args['assigned_to']),
117
+			'term_ids' => $this->normalizeTermIds($args['category']),
118
+			'type' => $args['type'],
119
+		]);
120
+		return glsr(CountsManager::class)->flatten($counts, [
121
+			'min' => $args['rating'],
122
+		]);
123
+	}
124 124
 
125
-    /**
126
-     * @param string $commaSeparatedTermIds
127
-     * @return array
128
-     */
129
-    public function normalizeTermIds($commaSeparatedTermIds)
130
-    {
131
-        $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
132
-        return array_unique(array_map('intval', $termIds));
133
-    }
125
+	/**
126
+	 * @param string $commaSeparatedTermIds
127
+	 * @return array
128
+	 */
129
+	public function normalizeTermIds($commaSeparatedTermIds)
130
+	{
131
+		$termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
132
+		return array_unique(array_map('intval', $termIds));
133
+	}
134 134
 
135
-    /**
136
-     * @param string $commaSeparatedTermIds
137
-     * @return array
138
-     */
139
-    public function normalizeTerms($commaSeparatedTermIds)
140
-    {
141
-        $terms = [];
142
-        $termIds = Arr::convertStringToArray($commaSeparatedTermIds);
143
-        foreach ($termIds as $termId) {
144
-            if (is_numeric($termId)) {
145
-                $termId = intval($termId);
146
-            }
147
-            $term = term_exists($termId, Application::TAXONOMY);
148
-            if (!isset($term['term_id'])) {
149
-                continue;
150
-            }
151
-            $terms[] = $term;
152
-        }
153
-        return $terms;
154
-    }
135
+	/**
136
+	 * @param string $commaSeparatedTermIds
137
+	 * @return array
138
+	 */
139
+	public function normalizeTerms($commaSeparatedTermIds)
140
+	{
141
+		$terms = [];
142
+		$termIds = Arr::convertStringToArray($commaSeparatedTermIds);
143
+		foreach ($termIds as $termId) {
144
+			if (is_numeric($termId)) {
145
+				$termId = intval($termId);
146
+			}
147
+			$term = term_exists($termId, Application::TAXONOMY);
148
+			if (!isset($term['term_id'])) {
149
+				continue;
150
+			}
151
+			$terms[] = $term;
152
+		}
153
+		return $terms;
154
+	}
155 155
 
156
-    /**
157
-     * @param int $postId
158
-     * @return void
159
-     */
160
-    public function revert($postId)
161
-    {
162
-        if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
163
-            return;
164
-        }
165
-        delete_post_meta($postId, '_edit_last');
166
-        $result = wp_update_post([
167
-            'ID' => $postId,
168
-            'post_content' => glsr(Database::class)->get($postId, 'content'),
169
-            'post_date' => glsr(Database::class)->get($postId, 'date'),
170
-            'post_title' => glsr(Database::class)->get($postId, 'title'),
171
-        ]);
172
-        if (is_wp_error($result)) {
173
-            glsr_log()->error($result->get_error_message());
174
-            return;
175
-        }
176
-        do_action('site-reviews/review/reverted', glsr_get_review($postId));
177
-    }
156
+	/**
157
+	 * @param int $postId
158
+	 * @return void
159
+	 */
160
+	public function revert($postId)
161
+	{
162
+		if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
163
+			return;
164
+		}
165
+		delete_post_meta($postId, '_edit_last');
166
+		$result = wp_update_post([
167
+			'ID' => $postId,
168
+			'post_content' => glsr(Database::class)->get($postId, 'content'),
169
+			'post_date' => glsr(Database::class)->get($postId, 'date'),
170
+			'post_title' => glsr(Database::class)->get($postId, 'title'),
171
+		]);
172
+		if (is_wp_error($result)) {
173
+			glsr_log()->error($result->get_error_message());
174
+			return;
175
+		}
176
+		do_action('site-reviews/review/reverted', glsr_get_review($postId));
177
+	}
178 178
 
179
-    /**
180
-     * @return Review
181
-     */
182
-    public function single(WP_Post $post)
183
-    {
184
-        if (Application::POST_TYPE != $post->post_type) {
185
-            $post = new WP_Post((object) []);
186
-        }
187
-        $review = new Review($post);
188
-        return apply_filters('site-reviews/get/review', $review, $post);
189
-    }
179
+	/**
180
+	 * @return Review
181
+	 */
182
+	public function single(WP_Post $post)
183
+	{
184
+		if (Application::POST_TYPE != $post->post_type) {
185
+			$post = new WP_Post((object) []);
186
+		}
187
+		$review = new Review($post);
188
+		return apply_filters('site-reviews/get/review', $review, $post);
189
+	}
190 190
 
191
-    /**
192
-     * @param bool $isBlacklisted
193
-     * @return string
194
-     */
195
-    protected function getNewPostStatus(array $reviewValues, $isBlacklisted)
196
-    {
197
-        $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
198
-        return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted)
199
-            ? 'pending'
200
-            : 'publish';
201
-    }
191
+	/**
192
+	 * @param bool $isBlacklisted
193
+	 * @return string
194
+	 */
195
+	protected function getNewPostStatus(array $reviewValues, $isBlacklisted)
196
+	{
197
+		$requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
198
+		return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted)
199
+			? 'pending'
200
+			: 'publish';
201
+	}
202 202
 
203
-    /**
204
-     * @param int $postId
205
-     * @param string $termIds
206
-     * @return void
207
-     */
208
-    protected function setTerms($postId, $termIds)
209
-    {
210
-        $termIds = $this->normalizeTermIds($termIds);
211
-        if (empty($termIds)) {
212
-            return;
213
-        }
214
-        $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
215
-        if (is_wp_error($termTaxonomyIds)) {
216
-            glsr_log()->error($termTaxonomyIds->get_error_message());
217
-        }
218
-    }
203
+	/**
204
+	 * @param int $postId
205
+	 * @param string $termIds
206
+	 * @return void
207
+	 */
208
+	protected function setTerms($postId, $termIds)
209
+	{
210
+		$termIds = $this->normalizeTermIds($termIds);
211
+		if (empty($termIds)) {
212
+			return;
213
+		}
214
+		$termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
215
+		if (is_wp_error($termTaxonomyIds)) {
216
+			glsr_log()->error($termTaxonomyIds->get_error_message());
217
+		}
218
+	}
219 219
 }
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * @return false|Review
21 21
      */
22
-    public function create(CreateReview $command)
22
+    public function create( CreateReview $command )
23 23
     {
24
-        $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
25
-        $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
26
-        $reviewValues = Arr::prefixArrayKeys($reviewValues);
24
+        $reviewValues = glsr( CreateReviewDefaults::class )->restrict( (array)$command );
25
+        $reviewValues = apply_filters( 'site-reviews/create/review-values', $reviewValues, $command );
26
+        $reviewValues = Arr::prefixArrayKeys( $reviewValues );
27 27
         unset($reviewValues['json']); // @todo remove the need for this
28 28
         $postValues = [
29 29
             'comment_status' => 'closed',
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
             'ping_status' => 'closed',
32 32
             'post_content' => $reviewValues['_content'],
33 33
             'post_date' => $reviewValues['_date'],
34
-            'post_date_gmt' => get_gmt_from_date($reviewValues['_date']),
34
+            'post_date_gmt' => get_gmt_from_date( $reviewValues['_date'] ),
35 35
             'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'],
36
-            'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
36
+            'post_status' => $this->getNewPostStatus( $reviewValues, $command->blacklisted ),
37 37
             'post_title' => $reviewValues['_title'],
38 38
             'post_type' => Application::POST_TYPE,
39 39
         ];
40
-        $postId = wp_insert_post($postValues, true);
41
-        if (is_wp_error($postId)) {
42
-            glsr_log()->error($postId->get_error_message())->debug($postValues);
40
+        $postId = wp_insert_post( $postValues, true );
41
+        if( is_wp_error( $postId ) ) {
42
+            glsr_log()->error( $postId->get_error_message() )->debug( $postValues );
43 43
             return false;
44 44
         }
45
-        $this->setTerms($postId, $command->category);
46
-        $review = $this->single(get_post($postId));
47
-        do_action('site-reviews/review/created', $review, $command);
45
+        $this->setTerms( $postId, $command->category );
46
+        $review = $this->single( get_post( $postId ) );
47
+        do_action( 'site-reviews/review/created', $review, $command );
48 48
         return $review;
49 49
     }
50 50
 
@@ -52,29 +52,29 @@  discard block
 block discarded – undo
52 52
      * @param string $metaReviewId
53 53
      * @return void
54 54
      */
55
-    public function delete($metaReviewId)
55
+    public function delete( $metaReviewId )
56 56
     {
57
-        if ($postId = $this->getPostId($metaReviewId)) {
58
-            wp_delete_post($postId, true);
57
+        if( $postId = $this->getPostId( $metaReviewId ) ) {
58
+            wp_delete_post( $postId, true );
59 59
         }
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return object
64 64
      */
65
-    public function get(array $args = [])
65
+    public function get( array $args = [] )
66 66
     {
67
-        $args = glsr(ReviewsDefaults::class)->merge($args);
68
-        $metaQuery = glsr(QueryBuilder::class)->buildQuery(
67
+        $args = glsr( ReviewsDefaults::class )->merge( $args );
68
+        $metaQuery = glsr( QueryBuilder::class )->buildQuery(
69 69
             ['assigned_to', 'email', 'ip_address', 'type', 'rating'],
70 70
             $args
71 71
         );
72
-        $taxQuery = glsr(QueryBuilder::class)->buildQuery(
72
+        $taxQuery = glsr( QueryBuilder::class )->buildQuery(
73 73
             ['category'],
74
-            ['category' => $this->normalizeTermIds($args['category'])]
74
+            ['category' => $this->normalizeTermIds( $args['category'] )]
75 75
         );
76
-        $paged = glsr(QueryBuilder::class)->getPaged(
77
-            wp_validate_boolean($args['pagination'])
76
+        $paged = glsr( QueryBuilder::class )->getPaged(
77
+            wp_validate_boolean( $args['pagination'] )
78 78
         );
79 79
         $parameters = [
80 80
             'meta_key' => '_pinned',
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             'offset' => $args['offset'],
83 83
             'order' => $args['order'],
84 84
             'orderby' => 'meta_value '.$args['orderby'],
85
-            'paged' => Arr::get($args, 'paged', $paged),
85
+            'paged' => Arr::get( $args, 'paged', $paged ),
86 86
             'post__in' => $args['post__in'],
87 87
             'post__not_in' => $args['post__not_in'],
88 88
             'post_status' => 'publish',
@@ -90,62 +90,62 @@  discard block
 block discarded – undo
90 90
             'posts_per_page' => $args['per_page'],
91 91
             'tax_query' => $taxQuery,
92 92
         ];
93
-        $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
94
-        $query = new WP_Query($parameters);
95
-        $results = array_map([$this, 'single'], $query->posts);
96
-        $reviews = new Reviews($results, $query->max_num_pages, $args);
97
-        return apply_filters('site-reviews/get/reviews', $reviews, $query);
93
+        $parameters = apply_filters( 'site-reviews/get/reviews/query', $parameters, $args );
94
+        $query = new WP_Query( $parameters );
95
+        $results = array_map( [$this, 'single'], $query->posts );
96
+        $reviews = new Reviews( $results, $query->max_num_pages, $args );
97
+        return apply_filters( 'site-reviews/get/reviews', $reviews, $query );
98 98
     }
99 99
 
100 100
     /**
101 101
      * @param string $metaReviewId
102 102
      * @return int
103 103
      */
104
-    public function getPostId($metaReviewId)
104
+    public function getPostId( $metaReviewId )
105 105
     {
106
-        return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
106
+        return glsr( SqlQueries::class )->getPostIdFromReviewId( $metaReviewId );
107 107
     }
108 108
 
109 109
     /**
110 110
      * @return array
111 111
      */
112
-    public function getRatingCounts(array $args = [])
112
+    public function getRatingCounts( array $args = [] )
113 113
     {
114
-        $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
115
-        $counts = glsr(CountsManager::class)->get([
116
-            'post_ids' => Arr::convertStringToArray($args['assigned_to']),
117
-            'term_ids' => $this->normalizeTermIds($args['category']),
114
+        $args = glsr( SiteReviewsSummaryDefaults::class )->filter( $args );
115
+        $counts = glsr( CountsManager::class )->get( [
116
+            'post_ids' => Arr::convertStringToArray( $args['assigned_to'] ),
117
+            'term_ids' => $this->normalizeTermIds( $args['category'] ),
118 118
             'type' => $args['type'],
119
-        ]);
120
-        return glsr(CountsManager::class)->flatten($counts, [
119
+        ] );
120
+        return glsr( CountsManager::class )->flatten( $counts, [
121 121
             'min' => $args['rating'],
122
-        ]);
122
+        ] );
123 123
     }
124 124
 
125 125
     /**
126 126
      * @param string $commaSeparatedTermIds
127 127
      * @return array
128 128
      */
129
-    public function normalizeTermIds($commaSeparatedTermIds)
129
+    public function normalizeTermIds( $commaSeparatedTermIds )
130 130
     {
131
-        $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
132
-        return array_unique(array_map('intval', $termIds));
131
+        $termIds = glsr_array_column( $this->normalizeTerms( $commaSeparatedTermIds ), 'term_id' );
132
+        return array_unique( array_map( 'intval', $termIds ) );
133 133
     }
134 134
 
135 135
     /**
136 136
      * @param string $commaSeparatedTermIds
137 137
      * @return array
138 138
      */
139
-    public function normalizeTerms($commaSeparatedTermIds)
139
+    public function normalizeTerms( $commaSeparatedTermIds )
140 140
     {
141 141
         $terms = [];
142
-        $termIds = Arr::convertStringToArray($commaSeparatedTermIds);
143
-        foreach ($termIds as $termId) {
144
-            if (is_numeric($termId)) {
145
-                $termId = intval($termId);
142
+        $termIds = Arr::convertStringToArray( $commaSeparatedTermIds );
143
+        foreach( $termIds as $termId ) {
144
+            if( is_numeric( $termId ) ) {
145
+                $termId = intval( $termId );
146 146
             }
147
-            $term = term_exists($termId, Application::TAXONOMY);
148
-            if (!isset($term['term_id'])) {
147
+            $term = term_exists( $termId, Application::TAXONOMY );
148
+            if( !isset($term['term_id']) ) {
149 149
                 continue;
150 150
             }
151 151
             $terms[] = $term;
@@ -157,44 +157,44 @@  discard block
 block discarded – undo
157 157
      * @param int $postId
158 158
      * @return void
159 159
      */
160
-    public function revert($postId)
160
+    public function revert( $postId )
161 161
     {
162
-        if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
162
+        if( Application::POST_TYPE != get_post_field( 'post_type', $postId ) ) {
163 163
             return;
164 164
         }
165
-        delete_post_meta($postId, '_edit_last');
166
-        $result = wp_update_post([
165
+        delete_post_meta( $postId, '_edit_last' );
166
+        $result = wp_update_post( [
167 167
             'ID' => $postId,
168
-            'post_content' => glsr(Database::class)->get($postId, 'content'),
169
-            'post_date' => glsr(Database::class)->get($postId, 'date'),
170
-            'post_title' => glsr(Database::class)->get($postId, 'title'),
171
-        ]);
172
-        if (is_wp_error($result)) {
173
-            glsr_log()->error($result->get_error_message());
168
+            'post_content' => glsr( Database::class )->get( $postId, 'content' ),
169
+            'post_date' => glsr( Database::class )->get( $postId, 'date' ),
170
+            'post_title' => glsr( Database::class )->get( $postId, 'title' ),
171
+        ] );
172
+        if( is_wp_error( $result ) ) {
173
+            glsr_log()->error( $result->get_error_message() );
174 174
             return;
175 175
         }
176
-        do_action('site-reviews/review/reverted', glsr_get_review($postId));
176
+        do_action( 'site-reviews/review/reverted', glsr_get_review( $postId ) );
177 177
     }
178 178
 
179 179
     /**
180 180
      * @return Review
181 181
      */
182
-    public function single(WP_Post $post)
182
+    public function single( WP_Post $post )
183 183
     {
184
-        if (Application::POST_TYPE != $post->post_type) {
185
-            $post = new WP_Post((object) []);
184
+        if( Application::POST_TYPE != $post->post_type ) {
185
+            $post = new WP_Post( (object)[] );
186 186
         }
187
-        $review = new Review($post);
188
-        return apply_filters('site-reviews/get/review', $review, $post);
187
+        $review = new Review( $post );
188
+        return apply_filters( 'site-reviews/get/review', $review, $post );
189 189
     }
190 190
 
191 191
     /**
192 192
      * @param bool $isBlacklisted
193 193
      * @return string
194 194
      */
195
-    protected function getNewPostStatus(array $reviewValues, $isBlacklisted)
195
+    protected function getNewPostStatus( array $reviewValues, $isBlacklisted )
196 196
     {
197
-        $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
197
+        $requireApproval = glsr( OptionManager::class )->getBool( 'settings.general.require.approval' );
198 198
         return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted)
199 199
             ? 'pending'
200 200
             : 'publish';
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
      * @param string $termIds
206 206
      * @return void
207 207
      */
208
-    protected function setTerms($postId, $termIds)
208
+    protected function setTerms( $postId, $termIds )
209 209
     {
210
-        $termIds = $this->normalizeTermIds($termIds);
211
-        if (empty($termIds)) {
210
+        $termIds = $this->normalizeTermIds( $termIds );
211
+        if( empty($termIds) ) {
212 212
             return;
213 213
         }
214
-        $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
215
-        if (is_wp_error($termTaxonomyIds)) {
216
-            glsr_log()->error($termTaxonomyIds->get_error_message());
214
+        $termTaxonomyIds = wp_set_object_terms( $postId, $termIds, Application::TAXONOMY );
215
+        if( is_wp_error( $termTaxonomyIds ) ) {
216
+            glsr_log()->error( $termTaxonomyIds->get_error_message() );
217 217
         }
218 218
     }
219 219
 }
Please login to merge, or discard this patch.