Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
site-reviews.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -20,17 +20,17 @@
 block discarded – undo
20 20
 defined('WPINC') || die;
21 21
 
22 22
 if (!class_exists('GL_Plugin_Check_v4')) {
23
-    require_once __DIR__.'/activate.php';
23
+	require_once __DIR__.'/activate.php';
24 24
 }
25 25
 if ((new GL_Plugin_Check_v4(__FILE__))->canProceed()) {
26
-    require_once __DIR__.'/autoload.php';
27
-    require_once __DIR__.'/compatibility.php';
28
-    require_once __DIR__.'/deprecated.php';
29
-    require_once __DIR__.'/helpers.php';
30
-    $app = new GeminiLabs\SiteReviews\Application();
31
-    $app->make('Provider')->register($app);
32
-    register_activation_hook(__FILE__, array($app, 'activate'));
33
-    register_deactivation_hook(__FILE__, array($app, 'deactivate'));
34
-    register_shutdown_function(array($app, 'catchFatalError'));
35
-    $app->init();
26
+	require_once __DIR__.'/autoload.php';
27
+	require_once __DIR__.'/compatibility.php';
28
+	require_once __DIR__.'/deprecated.php';
29
+	require_once __DIR__.'/helpers.php';
30
+	$app = new GeminiLabs\SiteReviews\Application();
31
+	$app->make('Provider')->register($app);
32
+	register_activation_hook(__FILE__, array($app, 'activate'));
33
+	register_deactivation_hook(__FILE__, array($app, 'deactivate'));
34
+	register_shutdown_function(array($app, 'catchFatalError'));
35
+	$app->init();
36 36
 }
Please login to merge, or discard this patch.
plugin/Reviews.php 1 patch
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 (array_key_exists($key, $this->reviews)) {
59
-            return $this->reviews[$key];
60
-        }
61
-        return property_exists($this, $key)
62
-            ? $this->$key
63
-            : null;
64
-    }
52
+	/**
53
+	 * @param mixed $key
54
+	 * @return mixed
55
+	 */
56
+	public function offsetGet($key)
57
+	{
58
+		if (array_key_exists($key, $this->reviews)) {
59
+			return $this->reviews[$key];
60
+		}
61
+		return property_exists($this, $key)
62
+			? $this->$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.
plugin/Modules/Html/ReviewHtml.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -7,48 +7,48 @@
 block discarded – undo
7 7
 
8 8
 class ReviewHtml extends ArrayObject
9 9
 {
10
-    /**
11
-     * @var Review
12
-     */
13
-    public $review;
10
+	/**
11
+	 * @var Review
12
+	 */
13
+	public $review;
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    public $values;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	public $values;
19 19
 
20
-    public function __construct(Review $review, array $values = [])
21
-    {
22
-        $this->review = $review;
23
-        $this->values = $values;
24
-        parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
25
-    }
20
+	public function __construct(Review $review, array $values = [])
21
+	{
22
+		$this->review = $review;
23
+		$this->values = $values;
24
+		parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
25
+	}
26 26
 
27
-    /**
28
-     * @return string|void
29
-     */
30
-    public function __toString()
31
-    {
32
-        if (empty($this->values)) {
33
-            return;
34
-        }
35
-        return glsr(Template::class)->build('templates/review', [
36
-            'context' => $this->values,
37
-            'review' => $this->review,
38
-        ]);
39
-    }
27
+	/**
28
+	 * @return string|void
29
+	 */
30
+	public function __toString()
31
+	{
32
+		if (empty($this->values)) {
33
+			return;
34
+		}
35
+		return glsr(Template::class)->build('templates/review', [
36
+			'context' => $this->values,
37
+			'review' => $this->review,
38
+		]);
39
+	}
40 40
 
41
-    /**
42
-     * @param mixed $key
43
-     * @return mixed
44
-     */
45
-    public function offsetGet($key)
46
-    {
47
-        if (array_key_exists($key, $this->values)) {
48
-            return $this->values[$key];
49
-        }
50
-        return property_exists($this, $key)
51
-            ? $this->$key
52
-            : null;
53
-    }
41
+	/**
42
+	 * @param mixed $key
43
+	 * @return mixed
44
+	 */
45
+	public function offsetGet($key)
46
+	{
47
+		if (array_key_exists($key, $this->values)) {
48
+			return $this->values[$key];
49
+		}
50
+		return property_exists($this, $key)
51
+			? $this->$key
52
+			: null;
53
+	}
54 54
 }
Please login to merge, or discard this patch.
plugin/Contracts/PartialContract.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 interface PartialContract
6 6
 {
7
-    /**
8
-     * @return string
9
-     */
10
-    public function build(array $args = []);
7
+	/**
8
+	 * @return string
9
+	 */
10
+	public function build(array $args = []);
11 11
 }
Please login to merge, or discard this patch.
uninstall.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 require_once $file;
7 7
 
8 8
 if (!(new GL_Plugin_Check_v4($file))->isValid()) {
9
-    return;
9
+	return;
10 10
 }
11 11
 delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(3));
12 12
 delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(4));
Please login to merge, or discard this patch.
activate.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -8,141 +8,141 @@
 block discarded – undo
8 8
  */
9 9
 class GL_Plugin_Check_v4
