JsonRequestHandler::handleRequest()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Majora\Framework\Form\Extension\Json;
4
5
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
6
use Symfony\Component\Form\RequestHandlerInterface;
7
use Symfony\Component\Form\FormInterface;
8
use Symfony\Component\Form\Exception\UnexpectedTypeException;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class JsonRequestHandler implements RequestHandlerInterface
12
{
13
    /**
14
     * @var HttpFoundationRequestHandler
15
     */
16
    private $httpFoundationRequestHandler;
17
18 28
    public function __construct(HttpFoundationRequestHandler $httpFoundationRequestHandler)
19
    {
20 28
        $this->httpFoundationRequestHandler = $httpFoundationRequestHandler;
21 28
    }
22
    /**
23
     * {@inheritdoc}
24
     */
25 20
    public function handleRequest(FormInterface $form, $request = null)
26
    {
27 20
        if (!$request instanceof Request) {
28 2
            throw new UnexpectedTypeException($request, Symfony\Component\HttpFoundation\Request::class);
29
        }
30
31 18
        if ($request->getContentType() !== 'json') {
32 4
            $this->httpFoundationRequestHandler->handleRequest($form, $request);
33
34 4
            return;
35
        }
36
37 14
        $form->submit($request->getContent());
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, Symfony\Component\Form\FormInterface::submit() does only seem to accept null|string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38 6
    }
39
}
40