Test Setup Failed
Push — develop ( 67f164...d5fe8d )
by Elvis Henrique
03:02
created

Post::find_one()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
ccs 4
cts 4
cp 1
crap 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\Post as Entity;
13
use WPSteak\Entities\Collection;
0 ignored issues
show
Bug introduced by
The type WPSteak\Entities\Collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use WPSteak\Repositories\AbstractPost;
0 ignored issues
show
Bug introduced by
The type WPSteak\Repositories\AbstractPost was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Post class.
18
 */
19
class Post extends AbstractPost {
20
21
	/**
22
	 * Find one.
23
	 *
24
	 * @param \WP_Post|int $post The post object or id.
25
	 * @return Entity|null
26 2
	 */
27 2
	public function find_one( $post ) : ?Entity {
28
		$post = $this->get_post( $post );
29 2
30 1
		if ( empty( $post ) ) {
31
			return null;
32
		}
33 1
34
		return ( new Entity() )->set_post( $post );
35
	}
36
37
	/**
38
	 * Find by author id.
39
	 *
40
	 * @param integer $author_id Author id.
41
	 * @param integer $quantity Quantity.
42
	 * @return Collection
43 1
	 */
44 1
	public function find_by_author_id( int $author_id, int $quantity ) : Collection {
45
		$posts = $this->get_posts(
46 1
			[
47 1
				'numberposts' => $quantity,
48
				'author'      => $author_id,
49
			]
50
		);
51 1
52
		$collection = new Collection();
53 1
54 1
		foreach ( $posts as $post ) {
55
			$collection->add_entity( ( new Entity() )->set_post( $post ) );
56
		}
57 1
58
		return $collection;
59
	}
60
}
61