Passed
Push — master ( 507d84...d47355 )
by Paul
04:33
created

CreateReview::createEmailNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 17
ccs 0
cts 12
cp 0
crap 2
rs 9.8333
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
		do_action( 'site-reviews/local/review/submitted', $review );
26
		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