10 10
 {
11
-    const MIN_PHP_VERSION = '5.6.0';
12
-    const MIN_WORDPRESS_VERSION = '4.7.0';
11
+	const MIN_PHP_VERSION = '5.6.0';
12
+	const MIN_WORDPRESS_VERSION = '4.7.0';
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    public $versions;
14
+	/**
15
+	 * @var array
16
+	 */
17
+	public $versions;
18 18
 
19
-    /**
20
-     * @var string
21
-     */
22
-    protected $file;
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected $file;
23 23
 
24
-    /**
25
-     * @param string $file
26
-     */
27
-    public function __construct($file)
28
-    {
29
-        $this->file = realpath($file);
30
-        $versionRequirements = get_file_data($this->file, [
31
-            'php' => 'Requires PHP',
32
-            'wordpress' => 'Requires at least',
33
-        ]);
34
-        $this->versions = wp_parse_args(array_filter($versionRequirements), [
35
-            'php' => static::MIN_PHP_VERSION,
36
-            'wordpress' => static::MIN_WORDPRESS_VERSION,
37
-        ]);
38
-    }
24
+	/**
25
+	 * @param string $file
26
+	 */
27
+	public function __construct($file)
28
+	{
29
+		$this->file = realpath($file);
30
+		$versionRequirements = get_file_data($this->file, [
31
+			'php' => 'Requires PHP',
32
+			'wordpress' => 'Requires at least',
33
+		]);
34
+		$this->versions = wp_parse_args(array_filter($versionRequirements), [
35
+			'php' => static::MIN_PHP_VERSION,
36
+			'wordpress' => static::MIN_WORDPRESS_VERSION,
37
+		]);
38
+	}
39 39
 
40
-    /**
41
-     * @return bool
42
-     */
43
-    public function canProceed()
44
-    {
45
-        if ($this->isValid()) {
46
-            return true;
47
-        }
48
-        add_action('activated_plugin', [$this, 'deactivate']);
49
-        add_action('admin_notices', [$this, 'deactivate']);
50
-        return false;
51
-    }
40
+	/**
41
+	 * @return bool
42
+	 */
43
+	public function canProceed()
44
+	{
45
+		if ($this->isValid()) {
46
+			return true;
47
+		}
48
+		add_action('activated_plugin', [$this, 'deactivate']);
49
+		add_action('admin_notices', [$this, 'deactivate']);
50
+		return false;
51
+	}
52 52
 
53
-    /**
54
-     * @return bool
55
-     */
56
-    public function isPhpValid()
57
-    {
58
-        return !version_compare(PHP_VERSION, $this->versions['php'], '<');
59
-    }
53
+	/**
54
+	 * @return bool
55
+	 */
56
+	public function isPhpValid()
57
+	{
58
+		return !version_compare(PHP_VERSION, $this->versions['php'], '<');
59
+	}
60 60
 
61
-    /**
62
-     * @return bool
63
-     */
64
-    public function isValid()
65
-    {
66
-        return $this->isPhpValid() && $this->isWpValid();
67
-    }
61
+	/**
62
+	 * @return bool
63
+	 */
64
+	public function isValid()
65
+	{
66
+		return $this->isPhpValid() && $this->isWpValid();
67
+	}
68 68
 
69
-    /**
70
-     * @return bool
71
-     */
72
-    public function isWpValid()
73
-    {
74
-        global $wp_version;
75
-        return !version_compare($wp_version, $this->versions['wordpress'], '<');
76
-    }
69
+	/**
70
+	 * @return bool
71
+	 */
72
+	public function isWpValid()
73
+	{
74
+		global $wp_version;
75
+		return !version_compare($wp_version, $this->versions['wordpress'], '<');
76
+	}
77 77
 
78
-    /**
79
-     * @param string $plugin
80
-     * @return void
81
-     */
82
-    public function deactivate($plugin)
83
-    {
84
-        if ($this->isValid()) {
85
-            return;
86
-        }
87
-        $pluginSlug = plugin_basename($this->file);
88
-        if ($plugin == $pluginSlug) {
89
-            $this->redirect(); //exit
90
-        }
91
-        $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin');
92
-        deactivate_plugins($pluginSlug);
93
-        $this->printNotice($pluginData['name']);
94
-    }
78
+	/**
79
+	 * @param string $plugin
80
+	 * @return void
81
+	 */
82
+	public function deactivate($plugin)
83
+	{
84
+		if ($this->isValid()) {
85
+			return;
86
+		}
87
+		$pluginSlug = plugin_basename($this->file);
88
+		if ($plugin == $pluginSlug) {
89
+			$this->redirect(); //exit
90
+		}
91
+		$pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin');
92
+		deactivate_plugins($pluginSlug);
93
+		$this->printNotice($pluginData['name']);
94
+	}
95 95
 
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getMessages()
100
-    {
101
-        return [
102
-            'notice' => __('The %s plugin was deactivated.', 'site-reviews'),
103
-            'php_version' => __('PHP version', 'site-reviews'),
104
-            'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
-            'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
106
-            'update_wp' => __('Update WordPress', 'site-reviews'),
107
-            'wp_version' => __('WordPress version', 'site-reviews'),
108
-            'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
109
-        ];
110
-    }
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getMessages()
100
+	{
101
+		return [
102
+			'notice' => __('The %s plugin was deactivated.', 'site-reviews'),
103
+			'php_version' => __('PHP version', 'site-reviews'),
104
+			'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
+			'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
106
+			'update_wp' => __('Update WordPress', 'site-reviews'),
107
+			'wp_version' => __('WordPress version', 'site-reviews'),
108
+			'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
109
+		];
110
+	}
111 111
 
112
-    /**
113
-     * @param string $pluginName
114
-     * @return void
115
-     */
116
-    protected function printNotice($pluginName)
117
-    {
118
-        $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
119
-        $messages = $this->getMessages();
120
-        $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
121
-        if (!$this->isPhpValid()) {
122
-            printf($noticeTemplate,
123
-                sprintf($messages['notice'], $pluginName),
124
-                sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']),
125
-                sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage
126
-            );
127
-        } elseif (!$this->isWpValid()) {
128
-            printf($noticeTemplate,
129
-                sprintf($messages['notice'], $pluginName),
130
-                sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']),
131
-                $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp'])
132
-            );
133
-        }
134
-    }
112
+	/**
113
+	 * @param string $pluginName
114
+	 * @return void
115
+	 */
116
+	protected function printNotice($pluginName)
117
+	{
118
+		$noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
119
+		$messages = $this->getMessages();
120
+		$rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
121
+		if (!$this->isPhpValid()) {
122
+			printf($noticeTemplate,
123
+				sprintf($messages['notice'], $pluginName),
124
+				sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']),
125
+				sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage
126
+			);
127
+		} elseif (!$this->isWpValid()) {
128
+			printf($noticeTemplate,
129
+				sprintf($messages['notice'], $pluginName),
130
+				sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']),
131
+				$rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp'])
132
+			);
133
+		}
134
+	}
135 135
 
136
-    /**
137
-     * @return void
138
-     */
139
-    protected function redirect()
140
-    {
141
-        wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
142
-            filter_input(INPUT_GET, 'plugin_status'),
143
-            filter_input(INPUT_GET, 'paged'),
144
-            filter_input(INPUT_GET, 's')
145
-        )));
146
-        exit;
147
-    }
136
+	/**
137
+	 * @return void
138
+	 */
139
+	protected function redirect()
140
+	{
141
+		wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
142
+			filter_input(INPUT_GET, 'plugin_status'),
143
+			filter_input(INPUT_GET, 'paged'),
144
+			filter_input(INPUT_GET, 's')
145
+		)));
146
+		exit;
147
+	}
148 148
 }
