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

AbstractTerm   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 48
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_terms() 0 8 2
A __construct() 0 2 1
A get_term() 0 6 2
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