Completed
Push — develop ( f6ac94...a82602 )
by Paul
01:59
created

Render   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 79
Duplicated Lines 25.32 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 20
loc 79
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A blockquote() 9 9 2
A button() 0 14 3
A buttons() 0 6 2
A content() 0 10 2
A gallery() 0 4 1
A title() 11 11 3
A video() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
	public function blockquote( $metaKey = false, array $attributes = [] )
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
	{
27
		$tag = 'blockquote';
28
		$value = $this->postmeta->get( $metaKey );
29
30
		if( !$value )return;
31
32
		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
33
	}
34
35
	public function button( $postId = 0, $title = false )
36
	{
37
		$post = get_post( $postId );
38
39
		if( !$post )return;
40
		if( !$title ) {
41
			$title = $post->post_title;
42
		}
43
44
		printf( '<a href="%s" class="button"><span>%s</span></a>',
45
			get_permalink( $post->ID ),
46
			$title
47
		);
48
	}
49
50
	public function buttons( array $postIds = [] )
51
	{
52
		foreach( $postIds as $postId ) {
53
			$this->button( $postId );
54
		}
55
	}
56
57
	public function content( $metaKey = false )
58
	{
59
		$content = $metaKey
60
			? $this->postmeta->get( $metaKey )
61
			: get_the_content();
62
63
		$content = apply_filters( 'the_content', $content );
64
65
		print str_replace( ']]>', ']]&gt;', $content );
66
	}
67
68
	public function gallery( array $args = [] )
69
	{
70
		print $this->media->gallery( $args );
71
	}
72
73 View Code Duplication
	public function title( $metaKey = false, array $attributes = [] )
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
	{
75
		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
76
		$value = $metaKey
77
			? $this->postmeta->get( $metaKey )
78
			: $this->theme->pageTitle();
79
80
		if( !$value )return;
81
82
		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
83
	}
84
85
	public function video( $metaKey = 'video', $screenshotMetaKey = false )
2 ignored issues
show
Unused Code introduced by
The parameter $metaKey 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 $screenshotMetaKey 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...
86
	{
87
	}
88
}
89