Completed
Push — master ( b83fbc...631ad4 )
by Dominik
22:32
created

AzineEmailController::emailsDashboardAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace Azine\EmailBundle\Controller;
4
5
use Azine\EmailBundle\Entity\Repositories\SentEmailRepository;
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
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * This controller provides actions related to SentEmails stored in the database.
14
 */
15
class AzineEmailController extends Controller
16
{
17
    /**
18
     *  Displays an Emails-Dashboard with filters for each property of SentEmails entity and links to
19
     *  emailDetailsByToken & webView actions for each email
20
     *
21
     * @param Request $request
22
     * @return Response
23
     */
24
    public function emailsDashboardAction(Request $request)
25
    {
26
        $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...
27
        $form->handleRequest($request);
28
        $searchParams = $form->getData();
29
        /** @var SentEmailRepository $repository */
30
        $repository = $this->getDoctrine()->getManager()->getRepository(SentEmail::class);
31
        $query = $repository->search($searchParams);
32
        $pagination = $this->get('knp_paginator')->paginate($query, $request->query->getInt('page', 1));
33
34
        return $this->render('AzineEmailBundle::emailsDashboard.html.twig',
35
            ['form' => $form->createView(), 'pagination' => $pagination ]);
36
    }
37
38
    /**
39
     * Displays an extended view of SentEmail entity searched by a token property
40
     * @param string $token
41
     * @return Response
42
     */
43
    public function emailDetailsByTokenAction(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...
44
    {
45
        $email = $this->getDoctrine()->getManager()->getRepository(SentEmail::class)
0 ignored issues
show
Bug introduced by
The method findOneByToken() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
            ->findOneByToken($token);
47
48
        if($email instanceof SentEmail){
49
50
            $recipients = implode(', ', $email->getRecipients());
51
            $variables = implode(', ', array_keys($email->getVariables()));
52
53
            return $this->render('AzineEmailBundle::sentEmailDetails.html.twig',
54
                ['email' => $email, 'recipients' => $recipients, 'variables' => $variables]);
55
        }
56
57
        // the parameters-array is null => the email is not available in webView
58
        $days = $this->getParameter("azine_email_web_view_retention");
59
        $response = $this->render("AzineEmailBundle:Webview:mail.not.available.html.twig", array('days' => $days));
60
        $response->setStatusCode(404);
61
62
        return $response;
63
    }
64
}
65