Please login to merge, or discard this patch.
plugin/Database/GlobalCountsManager.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,73 +7,73 @@
 block discarded – undo
7 7
 
8 8
 class GlobalCountsManager
9 9
 {
10
-    /**
11
-     * @var CountsManager
12
-     */
13
-    protected $manager;
10
+	/**
11
+	 * @var CountsManager
12
+	 */
13
+	protected $manager;
14 14
 
15
-    public function __construct()
16
-    {
17
-        $this->manager = glsr(CountsManager::class);
18
-    }
15
+	public function __construct()
16
+	{
17
+		$this->manager = glsr(CountsManager::class);
18
+	}
19 19
 
20
-    /**
21
-     * @return array
22
-     */
23
-    public function build()
24
-    {
25
-        return $this->manager->buildCounts();
26
-    }
20
+	/**
21
+	 * @return array
22
+	 */
23
+	public function build()
24
+	{
25
+		return $this->manager->buildCounts();
26
+	}
27 27
 
28
-    /**
29
-     * @return void
30
-     */
31
-    public function decrease(Review $review)
32
-    {
33
-        $this->update($this->manager->decreaseRating(
34
-            $this->get(),
35
-            $review->review_type,
36
-            $review->rating
37
-        ));
38
-    }
28
+	/**
29
+	 * @return void
30
+	 */
31
+	public function decrease(Review $review)
32
+	{
33
+		$this->update($this->manager->decreaseRating(
34
+			$this->get(),
35
+			$review->review_type,
36
+			$review->rating
37
+		));
38
+	}
39 39
 
40
-    /**
41
-     * @return array
42
-     */
43
-    public function get()
44
-    {
45
-        $counts = glsr(OptionManager::class)->get('counts', []);
46
-        if (!is_array($counts)) {
47
-            glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
48
-            return [];
49
-        }
50
-        return $counts;
51
-    }
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function get()
44
+	{
45
+		$counts = glsr(OptionManager::class)->get('counts', []);
46
+		if (!is_array($counts)) {
47
+			glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
48
+			return [];
49
+		}
50
+		return $counts;
51
+	}
52 52
 
53
-    /**
54
-     * @return void
55
-     */
56
-    public function increase(Review $review)
57
-    {
58
-        if (empty($counts = $this->get())) {
59
-            $counts = $this->build();
60
-        }
61
-        $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating));
62
-    }
53
+	/**
54
+	 * @return void
55
+	 */
56
+	public function increase(Review $review)
57
+	{
58
+		if (empty($counts = $this->get())) {
59
+			$counts = $this->build();
60
+		}
61
+		$this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating));
62
+	}
63 63
 
64
-    /**
65
-     * @return void
66
-     */
67
-    public function update(array $reviewCounts)
68
-    {
69
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
70
-    }
64
+	/**
65
+	 * @return void
66
+	 */
67
+	public function update(array $reviewCounts)
68
+	{
69
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
70
+	}
71 71
 
72
-    /**
73
-     * @return void
74
-     */
75
-    public function updateAll()
76
-    {
77
-        $this->update($this->build());
78
-    }
72
+	/**
73
+	 * @return void
74
+	 */
75
+	public function updateAll()
76
+	{
77
+		$this->update($this->build());
78
+	}
79 79
 }
Please login to merge, or discard this patch.
plugin/Controllers/ReviewController.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -16,159 +16,159 @@
 block discarded – undo
16 16
 
17 17
 class ReviewController extends Controller
