Message::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Mdb\PayPal\Ipn;
4
5
class Message
6
{
7
    /**
8
     * @var array
9
     */
10
    private $data;
11
12
    /**
13
     * @param array|string $data
14
     */
15
    public function __construct($data = [])
16
    {
17
        if (!is_array($data)) {
18
            $data = $this->extractDataFromRawPostDataString($data);
19
        }
20
21
        $this->data = $data;
22
    }
23
24
    public function get(string $key) : string
25
    {
26
        $value = '';
27
28
        if (isset($this->data[$key])) {
29
            $value = $this->data[$key];
30
        }
31
32
        return $value;
33
    }
34
35
    public function getAll() : array
36
    {
37
        return $this->data;
38
    }
39
40
    public function __toString() : string
41
    {
42
        return http_build_query($this->getAll(), null, '&');
43
    }
44
45
    private function extractDataFromRawPostDataString($rawPostDataString) : array
46
    {
47
        parse_str($rawPostDataString, $data);
48
49
        return $data;
50
    }
51
}
52