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

Media   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getMediaId() 0 6 1
A toXmlArray() 0 8 1
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