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

Category   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 38
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find_all() 0 15 2
A find_by_id() 0 8 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