MimeTypeTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addMimeType() 0 8 2
A removeMimeType() 0 8 2
A getMimeTypes() 0 4 1
1
<?php
2
3
/*
4
 * body-parser (https://github.com/juliangut/body-parser).
5
 * PSR7 body parser middleware.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/body-parser
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Jgut\BodyParser\Decoder;
13
14
/**
15
 * MimeType helper trait.
16
 */
17
trait MimeTypeTrait
18
{
19
    protected $mimeTypes = [];
20
21
    /**
22
     * Add MIME Type.
23
     *
24
     * @param string $mimeType
25
     */
26
    public function addMimeType($mimeType)
27
    {
28
        $mimeType = (string) $mimeType;
29
30
        if (!in_array($mimeType, $this->mimeTypes)) {
31
            $this->mimeTypes[] = $mimeType;
32
        }
33
    }
34
35
    /**
36
     * Remove MIME Type.
37
     *
38
     * @param string $mimeType
39
     */
40
    public function removeMimeType($mimeType)
41
    {
42
        $pos = array_search($mimeType, $this->mimeTypes, true);
43
44
        if ($pos !== false) {
45
            array_splice($this->mimeTypes, $pos, 1);
46
        }
47
    }
48
49
    /**
50
     * Get MIME Types that can be decoded.
51
     *
52
     * @return array
53
     */
54
    public function getMimeTypes()
55
    {
56
        return $this->mimeTypes;
57
    }
58
}
59