Completed
Push — develop ( 633b58...079584 )
by Paul
02:14
created

PostMeta   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 9 2
A normalize() 0 16 4
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
class PostMeta
6
{
7
	public function get( $value, array $args = [] )
8
	{
9
		$args = $this->normalize( $args );
10
		$metaValue = get_post_meta( $args['ID'], $args['prefix'] . $value, $args['single'] );
11
12
		return empty( $metaValue )
13
			? $args['fallback']
14
			: $metaValue;
15
	}
16
17
	protected function normalize( array $args )
18
	{
19
		$defaults = [
20
			'ID'       => get_the_ID(),
21
			'fallback' => '',
22
			'single'   => true,
23
			'prefix'   => 'pollux_',
24
		];
25
26
		$args = shortcode_atts( $defaults, $args );
27
28
		if( !empty( $value ) && $value[0] == '_' && !empty( $args['prefix'] )) {
0 ignored issues
show
Bug introduced by
The variable $value seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
29
			$args['prefix'] = sprintf( '_%s', rtrim( $args['prefix'], '_' ));
30
		}
31
		return $args;
32
	}
33
}
34