Passed
Push — master ( f2dd2f...70c2c9 )
by Elvis Henrique
08:46
created

Example::find_one_by_post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace App\Repositories;
4
5
use App\Entities\Example as Entity;
6
use App\Entities\Examples;
7
use WPSteak\Repositories\AbstractPost;
8
9
/** @codeCoverageIgnore */
10
class Example extends AbstractPost {
11
12
	public function find_one_by_post( \WP_Post $post ): ?Entity {
13
		return new Entity( $post, $this->meta->get( (int) $post->ID, 'address', true ) );
14
	}
15
16
	public function find_by_author_id( int $author_id, int $quantity ): Examples {
17
		$posts = $this->get_posts(
18
			[
19
				'numberposts' => $quantity,
20
				'author' => $author_id,
21
			],
22
		);
23
24
		return new Examples(
25
			...array_map(
26
				fn ( \WP_Post $post ) => new Entity(
27
					$post,
28
					$this->meta->get( (int) $post->ID, 'address', true ),
29
				),
30
				$posts,
31
			),
32
		);
33
	}
34
35
}
36