Completed
Push — master ( 2d2f76...c06362 )
by Sebastian
02:09
created

PhpObjectContent::asString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Kartenmacherei\RestFramework\Response\Content;
3
4
use Kartenmacherei\RestFramework\EnsureException;
5
6
class PhpObjectContent implements Content
7
{
8
    /**
9
     * @var mixed object
10
     */
11
    private $object;
12
13
    /**
14
     * @param mixed $object
15
     */
16
    public function __construct($object)
17
    {
18
        $this->ensureIsObject($object);
19
        $this->object = $object;
20
    }
21
22
23
    /**
24
     * @return string
25
     */
26
    public function asString(): string
27
    {
28
        return serialize($this->object);
29
    }
30
31
    /**
32
     * @return ContentType
33
     */
34
    public function getContentType(): ContentType
35
    {
36
        return new PlainContentType();
37
    }
38
39
    /**
40
     * @param $value
41
     * @throws EnsureException
42
     */
43
    private function ensureIsObject($value)
44
    {
45
        if (!is_object($value)) {
46
            throw new EnsureException('Value must be an object');
47
        }
48
    }
49
}
50