Completed
Push — 3.x ( e32815...7c4255 )
by Ryota
09:26 queued 05:13
created

Messages   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 27.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 22
loc 81
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A show() 11 11 1
A detail() 11 11 1
A create() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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