Passed
Branch master (0828fa)
by Gabor
03:19
created

IndexAction::getBlobPostData()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 32
nc 2
nop 2
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 WebHemi\Data\StorageInterface;
17
use WebHemi\Data\Entity;
18
use WebHemi\Environment\ServiceInterface as EnvironmentInterface;
19
use WebHemi\Middleware\Action\AbstractMiddlewareAction;
20
use WebHemi\Middleware\Action\Traits;
21
use WebHemi\Data\Traits\StorageInjectorTrait;
22
23
/**
24
 * Class IndexAction.
25
 */
26
class IndexAction extends AbstractMiddlewareAction
27
{
28
    /** @var EnvironmentInterface */
29
    protected $environmentManager;
30
31
    use StorageInjectorTrait;
32
    use Traits\GetPublicationAuthorTrait;
33
    use Traits\GetPublicationPathTrait;
34
    use Traits\GetPublicationTagsTrait;
35
    use Traits\GetPublicationCategoryTrait;
36
37
    /**
38
     * IndexAction constructor.
39
     *
40
     * @param EnvironmentInterface $environmentManager
41
     * @param StorageInterface[] ...$dataStorages
42
     */
43
    public function __construct(EnvironmentInterface $environmentManager, StorageInterface ...$dataStorages)
44
    {
45
        $this->environmentManager = $environmentManager;
46
        $this->addStorageInstances($dataStorages);
0 ignored issues
show
Documentation introduced by
$dataStorages is of type array<integer,array<inte...ata\StorageInterface>>>, but the function expects a array<integer,object<Web...Data\StorageInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
    }
48
49
    /**
50
     * Gets template map name or template file path.
51
     *
52
     * @return string
53
     */
54
    public function getTemplateName() : string
55
    {
56
        return 'website-index';
57
    }
58
59
    /**
60
     * Gets template data.
61
     *
62
     * @return array
63
     */
64
    public function getTemplateData() : array
65
    {
66
        $blogPosts = [];
67
68
        /** @var Entity\ApplicationEntity $applicationEntity */
69
        $applicationEntity = $this->getApplicationStorage()
70
            ->getApplicationByName($this->environmentManager->getSelectedApplication());
71
72
        /** @var Entity\Filesystem\FilesystemEntity[] $publications */
73
        $publications = $this->getFilesystemStorage()
74
            ->getPublishedDocuments($applicationEntity->getApplicationId());
75
76
        /** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */
77
        foreach ($publications as $filesystemEntity) {
78
            $blogPosts[] = $this->getBlobPostData($applicationEntity, $filesystemEntity);
79
        }
80
81
        return [
82
            'activeMenu' => '',
83
            'blogPosts' => $blogPosts,
84
            'fixPost' => $applicationEntity->getIntroduction(),
85
        ];
86
    }
87
88
    /**
89
     * Collets the blog post data
90
     *
91
     * @param Entity\ApplicationEntity $applicationEntity
92
     * @param Entity\Filesystem\FilesystemEntity $filesystemEntity
93
     * @return array
94
     */
95
    protected function getBlobPostData(
96
        Entity\ApplicationEntity $applicationEntity,
97
        Entity\Filesystem\FilesystemEntity $filesystemEntity
98
    ) : array {
99
        /** @var Entity\Filesystem\FilesystemDocumentEntity $documentEntity */
100
        $documentEntity = $this->getFilesystemDocumentStorage()
101
            ->getFilesystemDocumentById($filesystemEntity->getDocumentId());
102
103
        $documentMeta = $this->getFilesystemStorage()
104
            ->getPublicationMeta($filesystemEntity->getFilesystemId());
105
106
        $author = $this->getPublicationAuthor(
107
            $documentEntity->getAuthorId(),
108
            $applicationEntity->getApplicationId()
109
        );
110
        $author['mood'] = [];
111
112
        if (isset($documentMeta['mood_key']) && isset($documentMeta['mood_name'])) {
113
            $author['mood'] = [
114
                $documentMeta['mood_name'],
115
                $documentMeta['mood_key']
116
            ];
117
        }
118
119
        return [
120
            'author' => $author,
121
            'tags' => $this->getPublicationTags(
122
                $applicationEntity->getApplicationId(),
123
                $filesystemEntity->getFilesystemId()
124
            ),
125
            'category' => $this->getPublicationCategory(
126
                $applicationEntity->getApplicationId(),
127
                $filesystemEntity->getCategoryId()
128
            ),
129
            'publishedAt' => $filesystemEntity->getDatePublished(),
130
            'location' => $documentMeta['location'] ?? '',
131
            'summary' => $filesystemEntity->getDescription(),
132
            'illustration' => $documentMeta['illustration'] ?? '',
133
            'path' => $this->getPublicationPath($filesystemEntity),
134
            'title' => $filesystemEntity->getTitle(),
135
            'contentLead' => $documentEntity->getContentLead(),
136
            'contentBody' => $documentEntity->getContentBody()
137
        ];
138
    }
139
}
140