MailformController::showAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 3
b 0
f 0
nc 2
nop 8
dl 0
loc 18
rs 9.9332

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace Qbus\Qbtools\Controller;
3
4
/* * *************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2014 Benjamin Franzke <[email protected], Qbus Werbeagentur GmbH
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 * ************************************************************* */
27
28
/**
29
 * Mailform Controller that wraps the Mailform View Helper.
30
 *
31
 * It is intended to be used via typoscript from a standalone fluid template (e.g. in DCE).
32
 * In a standalone fluid template you need to use instead of
33
 *   <qbtools:mailform recipient="..." sender="..." />
34
 * a typoscript caller, that itself calls this controller, which passes rendering on to the viewhelper:
35
 *   <f:cObject typoscriptObjectPath="tt_content.list.20.qbtools_mailformwrapper"
36
 *   		data="{recipientName: "Name", recipientEmail: "[email protected]"}" />
37
 *
38
 * Note: The tt_content.list.20.qbtools_mailformwrapper is created through the
39
 *       call configurePlugin in this extensions ext_localconf.php.
40
 *
41
 * @todo Extend to be able to be used as a tt_content ctype element.
42
 *
43
 * @deprecated <qbtools:widget.mailform> can be used in a static fluid template nowadays, so this mailform is not useful
44
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
45
 */
46
class MailformController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
47
{
48
    /* Initialize arguments from typoscript cObject context data.
49
     * That is the data that is passes by the fluid f:cObject view helper. */
50
    public function initializeShowAction()
51
    {
52
        $cobj = $this->configurationManager->getContentObject();
53
        foreach ($this->arguments as $argument) {
54
            if (isset($cobj->data[$argument->getName()]) && $cobj->data[$argument->getName()]) {
55
                $argument->setDefaultValue($cobj->data[$argument->getName()]);
56
                $argument->setRequired(false);
57
            }
58
        }
59
    }
60
61
    /**
62
     * @param \string $recipientName
63
     * @param \string $recipientEmail
64
     * @param \string $senderName
65
     * @param \string $senderEmail
66
     * @param \array  $required
67
     * @param \string $formPartial
68
     * @param \string $mailTemplate
69
     * @param \string $property
70
     */
71
    public function showAction($recipientName, $recipientEmail, $senderName = null, $senderEmail = null,
72
            $required = 'firstname,lastname,email,message',
73
            $formPartial = 'Mailform',
74
            $mailTemplate = 'EXT:qbtools/Resources/Private/Templates/Mailform/Mail.txt',
75
            $property = null)
76
    {
77
        $this->view->assign('recipient', array('email' => $recipientEmail, 'name' => $recipientName));
78
        $this->view->assign('required', explode(',', $required));
79
        $this->view->assign('formPartial', $formPartial);
80
        $this->view->assign('mailTemplate', $mailTemplate);
81
        $this->view->assign('property', $property);
82
83
        $this->view->setPartialRootPaths(array('fileadmin/Resources/Private/Partials'));
0 ignored issues
show
Bug introduced by
The method setPartialRootPaths() does not exist on TYPO3\CMS\Extbase\Mvc\View\ViewInterface. It seems like you code against a sub-type of said class. However, the method does not exist in TYPO3\CMS\Extbase\Mvc\View\AbstractView or TYPO3\CMS\Extbase\Mvc\View\JsonView. Are you sure you never get one of those? ( Ignorable by Annotation )

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

83
        $this->view->/** @scrutinizer ignore-call */ 
84
                     setPartialRootPaths(array('fileadmin/Resources/Private/Partials'));
Loading history...
84
85
        if (strlen($senderName) > 0 && strlen($senderEmail) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $senderName can also be of type null; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

85
        if (strlen(/** @scrutinizer ignore-type */ $senderName) > 0 && strlen($senderEmail) > 0) {
Loading history...
86
            $this->view->assign('sender', array('email' => $senderEmail, 'name' => $senderName));
87
        } else {
88
            $this->view->assign('sender', null);
89
        }
90
    }
91
}
92