DefaultController::indexAction()   B
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 45
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 45
ccs 0
cts 38
cp 0
rs 8.5806
cc 4
eloc 27
nc 5
nop 1
crap 20
1
<?php
2
3
namespace SumoCoders\FrameworkSearchBundle\Controller;
4
5
use SumoCoders\FrameworkSearchBundle\Form\Type\SearchType;
6
use SumoCoders\FrameworkSearchBundle\Helper\Search;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Request;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
12
class DefaultController extends Controller
13
{
14
    /**
15
     * @Route("/search.{_format}", defaults={"_format"="html"}, requirements={"_format"="html|json"})
16
     * @Template()
17
     */
18
    public function indexAction(Request $request)
19
    {
20
        $term = $request->get('term');
21
        $form = $this->createForm(
22
            SearchType::class,
23
            array('term' => $term)
24
        );
25
26
        $form->handleRequest($request);
27
28
        if ($form->isValid()) {
29
            $data = $form->getData();
30
31
            return $this->redirect(
32
                $this->generateUrl(
33
                    'sumocoders_frameworksearch_default_index',
34
                    array(
35
                        'term' => $data['term']
36
                    )
37
                )
38
            );
39
        }
40
41
        $results = null;
42
        if ('' != $term) {
43
            $repository = $this->getDoctrine()->getRepository('SumoCodersFrameworkSearchBundle:IndexItem');
44
            $dispatcher = $this->get('event_dispatcher');
45
            $search = new Search($repository, $dispatcher, $term);
0 ignored issues
show
Compatibility introduced by
$repository of type object<Doctrine\Common\P...tence\ObjectRepository> is not a sub-type of object<SumoCoders\Framew...ty\IndexItemRepository>. It seems like you assume a concrete implementation of the interface Doctrine\Common\Persistence\ObjectRepository to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46
47
            $results = $search->search();
48
        }
49
50
        if ('' != $term) {
51
            $this->get('framework.breadcrumb_builder')
52
                ->addSimpleItem(
53
                    $term
54
                );
55
        }
56
57
        return array(
58
            'term' => $term,
59
            'form' => $form->createView(),
60
            'results' => $results,
61
        );
62
    }
63
}
64