18 18
 {
19
-    /**
20
-     * Triggered when a category is added to a review.
21
-     *
22
-     * @param int $postId
23
-     * @param array $terms
24
-     * @param array $newTTIds
25
-     * @param string $taxonomy
26
-     * @param bool $append
27
-     * @param array $oldTTIds
28
-     * @return void
29
-     * @action set_object_terms
30
-     */
31
-    public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
32
-    {
33
-        sort($newTTIds);
34
-        sort($oldTTIds);
35
-        if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) {
36
-            return;
37
-        }
38
-        $review = glsr_get_review($postId);
39
-        if ('publish' !== $review->status) {
40
-            return;
41
-        }
42
-        $ignoredIds = array_intersect($oldTTIds, $newTTIds);
43
-        $decreasedIds = array_diff($oldTTIds, $ignoredIds);
44
-        $increasedIds = array_diff($newTTIds, $ignoredIds);
45
-        if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) {
46
-            glsr(TermCountsManager::class)->decrease($review);
47
-        }
48
-        if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) {
49
-            glsr(TermCountsManager::class)->increase($review);
50
-        }
51
-    }
19
+	/**
20
+	 * Triggered when a category is added to a review.
21
+	 *
22
+	 * @param int $postId
23
+	 * @param array $terms
24
+	 * @param array $newTTIds
25
+	 * @param string $taxonomy
26
+	 * @param bool $append
27
+	 * @param array $oldTTIds
28
+	 * @return void
29
+	 * @action set_object_terms
30
+	 */
31
+	public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
32
+	{
33
+		sort($newTTIds);
34
+		sort($oldTTIds);
35
+		if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) {
36
+			return;
37
+		}
38
+		$review = glsr_get_review($postId);
39
+		if ('publish' !== $review->status) {
40
+			return;
41
+		}
42
+		$ignoredIds = array_intersect($oldTTIds, $newTTIds);
43
+		$decreasedIds = array_diff($oldTTIds, $ignoredIds);
44
+		$increasedIds = array_diff($newTTIds, $ignoredIds);
45
+		if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) {
46
+			glsr(TermCountsManager::class)->decrease($review);
47
+		}
48
+		if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) {
49
+			glsr(TermCountsManager::class)->increase($review);
50
+		}
51
+	}
52 52
 
53
-    /**
54
-     * Triggered when an existing review is approved|unapproved.
55
-     *
56
-     * @param string $oldStatus
57
-     * @param string $newStatus
58
-     * @param \WP_Post $post
59
-     * @return void
60
-     * @action transition_post_status
61
-     */
62
-    public function onAfterChangeStatus($newStatus, $oldStatus, $post)
63
-    {
64
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') 
65
-            || in_array($oldStatus, ['new', $newStatus])) {
66
-            return;
67
-        }
68
-        $review = glsr_get_review($post);
69
-        if ('publish' == $post->post_status) {
70
-            glsr(CountsManager::class)->increaseAll($review);
71
-        } else {
72
-            glsr(CountsManager::class)->decreaseAll($review);
73
-        }
74
-    }
53
+	/**
54
+	 * Triggered when an existing review is approved|unapproved.
55
+	 *
56
+	 * @param string $oldStatus
57
+	 * @param string $newStatus
58
+	 * @param \WP_Post $post
59
+	 * @return void
60
+	 * @action transition_post_status
61
+	 */
62
+	public function onAfterChangeStatus($newStatus, $oldStatus, $post)
63
+	{
64
+		if (Application::POST_TYPE != Arr::get($post, 'post_type') 
65
+			|| in_array($oldStatus, ['new', $newStatus])) {
66
+			return;
67
+		}
68
+		$review = glsr_get_review($post);
69
+		if ('publish' == $post->post_status) {
70
+			glsr(CountsManager::class)->increaseAll($review);
71
+		} else {
72
+			glsr(CountsManager::class)->decreaseAll($review);
73
+		}
74
+	}
75 75
 
76
-    /**
77
-     * Triggered when a review is first created.
78
-     *
79
-     * @return void
80
-     * @action site-reviews/review/created
81
-     */
82
-    public function onAfterCreate(Review $review)
83
-    {
84
-        if ('publish' !== $review->status) {
85
-            return;
86
-        }
87
-        glsr(GlobalCountsManager::class)->increase($review);
88
-        glsr(PostCountsManager::class)->increase($review);
89
-    }
76
+	/**
77
+	 * Triggered when a review is first created.
78
+	 *
79
+	 * @return void
80
+	 * @action site-reviews/review/created
81
+	 */
82
+	public function onAfterCreate(Review $review)
83
+	{
84
+		if ('publish' !== $review->status) {
85
+			return;
86
+		}
87
+		glsr(GlobalCountsManager::class)->increase($review);
88
+		glsr(PostCountsManager::class)->increase($review);
89
+	}
90 90
 
91
-    /**
92
-     * Triggered when a review is deleted.
93
-     *
94
-     * @param int $postId
95
-     * @return void
96
-     * @action before_delete_post
97
-     */
98
-    public function onBeforeDelete($postId)
99
-    {
100
-        if (!$this->isReviewPostId($postId)) {
101
-            return;
102
-        }
103
-        $review = glsr_get_review($postId);
104
-        if ('trash' !== $review->status) { // do not run for trashed posts
105
-            glsr(CountsManager::class)->decreaseAll($review);
106
-        }
107
-    }
91
+	/**
92
+	 * Triggered when a review is deleted.
93
+	 *
94
+	 * @param int $postId
95
+	 * @return void
96
+	 * @action before_delete_post
97
+	 */
98
+	public function onBeforeDelete($postId)
99
+	{
100
+		if (!$this->isReviewPostId($postId)) {
101
+			return;
102
+		}
103
+		$review = glsr_get_review($postId);
104
+		if ('trash' !== $review->status) { // do not run for trashed posts
105
+			glsr(CountsManager::class)->decreaseAll($review);
106
+		}
107
+	}
108 108
 
