Audio   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 55%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 70
ccs 11
cts 20
cp 0.55
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 9 3
A __construct() 0 3 1
A getProperties() 0 18 4
1
<?php
2
3
namespace Mpyw\OpenGraph\Elements;
4
5
use Mpyw\OpenGraph\Property;
6
7
/**
8
 * An Open Graph audio element.
9
 */
10
class Audio extends ElementBase
11
{
12
    /**
13
     * The URL of an audio resource associated with the object.
14
     *
15
     * @var string
16
     */
17
    public $url;
18
19
    /**
20
     * An alternate URL to use if an audio resource requires HTTPS.
21
     *
22
     * @var null|string
23
     */
24
    public $secureUrl;
25
26
    /**
27
     * The MIME type of an audio resource associated with the object.
28
     *
29
     * @var null|string
30
     */
31
    public $type;
32
33
    /**
34
     * @param mixed $url URL to the audio file.
35
     */
36 1
    public function __construct($url)
37
    {
38 1
        $this->url = (string)$url;
39 1
    }
40
41
    /**
42
     * @param string $name
43
     * @param mixed  $value
44
     */
45 1
    public function setAttribute(string $name, $value)
46
    {
47
        switch ($name) {
48 1
            case Property::AUDIO_TYPE:
49 1
                $this->type = (string)$value;
50 1
                break;
51 1
            case Property::AUDIO_SECURE_URL:
52 1
                $this->secureUrl = (string)$value;
53 1
                break;
54
        }
55 1
    }
56
57
    /**
58
     * Gets all properties set on this element.
59
     *
60
     * @return Property[]
61
     */
62
    public function getProperties(): array
63
    {
64
        $properties = [];
65
66
        // URL must precede all other properties
67
        if ($this->url !== null) {
68
            $properties[] = new Property(Property::AUDIO_URL, $this->url);
69
        }
70
71
        if ($this->secureUrl !== null) {
72
            $properties[] = new Property(Property::AUDIO_SECURE_URL, $this->secureUrl);
73
        }
74
75
        if ($this->type !== null) {
76
            $properties[] = new Property(Property::AUDIO_TYPE, $this->type);
77
        }
78
79
        return $properties;
80
    }
81
}
82