Passed
Push — master ( 9cbbc5...71a3af )
by Michael
02:33
created

AttributesContainer::hasAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document\Behaviour;
5
6
/**
7
 * Attributes-container behaviour
8
 *
9
 * @see http://jsonapi.org/format/#document-resource-object-attributes
10
 *
11
 * @package Mikemirten\Component\JsonApi\Document\Behaviour
12
 */
13 View Code Duplication
trait AttributesContainer
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
     * Attributes
17
     *
18
     * @var array
19
     */
20
    protected $attributes = [];
21
22
    /**
23
     * Set attribute
24
     *
25
     * @param string $name
26
     * @param mixed  $value
27
     */
28 1
    public function setAttribute(string $name, $value)
29
    {
30 1
        $this->attributes[$name] = $value;
31 1
    }
32
33
    /**
34
     * Has attribute
35
     *
36
     * @param  string $name
37
     * @return bool
38
     */
39 1
    public function hasAttribute(string $name): bool
40
    {
41 1
        return array_key_exists($name, $this->attributes);
42
    }
43
44
    /**
45
     * Get attribute
46
     *
47
     * @param  string $name
48
     * @return mixed
49
     */
50 1
    public function getAttribute(string $name)
51
    {
52 1
        return $this->attributes[$name];
53
    }
54
55
    /**
56
     * Contains any attributes ?
57
     *
58
     * @return bool
59
     */
60
    public function hasAttributes(): bool
61
    {
62
        return count($this->attributes) > 0;
63
    }
64
65
    /**
66
     * Get all attributes
67
     *
68
     * @return array
69
     */
70 8
    public function getAttributes(): array
71
    {
72 8
        return $this->attributes;
73
    }
74
}