Failed Conditions
Push — develop ( d7a728...605806 )
by Elvis Henrique
04:12
created

AbstractTerm::get_term()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * Abstract term.
4
 *
5
 * @package App
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Repositories;
11
12
use App\Services\Meta\TermInterface as MetaInterface;
13
14
/**
15
 * Abstract term class.
16
 */
17
abstract class AbstractTerm {
18
19
	/**
20
	 * Meta.
21
	 *
22
	 * @var MetaInterface
23
	 */
24
	protected $meta;
25
26
	/**
27
	 * Construct.
28
	 *
29
	 * @param MetaInterface $meta Meta.
30
	 */
31
	public function __construct( MetaInterface $meta ) {
32
		$this->meta = $meta;
33
	}
34
35
	/**
36
	 * Get term.
37
	 *
38
	 * @param integer $id Id.
39
	 * @return \WP_term
40
	 * @throws \InvalidArgumentException When $id param is empty.
41
	 */
42
	protected function get_term( int $id ) {
43
		if ( empty( $id ) ) {
44
			throw new \InvalidArgumentException( __( 'Termo vazio.', 'wpsteak' ) );
45
		}
46
47
		return get_term( $id );
0 ignored issues
show
Bug Best Practice introduced by
The expression return get_term($id) also could return the type WP_Error|array which is incompatible with the documented return type WP_term.
Loading history...
48
	}
49
50
	/**
51
	 * Get terms.
52
	 *
53
	 * @param array $args Args.
54
	 * @return \WP_Term[]
55
	 * @throws \InvalidArgumentException When the passed taxonomy does not exists.
56
	 */
57
	protected function get_terms( array $args ) : array {
58
		$terms = get_terms( $args );
59
60
		if ( is_wp_error( $terms ) ) {
61
			throw new \InvalidArgumentException( __( 'Taxonomia não existe', 'wpsteak' ) );
62
		}
63
64
		return $terms;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $terms could return the type WP_Error which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
65
	}
66
}
67