Completed
Push — 3.x ( e32815...7c4255 )
by Ryota
10:41 queued 09:27
created

Messages::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Polidog\Chatwork\Api\Rooms;
6
7
use Polidog\Chatwork\Client\ClientInterface;
8
use Polidog\Chatwork\Entity\Collection\CollectionInterface;
9
use Polidog\Chatwork\Entity\EntityInterface;
10
use Polidog\Chatwork\Entity\Factory\MessageFactory;
11
use Polidog\Chatwork\Entity\Message;
12
13
/**
14
 * Class Messages.
15
 */
16
class Messages
17
{
18
    /**
19
     * @var ClientInterface
20
     */
21
    private $client;
22
23
    /**
24
     * @var MessageFactory
25
     */
26
    private $factory;
27
28
    /**
29
     * @var int
30
     */
31
    private $roomId;
32
33
    /**
34
     * Messages constructor.
35
     *
36
     * @param ClientInterface $client
37
     * @param MessageFactory  $factory
38
     * @param int             $roomId
39
     */
40
    public function __construct(ClientInterface $client, MessageFactory $factory, int $roomId)
41
    {
42
        $this->client = $client;
43
        $this->factory = $factory;
44
        $this->roomId = $roomId;
45
    }
46
47
    /**
48
     * @param bool $force
49
     *
50
     * @return CollectionInterface
51
     */
52 View Code Duplication
    public function show($force = false)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        return $this->factory->collection(
55
            $this->client->get(
56
                "rooms/{$this->roomId}/messages",
57
                [
58
                    'force' => (int) $force,
59
                ]
60
            )
61
        );
62
    }
63
64
    /**
65
     * @param $id
66
     * @param bool $force
67
     *
68
     * @return Message|EntityInterface
69
     */
70 View Code Duplication
    public function detail($id, $force = false)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        return $this->factory->entity(
73
            $this->client->get(
74
                "rooms/{$this->roomId}/messages/{$id}",
75
                [
76
                    'force' => (int) $force,
77
                ]
78
            )
79
        );
80
    }
81
82
    /**
83
     * @param Message $message
84
     */
85
    public function create(Message $message)
86
    {
87
        $result = $this->client->post(
88
            "rooms/{$this->roomId}/messages",
89
            [
90
                'body' => $message->body,
91
            ]
92
        );
93
94
        $message->messageId = $result['message_id'];
95
    }
96
}
97