Completed
Push — develop ( 4145c9...286694 )
by Paul
04:35
created

Render::h1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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, $passthrough = false )
33
	{
34
		if( $passthrough ) {
35
			$url = $postId;
36
		}
37
		if( !isset( $url )) {
38
			$url = get_permalink( $postId );
39
			if( !$title ) {
40
				$title = get_the_title( $postId );
41
			}
42
		}
43
		if( !$title || !$url )return;
44
		printf( '<a href="%s" class="button"><span>%s</span></a>', $url, $title );
45
	}
46
47
	public function buttons( $postIds = [] )
48
	{
49
		foreach( (array) $postIds as $postId ) {
50
			$this->button( $postId );
51
		}
52
	}
53
54
	public function content( $metaKey = false, $passthrough = false )
55
	{
56
		if( $passthrough ) {
57
			$content = $metaKey;
58
		}
59
		if( !isset( $content )) {
60
			$content = $metaKey
61
				? $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...
62
				: get_the_content();
63
		}
64
		echo str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $content ));
65
	}
66
67
	public function copyright( array $args = [] )
68
	{
69
		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...
70
			'copyright' => sprintf( '<span>%s </span>&copy;', __( 'Copyright', 'castor' )),
71
			'date' => date( 'Y' ),
72
			'name' => get_bloginfo( 'name' ),
73
			'separator' => '&mdash;',
74
		], $args ));
75
		if( $separator ) {
76
			$separator .= ' ';
77
		}
78
		printf( '%s %s %s%s', $copyright, $date, $separator, $name );
79
	}
80
81
	public function featured( $args = [] )
82
	{
83
		$args = wp_parse_args( $args, [
84
			'class'  => 'featured',
85
			'image'  => get_post_thumbnail_id(),
86
			'player' => '',
87
			'video'  => 'featured_video',
88
		]);
89
		$featuredHtml = $this->media->video( wp_parse_args( $args, [
90
			'url' => $args['video'],
91
		]));
92
		if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) {
93
			$featuredCaption = $featuredImage->caption
94
				? sprintf( '<figcaption>%s</figcaption>', $featuredImage->caption )
95
				: '';
96
			$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div>%s',
97
				$featuredImage->large['url'],
98
				$featuredImage->alt,
99
				$featuredCaption
100
			);
101
		}
102
		if( !empty( $featuredHtml )) {
103
			printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml );
104
		}
105
	}
106
107
	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...
108
	{
109
	}
110
111
	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...
112
	{
113
	}
114
115
	public function gallery( array $args = [] )
116
	{
117
		echo $this->media->gallery( $args );
118
	}
119
120
	public function h1( $string, array $attributes = [] ) {
121
		$this->utility->printTag( 'h1', wp_strip_all_tags( $string ), $attributes );
122
	}
123
124
	public function h2( $string, array $attributes = [] ) {
125
		$this->utility->printTag( 'h2', wp_strip_all_tags( $string ), $attributes );
126
	}
127
128
	public function h3( $string, array $attributes = [] ) {
129
		$this->utility->printTag( 'h3', wp_strip_all_tags( $string ), $attributes );
130
	}
131
132
	public function h4( $string, array $attributes = [] ) {
133
		$this->utility->printTag( 'h4', wp_strip_all_tags( $string ), $attributes );
134
	}
135
136
	public function h5( $string, array $attributes = [] ) {
137
		$this->utility->printTag( 'h5', wp_strip_all_tags( $string ), $attributes );
138
	}
139
140
	public function h6( $string, array $attributes = [] ) {
141
		$this->utility->printTag( 'h6', wp_strip_all_tags( $string ), $attributes );
142
	}
143
144
	public function madeWithLove( $name )
145
	{
146
		printf( __( 'Made with %s by %s', 'castor' ),
147
			file_get_contents( sprintf( '%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets )),
148
			$name
149
		);
150
	}
151
152
	public function p( $string, array $attributes = [] ) {
153
		$this->utility->printTag( 'p', wp_strip_all_tags( $string ), $attributes );
154
	}
155
156
	public function title( $metaKey = false, array $attributes = [] )
157
	{
158
		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
159
		$value = $metaKey
160
			? $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...
161
			: $this->theme->pageTitle();
162
163
		if( !$value )return;
164
165
		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
166
	}
167
168
	/**
169
	 * @param array|string $args
170
	 *
171
	 * @return string|null
172
	 */
173
	public function video( $args )
174
	{
175
		echo $this->media->video( $args );
176
	}
177
}
178