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

PostsToIdsDataFormatter::formatData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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