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

Category::find_by_id()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Category.
4
 *
5
 * @package App
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Repositories;
11
12
use App\Entities\Collection;
13
use App\Entities\Category as Entity;
14
15
/**
16
 * Category class.
17
 */
18
class Category extends AbstractTerm {
19
20
	/**
21
	 * Find by id.
22
	 *
23
	 * @param integer $id Id.
24
	 * @return Entity|null
25
	 */
26 2
	public function find_by_id( int $id ) : ?Entity {
27 2
		$term = $this->get_term( $id );
28
29 2
		if ( ! $term ) {
0 ignored issues
show
introduced by
$term is of type WP_term, thus it always evaluated to true.
Loading history...
30 1
			return null;
31
		}
32
33 1
		return ( new Entity() )->set_term( $term );
34
	}
35
36
	/**
37
	 * Find all.
38
	 *
39
	 * @return Collection
40
	 */
41 1
	public function find_all() : Collection {
42 1
		$terms = $this->get_terms(
43
			[
44 1
				'taxonomy'   => Entity::TAXONOMY,
45
				'hide_empty' => false,
46
			]
47
		);
48
49 1
		$collection = new Collection();
50
51 1
		foreach ( $terms as $term ) {
52 1
			$collection->add_entity( ( new Entity() )->set_term( $term ) );
53
		}
54
55 1
		return $collection;
56
	}
57
}
58