Metadata::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Incus
4
 * 
5
 * @copyright   Copyright (c) 2014 Warrick Bayman.
6
 * @author		Warrick Bayman <[email protected]>
7
 * @license     MIT License http://opensource.org/licenses/MIT
8
 * 
9
 */
10
11
namespace Incus;
12
13
14
use Incus\Contracts\SimpleCollectionInterface;
15
16
class Metadata implements SimpleCollectionInterface
17
{
18
    private $metadata;
19
20
21
    /**
22
     * @param $message
23
     */
24
    function __construct($message)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
    {
26
        $this->metadata = [];
27
        if (property_exists($message, 'metadata') && isset($message->metadata)) {
28
            $this->metadata = (Array)$message->metadata;
29
        }
30
    }
31
32
33
    /**
34
     * Returns an object of all the metadata keys
35
     *
36
     * @return stdClass
37
     */
38
    public function all()
39
    {
40
        return (Object)$this->metadata;
41
    }
42
43
44
    /**
45
     * Has metadata key
46
     *
47
     * @param string $key
48
     *
49
     * @return boolean
50
     */
51
    public function has($key)
52
    {
53
        if (array_key_exists($key, $this->metadata)) {
54
            return true;
55
        }
56
        return false;
57
    }
58
59
60
    /**
61
     * Get metadata value
62
     *
63
     * @param string $key
64
     *
65
     * @return string
66
     */
67
    public function get($key)
68
    {
69
        if ($this->has($key)) {
70
            return $this->metadata[$key];
71
        }
72
        return null;
73
    }
74
}
75