Passed
Pull Request — master (#9)
by Iakov
02:59
created

SerializeResponseDataStep::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Common;
4
5
use JMS\Serializer\Serializer;
6
use Kami\ApiCoreBundle\RequestProcessor\ProcessorResponse;
7
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractStep;
8
9
class SerializeResponseDataStep extends AbstractStep
10
{
11
    /**
12
     * @var Serializer
13
     */
14
    private $serializer;
15
16
    public function __construct(Serializer $serializer)
17
    {
18
        $this->serializer = $serializer;
19
    }
20
21
    public function execute()
22
    {
23
        $serialized = $this->serializer->serialize(
24
            $this->getFromResponse('response_data'),
25
            $this->request->attributes->get('_format')
26
        );
27
        return $this->createResponse(['response_data'=> $serialized], true);
28
29
30
    }
31
32
    public function requiresBefore()
33
    {
34
        return [];
35
    }
36
}