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

Post   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find_by_author_id() 0 15 2
A find_by_id() 0 8 2
1
<?php
2
/**
3
 * Post.
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\Post as Entity;
14
15
/**
16
 * Post class.
17
 */
18
class Post extends AbstractPost {
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
		$post = $this->get_post( $id );
28
29 2
		if ( ! $post ) {
0 ignored issues
show
introduced by
$post is of type WP_Post, thus it always evaluated to true.
Loading history...
30 1
			return null;
31
		}
32
33 1
		return ( new Entity() )->set_post( $post );
34
	}
35
36
	/**
37
	 * Find by author id.
38
	 *
39
	 * @param integer $author_id Author id.
40
	 * @param integer $quantity Quantity.
41
	 * @return Collection
42
	 */
43 1
	public function find_by_author_id( int $author_id, int $quantity ) : Collection {
44 1
		$posts = $this->get_posts(
45
			[
46 1
				'numberposts' => $quantity,
47 1
				'author'      => $author_id,
48
			]
49
		);
50
51 1
		$collection = new Collection();
52
53 1
		foreach ( $posts as $post ) {
54 1
			$collection->add_entity( ( new Entity() )->set_post( $post ) );
55
		}
56
57 1
		return $collection;
58
	}
59
}
60