109
-    /**
110
-     * Triggered when a review's rating, assigned_to, or review_type is changed.
111
-     *
112
-     * @param int $metaId
113
-     * @param int $postId
114
-     * @param string $metaKey
115
-     * @param mixed $metaValue
116
-     * @return void
117
-     * @action update_postmeta
118
-     */
119
-    public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue)
120
-    {
121
-        if (!$this->isReviewPostId($postId)) {
122
-            return;
123
-        }
124
-        $metaKey = Str::removePrefix('_', $metaKey);
125
-        if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) {
126
-            return;
127
-        }
128
-        $review = glsr_get_review($postId);
129
-        if ($review->$metaKey == $metaValue) {
130
-            return;
131
-        }
132
-        $method = Helper::buildMethodName($metaKey, 'onBeforeChange');
133
-        call_user_func([$this, $method], $review, $metaValue);
134
-    }
109
+	/**
110
+	 * Triggered when a review's rating, assigned_to, or review_type is changed.
111
+	 *
112
+	 * @param int $metaId
113
+	 * @param int $postId
114
+	 * @param string $metaKey
115
+	 * @param mixed $metaValue
116
+	 * @return void
117
+	 * @action update_postmeta
118
+	 */
119
+	public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue)
120
+	{
121
+		if (!$this->isReviewPostId($postId)) {
122
+			return;
123
+		}
124
+		$metaKey = Str::removePrefix('_', $metaKey);
125
+		if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) {
126
+			return;
127
+		}
128
+		$review = glsr_get_review($postId);
129
+		if ($review->$metaKey == $metaValue) {
130
+			return;
131
+		}
132
+		$method = Helper::buildMethodName($metaKey, 'onBeforeChange');
133
+		call_user_func([$this, $method], $review, $metaValue);
134
+	}
135 135
 
136
-    /**
137
-     * Triggered by the onBeforeUpdate method.
138
-     *
139
-     * @param string|int $assignedTo
140
-     * @return void
141
-     */
142
-    protected function onBeforeChangeAssignedTo(Review $review, $assignedTo)
143
-    {
144
-        glsr(PostCountsManager::class)->decrease($review);
145
-        $review->assigned_to = $assignedTo;
146
-        glsr(PostCountsManager::class)->increase($review);
147
-    }
136
+	/**
137
+	 * Triggered by the onBeforeUpdate method.
138
+	 *
139
+	 * @param string|int $assignedTo
140
+	 * @return void
141
+	 */
142
+	protected function onBeforeChangeAssignedTo(Review $review, $assignedTo)
143
+	{
144
+		glsr(PostCountsManager::class)->decrease($review);
145
+		$review->assigned_to = $assignedTo;
146
+		glsr(PostCountsManager::class)->increase($review);
147
+	}
148 148
 
149
-    /**
150
-     * Triggered by the onBeforeUpdate method.
151
-     *
152
-     * @param string|int $rating
153
-     * @return void
154
-     */
155
-    protected function onBeforeChangeRating(Review $review, $rating)
156
-    {
157
-        glsr(CountsManager::class)->decreaseAll($review);
158
-        $review->rating = $rating;
159
-        glsr(CountsManager::class)->increaseAll($review);
160
-    }
149
+	/**
150
+	 * Triggered by the onBeforeUpdate method.
151
+	 *
152
+	 * @param string|int $rating
153
+	 * @return void
154
+	 */
155
+	protected function onBeforeChangeRating(Review $review, $rating)
156
+	{
157
+		glsr(CountsManager::class)->decreaseAll($review);
158
+		$review->rating = $rating;
159
+		glsr(CountsManager::class)->increaseAll($review);
160
+	}
161 161
 
162
-    /**
163
-     * Triggered by the onBeforeUpdate method.
164
-     *
165
-     * @param string $reviewType
166
-     * @return void
167
-     */
168
-    protected function onBeforeChangeReviewType(Review $review, $reviewType)
169
-    {
170
-        glsr(CountsManager::class)->decreaseAll($review);
171
-        $review->review_type = $reviewType;
172
-        glsr(CountsManager::class)->increaseAll($review);
173
-    }
162
+	/**
163
+	 * Triggered by the onBeforeUpdate method.
164
+	 *
165
+	 * @param string $reviewType
166
+	 * @return void
167
+	 */
168
+	protected function onBeforeChangeReviewType(Review $review, $reviewType)
169
+	{
170
+		glsr(CountsManager::class)->decreaseAll($review);
171
+		$review->review_type = $reviewType;
172
+		glsr(CountsManager::class)->increaseAll($review);
173
+	}
174 174
 }
Please login to merge, or discard this patch.
plugin/Modules/Validator/ValidateReview.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -13,299 +13,299 @@
 block discarded – undo
13 13
 
14 14
 class ValidateReview
