Test Setup Failed
Push — develop ( 67f164...d5fe8d )
by Elvis Henrique
03:02
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_one() 0 8 2
A find_by_author_id() 0 15 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