Passed
Pull Request — master (#59)
by Raúl
05:19 queued 01:21
created

Mime   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullMime() 0 3 2
A supportsMimeType() 0 3 1
1
<?php
2
3
namespace Httpful;
4
5
/**
6
 * Class to organize the Mime stuff a bit more
7
 * @author Nate Good <[email protected]>
8
 */
9
class Mime
10
{
11
    const JSON    = 'application/json';
12
    const XML     = 'application/xml';
13
    const XHTML   = 'application/html+xml';
14
    const FORM    = 'application/x-www-form-urlencoded';
15
    const UPLOAD  = 'multipart/form-data';
16
    const PLAIN   = 'text/plain';
17
    const JS      = 'text/javascript';
18
    const HTML    = 'text/html';
19
    const YAML    = 'application/x-yaml';
20
    const CSV     = 'text/csv';
21
22
    /**
23
     * Map short name for a mime type
24
     * to a full proper mime type
25
     */
26
    public static $mimes = array(
27
        'json'      => self::JSON,
28
        'xml'       => self::XML,
29
        'form'      => self::FORM,
30
        'plain'     => self::PLAIN,
31
        'text'      => self::PLAIN,
32
        'upload'      => self::UPLOAD,
33
        'html'      => self::HTML,
34
        'xhtml'     => self::XHTML,
35
        'js'        => self::JS,
36
        'javascript'=> self::JS,
37
        'yaml'      => self::YAML,
38
        'csv'       => self::CSV,
39
    );
40
41
    /**
42
     * Get the full Mime Type name from a "short name".
43
     * Returns the short if no mapping was found.
44
     * @param string $short_name common name for mime type (e.g. json)
45
     * @return string full mime type (e.g. application/json)
46
     */
47
    public static function getFullMime($short_name)
48
    {
49
        return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name;
50
    }
51
52
    /**
53
     * @param string $short_name
54
     * @return bool
55
     */
56
    public static function supportsMimeType($short_name)
57
    {
58
        return array_key_exists($short_name, self::$mimes);
59
    }
60
}
61