15 15
 {
16
-    const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify';
16
+	const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify';
17 17
 
18
-    const RECAPTCHA_DISABLED = 0;
19
-    const RECAPTCHA_EMPTY = 1;
20
-    const RECAPTCHA_FAILED = 2;
21
-    const RECAPTCHA_INVALID = 3;
22
-    const RECAPTCHA_VALID = 4;
18
+	const RECAPTCHA_DISABLED = 0;
19
+	const RECAPTCHA_EMPTY = 1;
20
+	const RECAPTCHA_FAILED = 2;
21
+	const RECAPTCHA_INVALID = 3;
22
+	const RECAPTCHA_VALID = 4;
23 23
 
24
-    const VALIDATION_RULES = [
25
-        'content' => 'required',
26
-        'email' => 'required|email',
27
-        'name' => 'required',
28
-        'rating' => 'required|number|between:1,5',
29
-        'terms' => 'accepted',
30
-        'title' => 'required',
31
-    ];
24
+	const VALIDATION_RULES = [
25
+		'content' => 'required',
26
+		'email' => 'required|email',
27
+		'name' => 'required',
28
+		'rating' => 'required|number|between:1,5',
29
+		'terms' => 'accepted',
30
+		'title' => 'required',
31
+	];
32 32
 
33
-    /**
34
-     * @var string|void
35
-     */
36
-    public $error;
33
+	/**
34
+	 * @var string|void
35
+	 */
36
+	public $error;
37 37
 
38
-    /**
39
-     * @var string
40
-     */
41
-    public $form_id;
38
+	/**
39
+	 * @var string
40
+	 */
41
+	public $form_id;
42 42
 
43
-    /**
44
-     * @var bool
45
-     */
46
-    public $recaptchaIsUnset = false;
43
+	/**
44
+	 * @var bool
45
+	 */
46
+	public $recaptchaIsUnset = false;
47 47
 
48
-    /**
49
-     * @var array
50
-     */
51
-    public $request;
48
+	/**
49
+	 * @var array
50
+	 */
51
+	public $request;
52 52
 
53
-    /**
54
-     * @var array
55
-     */
56
-    protected $options;
53
+	/**
54
+	 * @var array
55
+	 */
56
+	protected $options;
57 57
 
58
-    /**
59
-     * @return static
60
-     */
61
-    public function validate(array $request)
62
-    {
63
-        $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation
64
-        $this->form_id = $request['form_id'];
65
-        $this->options = glsr(OptionManager::class)->all();
66
-        $this->request = $this->validateRequest($request);
67
-        $this->validateCustom();
68
-        $this->validatePermission();
69
-        $this->validateHoneyPot();
70
-        $this->validateReviewLimits();
71
-        $this->validateBlacklist();
72
-        $this->validateAkismet();
73
-        $this->validateRecaptcha();
74
-        if (!empty($this->error)) {
75
-            $this->setSessionValues('message', $this->error);
76
-        }
77
-        return $this;
78
-    }
58
+	/**
59
+	 * @return static
60
+	 */
61
+	public function validate(array $request)
62
+	{
63
+		$request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation
64
+		$this->form_id = $request['form_id'];
65
+		$this->options = glsr(OptionManager::class)->all();
66
+		$this->request = $this->validateRequest($request);
67
+		$this->validateCustom();
68
+		$this->validatePermission();
69
+		$this->validateHoneyPot();
70
+		$this->validateReviewLimits();
71
+		$this->validateBlacklist();
72
+		$this->validateAkismet();
73
+		$this->validateRecaptcha();
74
+		if (!empty($this->error)) {
75
+			$this->setSessionValues('message', $this->error);
76
+		}
77
+		return $this;
78
+	}
79 79
 
80
-    /**
81
-     * @param string $path
82
-     * @param mixed $fallback
83
-     * @return mixed
84
-     */
85
-    protected function getOption($path, $fallback = '')
86
-    {
87
-        return Arr::get($this->options, $path, $fallback);
88
-    }
80
+	/**
81
+	 * @param string $path
82
+	 * @param mixed $fallback
83
+	 * @return mixed
84
+	 */
85
+	protected function getOption($path, $fallback = '')
86
+	{
87
+		return Arr::get($this->options, $path, $fallback);
88
+	}
89 89
 
90
-    /**
91
-     * @return int
92
-     */
93
-    protected function getRecaptchaStatus()
94
-    {
95
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
96
-            return static::RECAPTCHA_DISABLED;
97
-        }
98
-        if (empty($this->request['_recaptcha-token'])) {
99
-            return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5))
100
-                ? static::RECAPTCHA_EMPTY
101
-                : static::RECAPTCHA_FAILED;
102
-        }
103
-        return $this->getRecaptchaTokenStatus();
104
-    }
90
+	/**
91
+	 * @return int
92
+	 */
93
+	protected function getRecaptchaStatus()
94
+	{
95
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
96
+			return static::RECAPTCHA_DISABLED;
97
+		}
98
+		if (empty($this->request['_recaptcha-token'])) {
99
+			return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5))
100
+				? static::RECAPTCHA_EMPTY
101
+				: static::RECAPTCHA_FAILED;
102
+		}
103
+		return $this->getRecaptchaTokenStatus();
104
+	}
105 105
 
106
-    /**
107
-     * @return int
108
-     */
109
-    protected function getRecaptchaTokenStatus()
110
-    {
111
-        $endpoint = add_query_arg([
112
-            'remoteip' => Helper::getIpAddress(),
113
-            'response' => $this->request['_recaptcha-token'],
114
-            'secret' => $this->getOption('settings.submissions.recaptcha.secret'),
115
-        ], static::RECAPTCHA_ENDPOINT);
116
-        if (is_wp_error($response = wp_remote_get($endpoint))) {
117
-            glsr_log()->error($response->get_error_message());
118
-            return static::RECAPTCHA_FAILED;
119
-        }
120
-        $response = json_decode(wp_remote_retrieve_body($response));
121
-        if (!empty($response->success)) {
122
-            return boolval($response->success)
123
-                ? static::RECAPTCHA_VALID
124
-                : static::RECAPTCHA_INVALID;
125
-        }
126
-        foreach ($response->{'error-codes'} as $error) {
127
-            glsr_log()->error('reCAPTCHA error: '.$error);
128
-        }
129
-        return static::RECAPTCHA_INVALID;
130
-    }
106
+	/**
107
+	 * @return int
108
+	 */
109
+	protected function getRecaptchaTokenStatus()
110
+	{
111
+		$endpoint = add_query_arg([
112
+			'remoteip' => Helper::getIpAddress(),
113
+			'response' => $this->request['_recaptcha-token'],
114
+			'secret' => $this->getOption('settings.submissions.recaptcha.secret'),
115
+		], static::RECAPTCHA_ENDPOINT);
116
+		if (is_wp_error($response = wp_remote_get($endpoint))) {
117
+			glsr_log()->error($response->get_error_message());
118
+			return static::RECAPTCHA_FAILED;
119
+		}
120
+		$response = json_decode(wp_remote_retrieve_body($response));
121
+		if (!empty($response->success)) {
122
+			return boolval($response->success)
123
+				? static::RECAPTCHA_VALID
124
+				: static::RECAPTCHA_INVALID;
125
+		}
126
+		foreach ($response->{'error-codes'} as $error) {
127
+			glsr_log()->error('reCAPTCHA error: '.$error);
128
+		}
129
+		return static::RECAPTCHA_INVALID;
130
+	}
131 131
 
