Completed
Push — master ( a2744c...70f396 )
by Dev
17:32 queued 02:34
created

AppExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 35
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 6 1
A __construct() 0 4 1
A showConversation() 0 11 1
1
<?php
2
3
namespace PiedWeb\ConversationBundle\Twig;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Twig\Environment as Twig;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFunction;
10
11
class AppExtension extends AbstractExtension
12
{
13
    /** @var EntityManagerInterface */
14
    private $em;
15
16
    /** @var string */
17
    private $messageEntity;
18
19
    public function __construct(EntityManager $em, string $messageEntity)
20
    {
21
        $this->em = $em;
22
        $this->messageEntity = $messageEntity;
23
    }
24
25
    public function getFunctions()
26
    {
27
        return [
28
            new TwigFunction('showConversation', [$this, 'showConversation'], [
29
                'is_safe' => ['html'],
30
                'needs_environment' => true,
31
            ]),
32
        ];
33
    }
34
35
    public function showConversation(
36
        Twig $env,
37
        string $referring,
38
        string $orderBy = 'createdAt DESC',
39
        $limit = 0,
40
        string $template = '@PiedWebConversation/_messages_list.html.twig'
41
    ) {
42
        $messages = $this->em->getRepository($this->messageEntity)
43
            ->getMessagesPublishedByReferring($referring, $orderBy, $limit);
0 ignored issues
show
Bug introduced by
The method getMessagesPublishedByReferring() does not exist on Doctrine\Persistence\ObjectRepository. It seems like you code against a sub-type of Doctrine\Persistence\ObjectRepository such as Doctrine\ORM\EntityRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            ->/** @scrutinizer ignore-call */ getMessagesPublishedByReferring($referring, $orderBy, $limit);
Loading history...
44
45
        return $env->render($template, ['messages' => $messages]);
46
    }
47
}
48