Completed
Push — develop ( 117c72...bb7f99 )
by Victor
03:10
created

AppExtension::getTabs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
ccs 14
cts 14
cp 1
rs 9.3143
cc 1
eloc 14
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: victor
5
 * Date: 08.01.16
6
 * Time: 18:45
7
 */
8
9
namespace AppBundle\Twig;
10
11
12
use Symfony\Bridge\Doctrine\RegistryInterface;
13
14
class AppExtension extends \Twig_Extension
15
{
16
    protected $doctrine;
17
18 9
    public function __construct(RegistryInterface $doctrine)
19
    {
20 9
        $this->doctrine = $doctrine;
21 9
    }
22
23 4
    public function getFunctions()
24
    {
25
        return array(
26 4
            new \Twig_SimpleFunction('popularArticlesTabs',
27 4
                array($this, 'getTabs'),
28
                array(
29 4
                    'needs_environment' => true,
30 4
                    'is_safe' => array('html'))
31 4
            ),
32 4
            new \Twig_SimpleFunction('tagsList',
33 4
                array($this, 'getTags'),
34
                array(
35 4
                    'needs_environment' => true,
36 4
                    'is_safe' => array('html'))
37 4
            ),
38 4
            new \Twig_SimpleFunction('categoriesList',
39 4
                array($this, 'getCategories'),
40
                array(
41 4
                    'needs_environment' => true,
42 4
                    'is_safe' => array('html'))
43 4
            )
44
45 4
        );
46
    }
47
48 5
    public function getTabs(\Twig_Environment $twig)
49
    {
50 5
        $em = $this->doctrine->getManager();
51 5
        $popularArticles = $em->getRepository("AppBundle:Article")
52 5
            ->getPopularArticles(5);
53
54 5
        $recentArticles = $em->getRepository("AppBundle:Article")
55 5
            ->getRecentArticles(5);
56
57 5
        $recentComments = $em->getRepository("AppBundle:Comment")
58 5
            ->getRecentComments(5);
59
60 5
        return $twig->render(
61 5
            'AppBundle:blog:widgetTabs.html.twig',
62
            array(
63 5
                'popularArticles' => $popularArticles,
64 5
                'recentArticles' => $recentArticles,
65 5
                'recentComments' => $recentComments,
66
            )
67 5
        );
68
    }
69
70 5
    public function getTags(\Twig_Environment $twig)
71
    {
72 5
        $em = $this->doctrine->getManager();
73 5
        $tags = $em->getRepository("AppBundle:Tag")
74 5
            ->getTagsWithCount();
75
76
//        shuffle($tags);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
78 5
        return $twig->render(
79 5
            'AppBundle:blog:widgetTags.html.twig',
80
            array(
81 5
                'tags' => $tags,
82
            )
83 5
        );
84
    }
85
86 5
    public function getCategories(\Twig_Environment $twig)
87
    {
88 5
        $em = $this->doctrine->getManager();
89 5
        $categories = $em->getRepository("AppBundle:Category")
90 5
            ->getCategoriesWithCount();
91
92 5
        return $twig->render(
93 5
            'AppBundle:blog:widgetCategories.html.twig',
94
            array(
95 5
                'categories' => $categories,
96
            )
97 5
        );
98
    }
99
100 9
    public function getName()
101
    {
102 9
        return 'app_extension';
103
    }
104
}