Passed
Push — master ( 999d23...fe5b90 )
by Paul
04:24
created

CreateReview::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 1
dl 0
loc 19
ccs 18
cts 18
cp 1
crap 1
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Commands;
4
5
use GeminiLabs\SiteReviews\Helper;
6
7
class CreateReview
8
{
9
	public $ajax_request;
10
	public $assigned_to;
11
	public $author;
12
	public $avatar;
13
	public $blacklisted;
14
	public $category;
15
	public $content;
16
	public $custom;
17
	public $email;
18
	public $form_id;
19
	public $ip_address;
20
	public $post_id;
21
	public $rating;
22
	public $referer;
23
	public $terms;
24
	public $title;
25
26
	protected $request;
27
28 1
	public function __construct( $input )
29
	{
30 1
		$this->request = $input;
31 1
		$this->ajax_request = isset( $input['ajax_request'] );
32 1
		$this->assigned_to = $this->getNumeric( 'assign_to' );
33 1
		$this->author = sanitize_text_field( $this->get( 'name' ));
34 1
		$this->avatar = get_avatar_url( $this->get( 'email' ));
35 1
		$this->blacklisted = isset( $input['blacklisted'] );
36 1
		$this->category = sanitize_key( $this->get( 'category' ));
37 1
		$this->content = sanitize_textarea_field( $this->get( 'content' ));
38 1
		$this->custom = $this->getCustom();
39 1
		$this->email = sanitize_email( $this->get( 'email' ));
40 1
		$this->form_id = sanitize_key( $this->get( 'form_id' ));
41 1
		$this->ip_address = $this->get( 'ip_address' );
42 1
		$this->post_id = intval( $this->get( 'post_id' ));
43 1
		$this->rating = intval( $this->get( 'rating' ));
44 1
		$this->referer = $this->get( 'referer' );
45 1
		$this->terms = isset( $input['terms'] );
46 1
		$this->title = sanitize_text_field( $this->get( 'title' ));
47 1
	}
48
49
	/**
50
	 * @param string $key
51
	 * @return string
52
	 */
53 1
	protected function get( $key )
54
	{
55 1
		return isset( $this->request[$key] )
56 1
			? (string)$this->request[$key]
57 1
			: '';
58
	}
59
60
	/**
61
	 * @return array
62
	 */
63 1
	protected function getCustom()
64
	{
65
		$unset = [
66 1
			'action', 'ajax_request', 'assign_to', 'category', 'content', 'email', 'excluded',
67
			'form_id', 'gotcha', 'ip_address', 'name', 'nonce', 'post_id', 'rating',
68
			'recaptcha-token', 'referer', 'terms', 'title',
69
		];
70 1
		$custom = $this->request;
71 1
		foreach( $unset as $value ) {
72 1
			unset( $custom[$value] );
73
		}
74 1
		return $custom;
75
	}
76
77
	/**
78
	 * @param string $key
79
	 * @return string
80
	 */
81 1
	protected function getNumeric( $key )
82
	{
83 1
		return is_numeric( $this->request[$key] )
84
			? (string)$this->request[$key]
85 1
			: '';
86
	}
87
}
88