DefaultController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 52
ccs 0
cts 38
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 45 4
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