| Total Complexity | 8 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class PostMetaManager |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @param string $metaKey |
||
| 17 | * @return mixed |
||
| 18 | */ |
||
| 19 | public function get( $metaKey, array $args = [] ) |
||
| 20 | { |
||
| 21 | if( empty( $metaKey ))return; |
||
| 22 | |||
| 23 | $args = $this->normalize( $args ); |
||
| 24 | $metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] ); |
||
| 25 | $metaValue = get_post_meta( $args['id'], $metaKey, $args['single'] ); |
||
| 26 | |||
| 27 | if( is_string( $metaValue )) { |
||
| 28 | $metaValue = trim( $metaValue ); |
||
| 29 | } |
||
| 30 | return empty( $metaValue ) |
||
| 31 | ? $args['fallback'] |
||
| 32 | : $metaValue; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $metaKey |
||
| 37 | * @param string $prefix |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | protected function buildMetaKey( $metaKey, $prefix ) |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | protected function normalize( array $args ) |
||
| 59 | } |
||
| 60 | } |
||
| 61 |