Passed
Pull Request — master (#135)
by Romain
03:12
created

ShowEntityEmailController::previewAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Controller\Backend\Manager\Notification;
18
19
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\EntityEmailNotification;
20
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Service\EntityEmailTemplateBuilder;
21
use CuyZ\Notiz\Domain\Property\Email;
22
use Exception;
23
use Throwable;
24
25
class ShowEntityEmailController extends ShowNotificationController
26
{
27
    /**
28
     * @var EntityEmailNotification
29
     */
30
    protected $notification;
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function showAction()
36
    {
37
        parent::showAction();
38
39
        if ($this->notification->hasEventDefinition()) {
40
            $eventDefinition = $this->notification->getEventDefinition();
41
            $emailProperties = $eventDefinition->getPropertyDefinition(Email::class, $this->notification);
42
43
            $this->view->assign('emailProperties', $emailProperties);
44
        }
45
    }
46
47
    /**
48
     * This action is called to show a preview of the shown email notification.
49
     *
50
     * An event is simulated in order to render the original Fluid template used
51
     * by the notification. Example values may be added to simulate fake markers
52
     * in the view.
53
     *
54
     * @return string
55
     */
56
    public function previewAction()
57
    {
58
        try {
59
            return $this->getEmailPreview();
60
        } catch (Throwable $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
        } catch (Exception $e) {
62
            // @PHP7
63
        }
64
65
        return null;
66
    }
67
68
    /**
69
     * This action is used to show an error
70
     */
71
    public function previewErrorAction()
72
    {
73
        return $this->getEmailPreview();
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    protected function getEmailPreview()
80
    {
81
        if (!$this->notification->hasEventDefinition()) {
82
            return $this->notification->getBody();
83
        }
84
85
        /** @var EntityEmailTemplateBuilder $entityEmailTemplateBuilder */
86
        $entityEmailTemplateBuilder = $this->objectManager->get(EntityEmailTemplateBuilder::class, $this->getPreviewPayload());
0 ignored issues
show
Unused Code introduced by
The call to TYPO3\CMS\Extbase\Object...ManagerInterface::get() has too many arguments starting with $this->getPreviewPayload(). ( Ignorable by Annotation )

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

86
        /** @scrutinizer ignore-call */ 
87
        $entityEmailTemplateBuilder = $this->objectManager->get(EntityEmailTemplateBuilder::class, $this->getPreviewPayload());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
87
88
        return $entityEmailTemplateBuilder->getBody();
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getNotificationDefinitionIdentifier()
95
    {
96
        return EntityEmailNotification::getDefinitionIdentifier();
97
    }
98
}
99