Passed
Push — master ( 7de9ff...9a7a6b )
by Paul
07:10 queued 03:33
created

ChangeStatus::getStatusLinks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 0
loc 14
ccs 0
cts 14
cp 0
crap 12
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Handlers;
4
5
use GeminiLabs\SiteReviews\Commands\ChangeStatus as Command;
6
use GeminiLabs\SiteReviews\Modules\Html\Builder;
7
8
class ChangeStatus
9
{
10
	/**
11
	 * @return array
12
	 */
13
	public function handle( Command $command )
14
	{
15
		$postId = wp_update_post([
16
			'ID' => $command->id,
17
			'post_status' => $command->status,
18
		]);
19
		if( is_wp_error( $postId )) {
20
			glsr_log()->error( $postId->get_error_message() );
21
			return [];
22
		}
23
		return [
24
			'class' => 'status-'.$command->status,
25
			'link' => $this->getPostLink( $postId ).$this->getPostState( $postId ),
26
		];
27
	}
28
29
	/**
30
	 * @param int $postId
31
	 * @return string
32
	 */
33
	protected function getPostLink( $postId )
34
	{
35
		$title = _draft_or_post_title( $postId );
36
		return glsr( Builder::class )->a( $title, [
37
			'aria-label' => '&#8220;'.esc_attr( $title ).'&#8221; ('.__( 'Edit', 'site-reviews' ).')',
38
			'class' => 'row-title',
39
			'href' => get_edit_post_link( $postId ),
40
		]);
41
	}
42
43
	/**
44
	 * @param int $postId
45
	 * @return string
46
	 */
47
	protected function getPostState( $postId )
48
	{
49
		ob_start();
50
		_post_states( get_post( $postId ));
51
		return ob_get_clean();
52
	}
53
}
54