Passed
Push — master ( d47355...85ec42 )
by Paul
04:15
created

CreateReview::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.4268

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 4
nop 1
dl 0
loc 18
ccs 7
cts 15
cp 0.4667
crap 6.4268
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Handlers;
4
5
use GeminiLabs\SiteReviews\Commands\CreateReview as Command;
6
use GeminiLabs\SiteReviews\Database\ReviewManager;
7
use GeminiLabs\SiteReviews\Modules\Notification;
8
use GeminiLabs\SiteReviews\Modules\Session;
9
10
class CreateReview
11
{
12
	/**
13
	 * @return void|string
14
	 */
15 1
	public function handle( Command $command )
16
	{
17 1
		$review = glsr( ReviewManager::class )->create( $command );
18 1
		if( !$review ) {
19
			glsr( Session::class )->set( $command->form_id.'errors', [] );
20
			glsr( Session::class )->set( $command->form_id.'message', __( 'Your review could not be submitted and the error has been logged. Please notify the site admin.', 'site-reviews' ));
21
			return;
22
		}
23 1
		glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' ));
24 1
		glsr( Notification::class )->send( $review );
25 1
		do_action( 'site-reviews/local/review/submitted', $review );
26 1
		if( $command->ajax_request )return;
27
		if( empty( $command->referer )) {
28
			glsr_log()->warning( 'The form referer ($_SERVER[REQUEST_URI]) was empty.' )->info( $command );
29
			$command->referer = home_url();
30
		}
31
		wp_safe_redirect( $command->referer );
32
		exit;
33
	}
34
}
35