Passed
Push — develop ( 176838...c67b25 )
by mingyoung
01:40
created

Message::type()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) mingyoung <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\Kernel\Messages;
13
14
/**
15
 * Class Message.
16
 *
17
 * @author mingyoung <[email protected]>
18
 */
19
abstract class Message
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $type;
25
26
    /**
27
     * @var array
28
     */
29
    protected $attributes = [];
30
31
    /**
32
     * Message constructor.
33
     *
34
     * @param array $attributes
35
     */
36
    public function __construct(array $attributes)
37
    {
38
        $this->attributes = $attributes;
39
    }
40
41
    /**
42
     * @param int|string|\EasyDingTalk\Kernel\Messages\Message $message
43
     *
44
     * @return \EasyDingTalk\Kernel\Messages\Message
45
     */
46 View Code Duplication
    public static function parse($message): Message
0 ignored issues
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...
47
    {
48
        if (is_int($message) || is_string($message)) {
49
            $message = new Text($message);
50
        }
51
52
        return $message;
53
    }
54
55
    public function type()
56
    {
57
        return $this->type;
58
    }
59
60
    public function body()
61
    {
62
        return $this->attributes;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function transform(): array
69
    {
70
        return [
71
            'msgtype' => $this->type,
72
            $this->type => $this->attributes,
73
        ];
74
    }
75
}
76