Context::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php namespace Rollbar\Payload;
2
3
class Context implements \Serializable
4
{
5
    private $pre;
6
    private $post;
7
    private $utilities;
8
9
    public function __construct($pre, $post)
10
    {
11
        $this->utilities = new \Rollbar\Utilities();
12
        $this->setPre($pre);
13
        $this->setPost($post);
14
    }
15
16
    public function getPre()
17
    {
18
        return $this->pre;
19
    }
20
21
    public function setPre($pre)
22
    {
23
        $this->pre = $pre;
24
        return $this;
25
    }
26
27
    public function getPost()
28
    {
29
        return $this->post;
30
    }
31
32
    public function setPost($post)
33
    {
34
        $this->post = $post;
35
        return $this;
36
    }
37
38
    public function serialize()
39
    {
40
        $result = array(
41
            "pre" => $this->pre,
42
            "post" => $this->post,
43
        );
44
        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...
45
    }
46
    
47
    public function unserialize($serialized)
48
    {
49
        throw new \Exception('Not implemented yet.');
50
    }
51
}
52