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

PostMeta::normalize()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 2
nop 1
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