Completed
Push — master ( 83b55d...472d84 )
by Justin
03:47 queued 36s
created

Body::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace Rollbar\Payload;
2
3
class Body implements \Serializable
4
{
5
    /**
6
     * @var ContentInterface
7
     */
8
    private $value;
9
    private $utilities;
10
11
    public function __construct(ContentInterface $value)
12
    {
13
        $this->utilities = new \Rollbar\Utilities();
14
        $this->setValue($value);
15
    }
16
17
    public function getValue()
18
    {
19
        return $this->value;
20
    }
21
22
    public function setValue(ContentInterface $value)
23
    {
24
        $this->value = $value;
25
        return $this;
26
    }
27
28
    public function serialize()
29
    {
30
        $result = array();
31
        $result[$this->value->getKey()] = $this->value;
32
        return $this->utilities->serializeForRollbar($result);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->utilities-...lizeForRollbar($result) returns the type array which is incompatible with the return type mandated by Serializable::serialize() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
33
    }
34
    
35
    public function unserialize($serialized)
36
    {
37
        throw new \Exception('Not implemented yet.');
38
    }
39
}
40