Passed
Push — master ( a2a2c3...5dc036 )
by Carlos
03:01
created

Media::toXmlArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[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 EasyWeChat\Kernel\Messages;
13
14
use EasyWeChat\Kernel\Contracts\MediaInterface;
15
use EasyWeChat\Kernel\Support\Str;
16
17
/**
18
 * Class Media.
19
 */
20
class Media extends Message implements MediaInterface
21
{
22
    /**
23
     * Properties.
24
     *
25
     * @var array
26
     */
27
    protected $properties = ['media_id'];
28
29
    /**
30
     * @var array
31
     */
32
    protected $required = [
33
        'media_id',
34
    ];
35
36
    /**
37
     * MaterialClient constructor.
38
     *
39
     * @param string $mediaId
40
     * @param string $type
41
     * @param array  $attributes
42
     */
43
    public function __construct(string $mediaId, $type = null, array $attributes = [])
44
    {
45
        parent::__construct(array_merge(['media_id' => $mediaId], $attributes));
46
47
        !empty($type) && $this->setType($type);
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getMediaId(): string
54
    {
55
        $this->checkRequiredAttributes();
56
57
        return $this->get('media_id');
58
    }
59
60
    public function toXmlArray()
61
    {
62
        return [
63
            Str::studly($this->getType()) => [
64
                'MediaId' => $this->get('media_id'),
65
            ],
66
        ];
67
    }
68
}
69