Completed
Push — master ( dcf43c...59d132 )
by Tijs
06:54
created

JsData::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Service;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
/**
9
 * Class JsData
10
 *
11
 * @package SumoCoders\FrameworkCoreBundle\Service
12
 */
13
class JsData extends ParameterBag
14
{
15
    /**
16
     * @var \Symfony\Component\HttpFoundation\RequestStack
17
     */
18
    protected $requestStack;
19
20
    /**
21
     * @param RequestStack $requestStack
22
     */
23 11
    public function __construct(RequestStack $requestStack)
24
    {
25 11
        $this->requestStack = $requestStack;
26 11
    }
27
28
    /**
29
     * Handle the request stack
30
     */
31 11
    protected function handleRequestStack()
32
    {
33 11
        $currentRequest = $this->requestStack->getCurrentRequest();
34
35 11
        if ($currentRequest) {
36
            $requestData = array(
37 11
                'locale' => $currentRequest->getLocale(),
38 11
            );
39
40 11
            $this->set('request', $requestData);
41 11
        }
42 11
    }
43
44
    /**
45
     * Parse into string
46
     *
47
     * @return string
48
     */
49 11
    public function __toString()
50
    {
51 11
        $this->handleRequestStack();
52
53 11
        return json_encode($this->all());
54
    }
55
}
56