Passed
Push — master ( c1150e...84b7ab )
by Michael
02:30
created

MetadataContainer::setMetadataAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document\Behaviour;
5
6
/**
7
 * Metadata-container behaviour
8
 *
9
 * @see http://jsonapi.org/format/#document-meta
10
 *
11
 * @package Mikemirten\Component\JsonApi\Document\Behaviour
12
 */
13 View Code Duplication
trait MetadataContainer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * Metadata attributes
17
     *
18
     * @var array
19
     */
20
    protected $metadata = [];
21
22
    /**
23
     * Set attribute of metadata
24
     *
25
     * @param string $name
26
     * @param $value
27
     */
28
    public function setMetadataAttribute(string $name, $value)
29
    {
30
        $this->metadata[$name] = $value;
31
    }
32
33
    /**
34
     * Has attribute of metadata
35
     *
36
     * @param  string $name
37
     * @return bool
38
     */
39
    public function hasMetadataAttribute(string $name): bool
40
    {
41
        return array_key_exists($name, $this->metadata);
42
    }
43
44
    /**
45
     * Get attribute of metadata
46
     *
47
     * @param string $name
48
     * @return mixed
49
     */
50
    public function getMetadataAttribute(string $name)
51
    {
52
        return $this->metadata[$name];
53
    }
54
55
    /**
56
     * Contains any metadata ?
57
     *
58
     * @return bool
59
     */
60
    public function hasMetadata(): bool
61
    {
62
        return count($this->metadata) > 0;
63
    }
64
65
    /**
66
     * Get all attributes of metadata
67
     *
68
     * @return array
69
     */
70
    public function getMetadata(): array
71
    {
72
        return $this->metadata;
73
    }
74
}