Passed
Push — master ( ffd336...c9d1fc )
by Gabor
17:27 queued 10:15
created

PreferencesAction::getTemplateData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 15
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2018 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\Applications;
15
16
use InvalidArgumentException;
17
use WebHemi\Auth\ServiceInterface as AuthInterface;
18
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface;
19
use WebHemi\CSRF\ServiceInterface as CSRFInterface;
20
use WebHemi\Data\Entity\ApplicationEntity;
21
use WebHemi\Data\Storage\ApplicationStorage;
22
use WebHemi\Environment\ServiceInterface as EnvironmentInterface;
23
use WebHemi\Middleware\Action\AbstractMiddlewareAction;
24
25
/**
26
 * Class EditAction
27
 */
28
class EditAction extends AbstractMiddlewareAction
29
{
30
    /**
31
     * @var ConfigurationInterface
32
     */
33
    private $configuration;
34
    /**
35
     * @var AuthInterface
36
     */
37
    private $authAdapter;
38
    /**
39
     * @var EnvironmentInterface
40
     */
41
    private $environmentManager;
42
    /**
43
     * @var ApplicationStorage
44
     */
45
    private $applicationStorage;
46
    /**
47
     * @var CSRFInterface
48
     */
49
    private $csrfAdapter;
50
51
    /**
52
     * EditAction constructor.
53
     *
54
     * @param ConfigurationInterface $configuration
55
     * @param AuthInterface          $authAdapter
56
     * @param EnvironmentInterface   $environmentManager
57
     * @parem ApplicationStorage     $applicationStorage
58
     * @param CSRFInterface          $csrfAdapter
59
     */
60
    public function __construct(
61
        ConfigurationInterface $configuration,
62
        AuthInterface $authAdapter,
63
        EnvironmentInterface $environmentManager,
64
        ApplicationStorage $applicationStorage,
65
        CSRFInterface $csrfAdapter
66
    ) {
67
        $this->configuration = $configuration;
68
        $this->authAdapter = $authAdapter;
69
        $this->environmentManager = $environmentManager;
70
        $this->applicationStorage = $applicationStorage;
71
        $this->csrfAdapter = $csrfAdapter;
72
    }
73
74
    /**
75
     * Gets template map name or template file path.
76
     *
77
     * @return string
78
     */
79
    public function getTemplateName() : string
80
    {
81
        return 'admin-applications-edit';
82
    }
83
84
    /**
85
     * Gets template data.
86
     *
87
     * @return array
88
     */
89
    public function getTemplateData() : array
90
    {
91
        $params = $this->getRoutingParameters();
92
        $applicationName = $params['name'] ?? '';
93
        $applicationEntity = $this->applicationStorage->getApplicationByName($applicationName);
94
95
        if (!$applicationEntity instanceof ApplicationEntity) {
0 ignored issues
show
introduced by
$applicationEntity is always a sub-type of WebHemi\Data\Entity\ApplicationEntity.
Loading history...
96
            throw new InvalidArgumentException(
97
                sprintf('%s is not a valid application name', $applicationName),
98
                404
99
            );
100
        }
101
102
        return [
103
            'application' => $applicationEntity
104
        ];
105
    }
106
}
107