Test Failed
Push — master ( bd39d1...7116ad )
by Gabor
08:54
created

AddAction::getTemplateData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 25
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.2
6
 *
7
 * @copyright 2012 - 2019 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Middleware\Action\Admin\ControlPanel\Applications;
15
16
use Exception;
17
use WebHemi\Form\ServiceAdapter\Base\ServiceAdapter as HtmlForm;
18
use WebHemi\Http\ServerRequestInterface;
19
use WebHemi\Http\ResponseInterface;
20
21
/**
22
 * Class AddAction.
23
 */
24
class AddAction extends ListAction
25
{
26
    /**
27
     * Gets template map name or template file path.
28
     *
29
     * @return string
30
     */
31
    public function getTemplateName() : string
32
    {
33
        return 'admin-control-panel-applications-add';
34
    }
35
36
    /**
37
     * Gets template data.
38
     *
39
     * @throws Exception
40
     * @return array
41
     */
42
    public function getTemplateData() : array
43
    {
44
        // TODO complete form
45
        /** @var array $postData */
46
        $postData = $this->request->getParsedBody();
47
        /** @var HtmlForm $form */
48
        $form = $this->applicationFormPreset->getPreset();
49
        $form->loadData($postData);
50
51
        if ($form->validate()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
52
            // TODO validate name
53
            // * in case of domain: no other application with the same domain (== name)
54
            // * in case of directory: no other application with the same path (== name)
55
            //   + no filesystem path within the same path
56
        } else {
57
            throw new Exception('Form validation failed', ResponseInterface::STATUS_BAD_REQUEST);
58
        }
59
60
        $applicationUri = $this->request->getAttribute(ServerRequestInterface::REQUEST_ATTR_APPLICATION_URI);
61
62
        $this->response = $this->response
63
            ->withStatus(ResponseInterface::STATUS_REDIRECT, 'Found')
64
            ->withHeader('Location', $applicationUri.'applications');
65
66
        return [];
67
    }
68
}
69