Completed
Push — master ( 6bc3b4...34ca55 )
by Ralf
15s queued 11s
created

MimeHandlerAdapter::stripBom()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 7
nc 4
nop 1
dl 0
loc 9
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Handlers are used to parse and serialize payloads for specific
5
 * mime types.  You can register a custom handler via the register
6
 * method.  You can also override a default parser in this way.
7
 */
8
9
namespace Httpful\Handlers;
10
11
class MimeHandlerAdapter
12
{
13
    public function __construct(array $args = array())
14
    {
15
        $this->init($args);
16
    }
17
18
    /**
19
     * Initial setup of
20
     * @param array $args
21
     */
22
    public function init(array $args)
23
    {
24
    }
25
26
    /**
27
     * @param string $body
28
     * @return mixed
29
     */
30
    public function parse($body)
31
    {
32
        return $body;
33
    }
34
35
    /**
36
     * @param mixed $payload
37
     * @return string
38
     */
39
    function serialize($payload)
40
    {
41
        return (string) $payload;
42
    }
43
44
    protected function stripBom($body)
45
    {
46
        if ( substr($body,0,3) === "\xef\xbb\xbf" )  // UTF-8
47
            $body = substr($body,3);
48
        else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" )  // UTF-32
49
            $body = substr($body,4);
50
        else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" )  // UTF-16
51
            $body = substr($body,2);
52
        return $body;
53
    }
54
}