Completed
Pull Request — master (#25)
by
unknown
04:55
created

AzineEmailController::emailsDashboardAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 1
1
<?php
2
3
namespace Azine\EmailBundle\Controller;
4
5
6
use Azine\EmailBundle\Entity\SentEmail;
7
use Azine\EmailBundle\Form\SentEmailType;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
11
class AzineEmailController extends Controller
12
{
13
14
    /**
15
     *  Emails-Dashboard
16
     */
17
    public function emailsDashboardAction(Request $request)
18
    {
19
        $form = $this->createForm(new SentEmailType());
0 ignored issues
show
Documentation introduced by
new \Azine\EmailBundle\Form\SentEmailType() is of type object<Azine\EmailBundle\Form\SentEmailType>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
20
21
        $form->handleRequest($request);
22
23
        $repository = $this->getDoctrine()->getManager()->getRepository(SentEmail::class);
24
        $queryBuilder = $repository->search($form->getData());
25
26
        $paginator = $this->get('azine.email.bundle.pagination');
27
28
        $paginator->setTotalCount($repository->getTotalCount($queryBuilder));
29
30
        $queryBuilder->setMaxResults($paginator->getPageSize())
31
            ->setFirstResult($paginator->getOffset());
32
33
        $emails = $queryBuilder->getQuery()->getResult();
34
        $emailsArray = [];
35
36
        foreach ($emails as $key => $email){
37
38
            $emailsArray[$key]['recipients'] = implode(', ', $email->getRecipients());
39
            $emailsArray[$key]['template'] = $email->getTemplate();
40
            $emailsArray[$key]['sent'] = $email->getSent()->format('Y-m-d H:i:s');
41
            $emailsArray[$key]['variables'] = substr(json_encode($email->getVariables()), 0, 60);
42
            $emailsArray[$key]['token'] = $email->getToken();
43
        }
44
45
        return $this->render('AzineEmailBundle::emailsDashboard.html.twig', ['paginator' => $paginator,
46
            'emails' => $emailsArray, 'form' => $form->createView()]);
47
    }
48
49
    public function getEmailDetailsByTokenAction(Request $request, $token)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        $email = $this->getDoctrine()->getManager()->getRepository(SentEmail::class)
52
            ->findOneByToken($token);
53
54
        if($email instanceof SentEmail){
55
56
            $recipients = implode(', ', $email->getRecipients());
57
            $variables = implode(', ', array_keys($email->getVariables()));
58
59
            return $this->render('AzineEmailBundle::sentEmailDetails.html.twig',
60
                ['email' => $email, 'recipients' => $recipients, 'variables' => $variables]);
61
        }
62
63
        $response = $this->render("AzineEmailBundle::emailNotFound.html.twig");
64
        $response->setStatusCode(404);
65
66
        return $response;
67
    }
68
}
69