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

CreateReview   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 46.67%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
ccs 7
cts 15
cp 0.4667
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 4
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