ImageRepository::whereIds()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Leonidas\Library\System\Model\Image;
4
5
use Leonidas\Contracts\System\Model\Image\ImageCollectionInterface;
6
use Leonidas\Contracts\System\Model\Image\ImageInterface;
7
use Leonidas\Contracts\System\Model\Image\ImageRepositoryInterface;
8
use Leonidas\Contracts\System\Model\Post\PostInterface;
9
use Leonidas\Library\System\Model\Abstracts\Attachment\AbstractAttachmentEntityRepository;
10
11
class ImageRepository extends AbstractAttachmentEntityRepository implements ImageRepositoryInterface
12
{
13
    public function select(int $id): ?ImageInterface
14
    {
15
        return $this->manager->select($id);
16
    }
17
18
    public function whereIds(int ...$ids): ImageCollectionInterface
19
    {
20
        return $this->manager->whereIds(...$ids);
21
    }
22
23
    public function whereAttachedToPost(PostInterface $post): ImageCollectionInterface
24
    {
25
        return $this->manager->whereAttachedToPost($post->getId());
26
    }
27
28
    public function query(array $args): ImageCollectionInterface
29
    {
30
        return $this->manager->query($args);
31
    }
32
33
    public function all(): ImageCollectionInterface
34
    {
35
        return $this->manager->all();
36
    }
37
38
    public function insert(ImageInterface $image): void
39
    {
40
        $this->manager->insert($this->extractData($image));
41
    }
42
43
    public function update(ImageInterface $image): void
44
    {
45
        $this->manager->update($image->getId(), $this->extractData($image));
46
    }
47
48
    protected function extractData(ImageInterface $image): array
49
    {
50
        $dateFormat = $image::DATE_FORMAT;
51
52
        $image->applyFilter('db');
53
54
        return [
55
            'post_author' => $image->getAuthor()->getId(),
56
            'post_date' => $image->getDate()->format($dateFormat),
57
            'post_date_gmt' => $image->getDate()->format($dateFormat),
58
            'post_content' => $image->getDescription(),
59
            'post_title' => $image->getTitle(),
60
            'post_excerpt' => $image->getCaption(),
61
            'comment_status' => $image->getCommentStatus(),
62
            'ping_status' => $image->getPingStatus(),
63
            'pinged' => $image->getPinged(),
64
            'to_ping' => $image->getToBePinged(),
65
            'post_password' => $image->getPassword(),
66
            'post_name' => $image->getName(),
67
            'post_modified' => $image->getDate()->format($dateFormat),
68
            'post_modified_gmt' => $image->getDate()->format($dateFormat),
69
            'post_mime_type' => $image->getMimeType(),
70
            'menu_order' => $image->getMenuOrder(),
71
            'guid' => $image->getGuid()->getHref(),
72
            'tax_input' => $this->extractTaxInput($image),
73
            'meta_input' => $this->extractMetaInput($image),
74
        ];
75
    }
76
77
    protected function extractMetaInput(ImageInterface $post): array
78
    {
79
        return [
80
            '_wp_attachment_image_alt' => $post->getAlt(),
81
        ];
82
    }
83
84
    protected function extractTaxInput(ImageInterface $post): array
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

84
    protected function extractTaxInput(/** @scrutinizer ignore-unused */ ImageInterface $post): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        return [];
87
    }
88
}
89