Completed
Push — develop ( 0f7a5c...505371 )
by Paul
02:14
created

Render   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 26
c 0
b 0
f 0
lcom 2
cbo 5
dl 0
loc 135
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A blockquote() 0 6 2
A button() 0 13 4
A buttons() 0 6 2
A content() 0 8 2
A copyright() 0 13 2
B featured() 0 25 5
A field() 0 3 1
A form() 0 3 1
A gallery() 0 4 1
A madeWithLove() 0 7 1
A title() 0 11 3
A video() 0 4 1
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
use GeminiLabs\Castor\Helpers\Media;
6
use GeminiLabs\Castor\Helpers\PostMeta;
7
use GeminiLabs\Castor\Helpers\Theme;
8
use GeminiLabs\Castor\Helpers\Utility;
9
10
class Render
11
{
12
	public $media;
13
	public $postmeta;
14
	public $theme;
15
	public $utility;
16
17
	public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility )
18
	{
19
		$this->media    = $media;
20
		$this->postmeta = $postmeta;
21
		$this->theme    = $theme;
22
		$this->utility  = $utility;
23
	}
24
25
	public function blockquote( $metaKey = false, array $attributes = [] )
26
	{
27
		if( $value = $this->postmeta->get( $metaKey )) {
0 ignored issues
show
Documentation introduced by
$metaKey is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
			$this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes );
29
		}
30
	}
31
32
	public function button( $postId = 0, $title = false )
33
	{
34
		$post = get_post( $postId );
35
36
		if( !$postId || !$post )return;
37
		if( !$title ) {
38
			$title = $post->post_title;
39
		}
40
		printf( '<a href="%s" class="button"><span>%s</span></a>',
41
			get_permalink( $post->ID ),
42
			$title
43
		);
44
	}
45
46
	public function buttons( $postIds = [] )
47
	{
48
		foreach( (array) $postIds as $postId ) {
49
			$this->button( $postId );
50
		}
51
	}
52
53
	public function content( $metaKey = false )
54
	{
55
		$content = $metaKey
56
			? $this->postmeta->get( $metaKey )
0 ignored issues
show
Documentation introduced by
$metaKey is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
			: get_the_content();
58
59
		echo str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $content ));
60
	}
61
62
	public function copyright( array $args = [] )
63
	{
64
		extract( shortcode_atts([
0 ignored issues
show
Bug introduced by
shortcode_atts(array('co...' => '&mdash;'), $args) cannot be passed to extract() as the parameter $var_array expects a reference.
Loading history...
65
			'copyright' => sprintf( '<span>%s </span>&copy;', __( 'Copyright', 'castor' )),
66
			'date' => date( 'Y' ),
67
			'name' => get_bloginfo( 'name' ),
68
			'separator' => '&mdash;',
69
		], $args ));
70
		if( $separator ) {
71
			$separator .= ' ';
72
		}
73
		printf( '%s %s %s%s', $copyright, $date, $separator, $name );
74
	}
75
76
	public function featured( $args = [] )
77
	{
78
		$args = wp_parse_args( $args, [
79
			'class'  => 'featured',
80
			'image'  => get_post_thumbnail_id(),
81
			'player' => '',
82
			'video'  => 'featured_video',
83
		]);
84
		$featuredHtml = $this->media->video( wp_parse_args( $args, [
85
			'url' => $args['video'],
86
		]));
87
		if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) {
88
			$featuredCaption = $featuredImage->caption
89
				? sprintf( '<figcaption>%s</figcaption>', $featuredImage->caption )
90
				: '';
91
			$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div>%s',
92
				$featuredImage->large['url'],
93
				$featuredImage->alt,
94
				$featuredCaption
95
			);
96
		}
97
		if( !empty( $featuredHtml )) {
98
			printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml );
99
		}
100
	}
101
102
	public function field( $name, array $args = [] )
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
	{
104
	}
105
106
	public function form( $name, array $args = [] )
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
	{
108
	}
109
110
	public function gallery( array $args = [] )
111
	{
112
		echo $this->media->gallery( $args );
113
	}
114
115
	public function madeWithLove( $name )
116
	{
117
		printf( __( 'Made with %s by %s', 'castor' ),
118
			file_get_contents( sprintf( '%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets )),
119
			$name
120
		);
121
	}
122
123
	public function title( $metaKey = false, array $attributes = [] )
124
	{
125
		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
126
		$value = $metaKey
127
			? $this->postmeta->get( $metaKey )
0 ignored issues
show
Documentation introduced by
$metaKey is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
			: $this->theme->pageTitle();
129
130
		if( !$value )return;
131
132
		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
133
	}
134
135
	/**
136
	 * @param array|string $args
137
	 *
138
	 * @return string|null
139
	 */
140
	public function video( $args )
141
	{
142
		echo $this->media->video( $args );
143
	}
144
}
145