Test Failed
Push — master ( 135f34...8b25c6 )
by Chris
33:49
created

PostsToIdsDataFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A formatInput() 0 7 2
A formatData() 0 5 1
1
<?php
2
3
namespace Leonidas\Library\Admin\Field\Formatting;
4
5
use Leonidas\Library\System\Schema\Post\PostCollection;
6
use WebTheory\Saveyour\Contracts\Formatting\DataFormatterInterface;
7
use WP_Post;
8
9
class PostsToIdsDataFormatter implements DataFormatterInterface
10
{
11
    /**
12
     * @param WP_Post[] $posts
13
     *
14
     * @return array
15
     */
16
    public function formatData($posts)
17
    {
18
        $posts = new PostCollection(...$posts);
19
20
        return array_map('strval', $posts->getIds());
21
    }
22
23
    /**
24
     * @param array $terms
25
     *
26
     * @return array
27
     */
28
    public function formatInput($posts)
29
    {
30
        if (in_array('', $posts)) {
31
            unset($posts[array_search('', $posts)]);
32
        }
33
34
        return array_map('intval', $posts);
35
    }
36
}
37