132
-    /**
133
-     * @return array
134
-     */
135
-    protected function getValidationRules(array $request)
136
-    {
137
-        $rules = array_intersect_key(
138
-            apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request),
139
-            array_flip($this->getOption('settings.submissions.required', []))
140
-        );
141
-        $excluded = explode(',', Arr::get($request, 'excluded'));
142
-        return array_diff_key($rules, array_flip($excluded));
143
-    }
132
+	/**
133
+	 * @return array
134
+	 */
135
+	protected function getValidationRules(array $request)
136
+	{
137
+		$rules = array_intersect_key(
138
+			apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request),
139
+			array_flip($this->getOption('settings.submissions.required', []))
140
+		);
141
+		$excluded = explode(',', Arr::get($request, 'excluded'));
142
+		return array_diff_key($rules, array_flip($excluded));
143
+	}
144 144
 
145
-    /**
146
-     * @return bool
147
-     */
148
-    protected function isRequestValid(array $request)
149
-    {
150
-        $rules = $this->getValidationRules($request);
151
-        $errors = glsr(Validator::class)->validate($request, $rules);
152
-        if (empty($errors)) {
153
-            return true;
154
-        }
155
-        $this->error = __('Please fix the submission errors.', 'site-reviews');
156
-        $this->setSessionValues('errors', $errors);
157
-        $this->setSessionValues('values', $request);
158
-        return false;
159
-    }
145
+	/**
146
+	 * @return bool
147
+	 */
148
+	protected function isRequestValid(array $request)
149
+	{
150
+		$rules = $this->getValidationRules($request);
151
+		$errors = glsr(Validator::class)->validate($request, $rules);
152
+		if (empty($errors)) {
153
+			return true;
154
+		}
155
+		$this->error = __('Please fix the submission errors.', 'site-reviews');
156
+		$this->setSessionValues('errors', $errors);
157
+		$this->setSessionValues('values', $request);
158
+		return false;
159
+	}
160 160
 
161
-    protected function setError($message, $loggedMessage = '')
162
-    {
163
-        $this->setSessionValues('errors', [], $loggedMessage);
164
-        $this->error = $message;
165
-    }
161
+	protected function setError($message, $loggedMessage = '')
162
+	{
163
+		$this->setSessionValues('errors', [], $loggedMessage);
164
+		$this->error = $message;
165
+	}
166 166
 
167
-    /**
168
-     * @param string $type
169
-     * @param mixed $value
170
-     * @param string $loggedMessage
171
-     * @return void
172
-     */
173
-    protected function setSessionValues($type, $value, $loggedMessage = '')
174
-    {
175
-        glsr()->sessionSet($this->form_id.$type, $value);
176
-        if (!empty($loggedMessage)) {
177
-            glsr_log()->warning($loggedMessage)->debug($this->request);
178
-        }
179
-    }
167
+	/**
168
+	 * @param string $type
169
+	 * @param mixed $value
170
+	 * @param string $loggedMessage
171
+	 * @return void
172
+	 */
173
+	protected function setSessionValues($type, $value, $loggedMessage = '')
174
+	{
175
+		glsr()->sessionSet($this->form_id.$type, $value);
176
+		if (!empty($loggedMessage)) {
177
+			glsr_log()->warning($loggedMessage)->debug($this->request);
178
+		}
179
+	}
180 180
 
181
-    /**
182
-     * @return void
183
-     */
184
-    protected function validateAkismet()
185
-    {
186
-        if (!empty($this->error)) {
187
-            return;
188
-        }
189
-        if (glsr(Akismet::class)->isSpam($this->request)) {
190
-            $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
191
-                'Akismet caught a spam submission (consider adding the IP address to the blacklist):'
192
-            );
193
-        }
194
-    }
181
+	/**
182
+	 * @return void
183
+	 */
184
+	protected function validateAkismet()
185
+	{
186
+		if (!empty($this->error)) {
187
+			return;
188
+		}
189
+		if (glsr(Akismet::class)->isSpam($this->request)) {
190
+			$this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
191
+				'Akismet caught a spam submission (consider adding the IP address to the blacklist):'
192
+			);
193
+		}
194
+	}
195 195
 
196
-    /**
197
-     * @return void
198
-     */
199
-    protected function validateBlacklist()
200
-    {
201
-        if (!empty($this->error)) {
202
-            return;
203
-        }
204
-        if (!glsr(Blacklist::class)->isBlacklisted($this->request)) {
205
-            return;
206
-        }
207
-        $blacklistAction = $this->getOption('settings.submissions.blacklist.action');
208
-        if ('reject' != $blacklistAction) {
209
-            $this->request['blacklisted'] = true;
210
-            return;
211
-        }
212
-        $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'),
213
-            'Blacklisted submission detected:'
214
-        );
215
-    }
196
+	/**
197
+	 * @return void
198
+	 */
199
+	protected function validateBlacklist()
200
+	{
201
+		if (!empty($this->error)) {
202
+			return;
203
+		}
204
+		if (!glsr(Blacklist::class)->isBlacklisted($this->request)) {
205
+			return;
206
+		}
207
+		$blacklistAction = $this->getOption('settings.submissions.blacklist.action');
208
+		if ('reject' != $blacklistAction) {
209
+			$this->request['blacklisted'] = true;
210
+			return;
211
+		}
212
+		$this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'),
213
+			'Blacklisted submission detected:'
214
+		);
215
+	}
216 216
 
