Completed
Pull Request — develop (#1588)
by Zack
19:25
created

View_Details   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 22 4
1
<?php
2
3
namespace GV\Gutenberg\Blocks\Block;
4
5
// Exit if accessed directly
6
if ( ! defined( 'ABSPATH' ) ) {
7
	exit;
8
}
9
10
class View_Details extends Block {
11
	const BLOCK_NAME = 'view-details';
12
13
	/**
14
	 * Generate `[gravityview]` shortcode
15
	 *
16
	 * @param array $attributes
17
	 *                         array['id']     string  The ID of the View you want to display
18
	 *                         array['detail'] string  Display specific information about a View. Valid values are total_entries, first_entry, last_entry, page_size
19
	 *
20
	 * @return string $output
21
	 */
22
	static function render( $attributes = array() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
		$accepted_attributes = array(
24
			'id',
25
			'detail',
26
		);
27
28
		$shortcode_attributes = array();
29
30
		foreach ( $attributes as $attribute => $value ) {
31
			$value = esc_attr( sanitize_text_field( $value ) );
32
33
			if ( in_array( $attribute, $accepted_attributes ) && ! empty( $value ) ) {
34
				$shortcode_attributes[] = "{$attribute}={$value}";
35
			}
36
		}
37
38
		$shortcode = sprintf( '[gravityview %s]', implode( ' ', $shortcode_attributes ) );
39
40
		$output = do_shortcode( $shortcode );
41
42
		return $output;
43
	}
44
}
45