Passed
Push — master ( 642023...49ec8d )
by Paul
03:40
created

Metaboxes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 29
ccs 4
cts 13
cp 0.3076
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveResponseMetabox() 0 8 2
A saveAssignedToMetabox() 0 9 3
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers\EditorController;
4
5
use GeminiLabs\SiteReviews\Database\CountsManager;
6
use GeminiLabs\SiteReviews\Database\ReviewManager;
7
use GeminiLabs\SiteReviews\Helper;
8
9
class Metaboxes
10
{
11
	/**
12
	 * @param int $postId
13
	 * @return void
14
	 */
15 1
	public function saveAssignedToMetabox( $postId )
16
	{
17 1
		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return;
18
		$assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' ));
19
		if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) {
20
			$review = glsr( ReviewManager::class )->single( get_post( $postId ));
21
			glsr( CountsManager::class )->decreasePostCounts( $review );
22
		}
23
		update_post_meta( $postId, 'assigned_to', $assignedTo );
24
	}
25
26
	/**
27
	 * @param int $postId
28
	 * @return mixed
29
	 */
30 1
	public function saveResponseMetabox( $postId )
31
	{
32 1
		if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return;
33
		$response = strval( glsr( Helper::class )->filterInput( 'response' ));
34
		update_post_meta( $postId, 'response', trim( wp_kses( $response, [
35
			'a' => ['href' => [], 'title' => []],
36
			'em' => [],
37
			'strong' => [],
38
		])));
39
	}
40
}
41