Completed
Push — master ( 72ee7f...4775c0 )
by Jacob
03:43
created

ServiceCommentRepository::createComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Comment\Comment;
4
5
use Jacobemerick\CommentService\Api\DefaultApi;
6
use Jacobemerick\CommentService\Model\Comment;
7
8
class ServiceCommentRepository implements CommentRepositoryInterface
9
{
10
11
    /**
12
     * @var Jacobemerick\CommentService\Api\DefaultApi
13
     */
14
    protected $api;
15
16
    /**
17
     * @param Jacobemerick\CommentService\Api\DefaultApi $api
18
     */
19
    public function __construct(DefaultApi $api)
20
    {
21
        $this->api = $api;
0 ignored issues
show
Documentation Bug introduced by
It seems like $api of type object<Jacobemerick\Comm...Service\Api\DefaultApi> is incompatible with the declared type object<Jacobemerick\Web\...Service\Api\DefaultApi> of property $api.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
    }
23
24
    /**
25
     * @param array $comment
26
     * @return array
27
     * @throws Jacobemerick\CommentService\ApiException
28
     */
29
    public function createComment(array $comment)
30
    {
31
        $response = $this->api->createComment($comment);
32
        return $this->deserializeComment($response);
33
    }
34
35
    /**
36
     * @param integer $commentId
37
     * @return array
38
     * @throws Jacobemerick\CommentService\ApiException
39
     */
40
    public function getComment($commentId)
41
    {
42
        $response = $this->api->getComment($commentId);
43
        return $this->deserializeComment($response);
44
    }
45
46
    /**
47
     * @param string $domain
48
     * @param string $path
49
     * @param integer $page
50
     * @param integer $perPage
51
     * @param string $order
52
     * @return array
53
     * @throws Jacobemerick\CommentService\ApiException
54
     */
55
    public function getComments($domain = null, $path = null, $page = null, $perPage = null, $order = null)
56
    {
57
        $response = $this->api->getComments($page, $perPage, $order, $domain, $path);
58
        return array_map([$this, 'deserializeComment'], $response);
59
    }
60
61
    /**
62
     * @param Jacobemerick\CommentService\Model\Comment $comment
63
     * @return array
64
     */
65
    protected function deserializeComment(Comment $comment)
66
    {
67
        return [
68
            'id' => $comment->getId(),
69
            'commenter' => [
70
                'id' => $comment->getCommenter()->getId(),
71
                'name' => $comment->getCommenter()->getName(),
72
                'website' => $comment->getCommenter()->getWebsite(),
73
            ],
74
            'body' => $comment->getBody(),
75
            'date' => $comment->getDate(),
76
            'url' => $comment->getUrl(),
77
            'reply_to' => $comment->getReplyTo(),
78
            'thread' => $comment->getThread(),
79
        ];
80
    }
81
}
82