JsonRequestHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleRequest() 0 14 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