217
-    /**
218
-     * @return void
219
-     */
220
-    protected function validateCustom()
221
-    {
222
-        if (!empty($this->error)) {
223
-            return;
224
-        }
225
-        $validated = apply_filters('site-reviews/validate/custom', true, $this->request);
226
-        if (true === $validated) {
227
-            return;
228
-        }
229
-        $errorMessage = is_string($validated)
230
-            ? $validated
231
-            : __('The review submission failed. Please notify the site administrator.', 'site-reviews');
232
-        $this->setError($errorMessage);
233
-        $this->setSessionValues('values', $this->request);
234
-    }
217
+	/**
218
+	 * @return void
219
+	 */
220
+	protected function validateCustom()
221
+	{
222
+		if (!empty($this->error)) {
223
+			return;
224
+		}
225
+		$validated = apply_filters('site-reviews/validate/custom', true, $this->request);
226
+		if (true === $validated) {
227
+			return;
228
+		}
229
+		$errorMessage = is_string($validated)
230
+			? $validated
231
+			: __('The review submission failed. Please notify the site administrator.', 'site-reviews');
232
+		$this->setError($errorMessage);
233
+		$this->setSessionValues('values', $this->request);
234
+	}
235 235
 
236
-    /**
237
-     * @return void
238
-     */
239
-    protected function validateHoneyPot()
240
-    {
241
-        if (!empty($this->error)) {
242
-            return;
243
-        }
244
-        if (!empty($this->request['gotcha'])) {
245
-            $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'),
246
-                'The Honeypot caught a bad submission:'
247
-            );
248
-        }
249
-    }
236
+	/**
237
+	 * @return void
238
+	 */
239
+	protected function validateHoneyPot()
240
+	{
241
+		if (!empty($this->error)) {
242
+			return;
243
+		}
244
+		if (!empty($this->request['gotcha'])) {
245
+			$this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'),
246
+				'The Honeypot caught a bad submission:'
247
+			);
248
+		}
249
+	}
250 250
 
251
-    /**
252
-     * @return void
253
-     */
254
-    protected function validatePermission()
255
-    {
256
-        if (!empty($this->error)) {
257
-            return;
258
-        }
259
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
260
-            $this->setError(__('You must be logged in to submit a review.', 'site-reviews'));
261
-        }
262
-    }
251
+	/**
252
+	 * @return void
253
+	 */
254
+	protected function validatePermission()
255
+	{
256
+		if (!empty($this->error)) {
257
+			return;
258
+		}
259
+		if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
260
+			$this->setError(__('You must be logged in to submit a review.', 'site-reviews'));
261
+		}
262
+	}
263 263
 
264
-    /**
265
-     * @return void
266
-     */
267
-    protected function validateReviewLimits()
268
-    {
269
-        if (!empty($this->error)) {
270
-            return;
271
-        }
272
-        if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) {
273
-            $this->setError(__('You have already submitted a review.', 'site-reviews'));
274
-        }
275
-    }
264
+	/**
265
+	 * @return void
266
+	 */
267
+	protected function validateReviewLimits()
268
+	{
269
+		if (!empty($this->error)) {
270
+			return;
271
+		}
272
+		if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) {
273
+			$this->setError(__('You have already submitted a review.', 'site-reviews'));
274
+		}
275
+	}
276 276
 
277
-    /**
278
-     * @return void
279
-     */
280
-    protected function validateRecaptcha()
281
-    {
282
-        if (!empty($this->error)) {
283
-            return;
284
-        }
285
-        $status = $this->getRecaptchaStatus();
286
-        if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
287
-            return;
288
-        }
289
-        if (static::RECAPTCHA_EMPTY === $status) {
290
-            $this->setSessionValues('recaptcha', 'unset');
291
-            $this->recaptchaIsUnset = true;
292
-            return;
293
-        }
294
-        $this->setSessionValues('recaptcha', 'reset');
295
-        $errors = [
296
-            static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
297
-            static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'),
298
-        ];
299
-        $this->setError($errors[$status]);
300
-    }
277
+	/**
278
+	 * @return void
279
+	 */
280
+	protected function validateRecaptcha()
281
+	{
282
+		if (!empty($this->error)) {
283
+			return;
284
+		}
285
+		$status = $this->getRecaptchaStatus();
286
+		if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
287
+			return;
288
+		}
289
+		if (static::RECAPTCHA_EMPTY === $status) {
290
+			$this->setSessionValues('recaptcha', 'unset');
291
+			$this->recaptchaIsUnset = true;
292
+			return;
293
+		}
294
+		$this->setSessionValues('recaptcha', 'reset');
295
+		$errors = [
296
+			static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
297
+			static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'),
298
+		];
299
+		$this->setError($errors[$status]);
300
+	}
301 301
 
302
-    /**
303
-     * @return array
304
-     */
305
-    protected function validateRequest(array $request)
306
-    {
307
-        return $this->isRequestValid($request)
308
-            ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request)
309
-            : $request;
310
-    }
302
+	/**
303
+	 * @return array
304
+	 */
305
+	protected function validateRequest(array $request)
306
+	{
307
+		return $this->isRequestValid($request)
308
+			? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request)
309
+			: $request;
310
+	}
311 311
 }
Please login to merge, or discard this patch.