Metadata   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 59
wmc 8
lcom 1
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A __construct() 0 7 3
A has() 0 7 2
A get() 0 7 2
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