Test Failed
Branch lab/data (a414ec)
by Gabor
07:41
created

UserAction::getTemplateData()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 57
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 9.0309
c 0
b 0
f 0
cc 4
eloc 27
nc 3
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Website\Directory;
15
16
use RuntimeException;
17
use WebHemi\Data\Entity;
18
use WebHemi\Middleware\Action\Website\IndexAction;
19
20
/**
21
 * Class UserAction
22
 */
23
class UserAction extends IndexAction
24
{
25
    /**
26
     * Gets template map name or template file path.
27
     *
28
     * @return string
29
     */
30
    public function getTemplateName() : string
31
    {
32
        return 'website-user';
33
    }
34
35
    /**
36
     * Gets template data.
37
     *
38
     * @return array
39
     */
40
    public function getTemplateData() : array
41
    {
42
        $blogPosts = [];
43
        $parameters = $this->getRoutingParameters();
44
45
        $userName = $parameters['basename'] ?? '';
46
47
        if ($parameters['path'] == '/' || empty($userName)) {
48
            throw new RuntimeException('Forbidden', 403);
49
        }
50
51
        /**
52
         * @var Entity\UserEntity $userEntity
53
         */
54
        $userEntity = $this->getUserStorage()
55
            ->getUserByUserName($userName);
56
57
        /**
58
         * @var array $userMeta
59
         */
60
        $userMeta = $this->getUserStorage()
61
            ->getSimpleUserMetaListByUser((int) $userEntity->getUserId());
62
63
        /**
64
         * @var Entity\ApplicationEntity $applicationEntity
65
         */
66
        $applicationEntity = $this->getApplicationStorage()
67
            ->getApplicationByName($this->environmentManager->getSelectedApplication());
68
69
        /**
70
         * @var Entity\EntitySet $publications
71
         */
72
        $publications = $this->getFilesystemStorage()
73
            ->getFilesystemPublishedDocumentListByAuthor(
74
                $applicationEntity->getApplicationId(),
75
                $userEntity->getUserId()
76
            );
77
78
        /**
79
         * @var Entity\FilesystemPublishedDocumentEntity $publishedDocumentEntity
80
         */
81
        foreach ($publications as $publishedDocumentEntity) {
82
            $blogPosts[] = $this->getBlobPostData($applicationEntity, $publishedDocumentEntity);
83
        }
84
85
        return [
86
            'activeMenu' => '',
87
            'user' => [
88
                'userId' => $userEntity->getUserId(),
89
                'userName' => $userEntity->getUserName(),
90
                'url' => $this->environmentManager->getRequestUri(),
91
                'meta' => $userMeta,
92
            ],
93
            'application' => $this->getApplicationData($applicationEntity),
94
            'blogPosts' => $blogPosts,
95
        ];
96
    }
97
}
98