Passed
Push — master ( 380f9e...cfd1fb )
by Gabor
05:22
created

UserAction::getTemplateName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 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\Website;
15
16
use RuntimeException;
17
use WebHemi\Data\Storage\User;
18
use WebHemi\Middleware\Action\AbstractMiddlewareAction;
19
20
/**
21
 * Class UserAction
22
 */
23
class UserAction extends AbstractMiddlewareAction
24
{
25
    /** @var User\UserStorage */
26
    private $userStorage;
27
    /** @var User\UserMetaStorage */
28
    private $userMetaStorage;
29
30
    /**
31
     * UserAction constructor.
32
     *
33
     * @param User\UserStorage $userStorage
34
     * @param User\UserMetaStorage $userMetaStorage
35
     */
36
    public function __construct(User\UserStorage $userStorage, User\UserMetaStorage $userMetaStorage)
37
    {
38
        $this->userStorage = $userStorage;
39
        $this->userMetaStorage = $userMetaStorage;
40
    }
41
42
    /**
43
     * Gets template map name or template file path.
44
     *
45
     * @return string
46
     */
47
    public function getTemplateName() : string
48
    {
49
        return 'website-user';
50
    }
51
52
    /**
53
     * Gets template data.
54
     *
55
     * @return array
56
     */
57
    public function getTemplateData() : array
58
    {
59
        $parameters = $this->getRoutingParameters();
60
        $userName = $parameters['username'] ?? '';
61
62
        $user = $this->userStorage->getUserByUserName($userName);
63
64
        if (!$user) {
65
            throw new RuntimeException(sprintf('User with name "%s" not found.', $userName), 404);
66
        }
67
68
        $userMeta = $this->userMetaStorage->getUserMetaForUserId($user->getUserId(), true);
69
70
        return [
71
            'user' => $user,
72
            'userMeta' => $userMeta
73
        ];
74
    }
75
}
76