Test Setup Failed
Push — master ( 2f148a...436d74 )
by Chauncey
01:04 queued 11s
created

AudioProperty::generateExtension()   B

Complexity

Conditions 8
Paths 18

Size

Total Lines 28

Duplication

Lines 9
Ratio 32.14 %

Importance

Changes 0
Metric Value
dl 9
loc 28
rs 8.4444
c 0
b 0
f 0
cc 8
nc 18
nop 1
1
<?php
2
3
namespace Charcoal\Property;
4
5
use InvalidArgumentException;
6
7
// From 'charcoal-property'
8
use Charcoal\Property\FileProperty;
9
10
/**
11
 * Audio Property.
12
 *
13
 * The audio property is a specialized file property.
14
 */
15
class AudioProperty extends FileProperty
16
{
17
    /**
18
     * Minimum audio length, in seconds.
19
     *
20
     * @var integer
21
     */
22
    private $minLength = 0;
23
24
    /**
25
     * Maximum audio length, in seconds.
26
     *
27
     * @var integer
28
     */
29
    private $maxLength = 0;
30
31
    /**
32
     * @return string
33
     */
34
    public function type()
35
    {
36
        return 'audio';
37
    }
38
39
    /**
40
     * @param integer $minLength The minimum length allowed, in seconds.
41
     * @throws InvalidArgumentException If the length is not an integer.
42
     * @return AudioProperty Chainable
43
     */
44
    public function setMinLength($minLength)
45
    {
46
        if (!is_int($minLength)) {
47
            throw new InvalidArgumentException(
48
                'Min length must be an integer (in seconds)'
49
            );
50
        }
51
        $this->minLength = $minLength;
52
        return $this;
53
    }
54
55
    /**
56
     * @return integer
57
     */
58
    public function getMinLength()
59
    {
60
        return $this->minLength;
61
    }
62
63
    /**
64
     * @param integer $maxLength The maximum length allowed, in seconds.
65
     * @throws InvalidArgumentException If the length is not an integer.
66
     * @return AudioProperty Chainable
67
     */
68
    public function setMaxLength($maxLength)
69
    {
70
        if (!is_int($maxLength)) {
71
            throw new InvalidArgumentException(
72
                'Max length must be an integer (in seconds)'
73
            );
74
        }
75
        $this->maxLength = $maxLength;
76
        return $this;
77
    }
78
79
    /**
80
     * @return integer
81
     */
82
    public function getMaxLength()
83
    {
84
        return $this->maxLength;
85
    }
86
87
    /**
88
     * Retrieves the default list of acceptable MIME types for uploaded files.
89
     *
90
     * This method should be overriden.
91
     *
92
     * @return string[]
93
     */
94 View Code Duplication
    public function getDefaultAcceptedMimetypes()
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...
95
    {
96
        return [
97
            'audio/mp3',
98
            'audio/mpeg',
99
            'audio/ogg',
100
            'audio/webm',
101
            'audio/wav',
102
            'audio/wave',
103
            'audio/x-wav',
104
            'audio/x-pn-wav',
105
        ];
106
    }
107
108
    /**
109
     * Resolve the file extension from the given MIME type.
110
     *
111
     * @param  string $type The MIME type to resolve.
112
     * @return string|null The extension based on the MIME type.
113
     */
114 View Code Duplication
    protected function resolveExtensionFromMimeType($type)
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...
115
    {
116
        switch ($type) {
117
            case 'audio/mp3':
118
            case 'audio/mpeg':
119
                return 'mp3';
120
121
            case 'audio/ogg':
122
                return 'ogg';
123
124
            case 'audio/webm':
125
                return 'webm';
126
127
            case 'audio/wav':
128
            case 'audio/wave':
129
            case 'audio/x-wav':
130
            case 'audio/x-pn-wav':
131
                return 'wav';
132
        }
133
134
        return null;
135
    }
136
}
137