Term::get_term()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 12
rs 10
1
<?php declare(strict_types = 1);
2
3
namespace WPSteak\Repositories;
4
5
/** @codeCoverageIgnore */
6
abstract class Term {
7
8
	/** @param \WP_Term|int $term Id. */
9
	protected function get_term( $term ): ?\WP_Term {
10
		if ( $term instanceof \WP_Term ) {
11
			return $term;
12
		}
13
14
		$result = get_term( $term );
15
16
		if ( ! $result instanceof \WP_Term ) {
17
			return null;
18
		}
19
20
		return $result;
21
	}
22
23
	/**
24
	 * @param array<string> $args Args.
25
	 * @return array<\WP_Term>
26
	 * @throws \InvalidArgumentException When the passed taxonomy does not exists.
27
	 */
28
	protected function get_terms( array $args ): array {
29
		$terms = get_terms( $args );
30
31
		if ( ! is_array( $terms ) ) {
0 ignored issues
show
introduced by
The condition is_array($terms) is always false.
Loading history...
32
			throw new \InvalidArgumentException( __( 'Taxonomia não existe.', 'wpsteak' ) );
33
		}
34
35
		return $terms;
36
	}
37
38
}
39