Completed
Pull Request — develop (#1588)
by Zack
37:04 queued 17:05
created

Entry   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 Entry extends Block {
11
	const BLOCK_NAME = 'entry';
12
13
	/**
14
	 * Generate `[gventry]` shortcode
15
	 *
16
	 * @param array $attributes
17
	 *                         array['view_id']     string  The numeric View ID the entry should be displayed from.
18
	 *                         array['id']          string  A numeric ID or slug referencing the entry. Or the last, first entry from the View. The View's sorting and filtering settings will be applied to the entries
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
			'view_id',
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( '[gventry %s]', implode( ' ', $shortcode_attributes ) );
39
40
		$output = do_shortcode( $shortcode );
41
42
		return $output;
43
	}
44
}
45