Code Duplication    Length = 71-73 lines in 2 locations

src/WebHemi/Middleware/Action/Website/Directory/CategoryAction.php 1 location

@@ 23-95 (lines=73) @@
20
/**
21
 * Class CategoryAction.
22
 */
23
class CategoryAction extends IndexAction
24
{
25
    /** @var string */
26
    protected $templateName = 'website-post-list';
27
28
    /**
29
     * Gets template map name or template file path.
30
     *
31
     * @return string
32
     */
33
    public function getTemplateName() : string
34
    {
35
        return $this->templateName;
36
    }
37
38
    /**
39
     * Gets template data.
40
     *
41
     * @return array
42
     */
43
    public function getTemplateData() : array
44
    {
45
        $blogPosts = [];
46
        $parameters = $this->getRoutingParameters();
47
        /** @var string $category */
48
        $category = $parameters['uri_parameter'] ?? null;
49
50
        if (!$category) {
51
            throw new RuntimeException('Forbidden', 403);
52
        }
53
54
        /** @var Entity\ApplicationEntity $applicationEntity */
55
        $applicationEntity = $this->getApplicationStorage()
56
            ->getApplicationByName($this->environmentManager->getSelectedApplication());
57
58
        $categoryEntity = $this->getFilesystemCategoryStorage()
59
            ->getFilesystemCategoryByApplicationAndName(
60
                $applicationEntity->getApplicationId(),
61
                $category
62
            );
63
64
        if (!$categoryEntity) {
65
            throw new RuntimeException('Not Found', 404);
66
        }
67
68
        /** @var Entity\Filesystem\FilesystemEntity[] $publications */
69
        $publications = $this->getFilesystemStorage()
70
            ->getPublishedDocuments(
71
                $applicationEntity->getApplicationId(),
72
                [
73
                    'fk_category = ?' => (int)$categoryEntity->getFilesystemCategoryId(),
74
                ]
75
            );
76
77
        if (!$publications) {
78
            $this->templateName = 'website-post-list-empty';
79
        }
80
81
        /** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */
82
        foreach ($publications as $filesystemEntity) {
83
            $blogPosts[] = $this->getBlobPostData($applicationEntity, $filesystemEntity);
84
        }
85
86
        return [
87
            'page' => [
88
                'title' => $categoryEntity->getTitle(),
89
                'type' => 'Categories',
90
            ],
91
            'activeMenu' => $category,
92
            'blogPosts' => $blogPosts,
93
        ];
94
    }
95
}
96

src/WebHemi/Middleware/Action/Website/Directory/TagAction.php 1 location

@@ 23-93 (lines=71) @@
20
/**
21
 * Class TagAction.
22
 */
23
class TagAction extends IndexAction
24
{
25
    /** @var string */
26
    protected $templateName = 'website-post-list';
27
28
    /**
29
     * Gets template map name or template file path.
30
     *
31
     * @return string
32
     */
33
    public function getTemplateName() : string
34
    {
35
        return $this->templateName;
36
    }
37
38
    /**
39
     * Gets template data.
40
     *
41
     * @return array
42
     */
43
    public function getTemplateData() : array
44
    {
45
        $blogPosts = [];
46
        $parameters = $this->getRoutingParameters();
47
        /** @var string $category */
48
        $category = $parameters['uri_parameter'] ?? null;
49
50
        if (!$category) {
51
            throw new RuntimeException('Forbidden', 403);
52
        }
53
54
        /** @var Entity\ApplicationEntity $applicationEntity */
55
        $applicationEntity = $this->getApplicationStorage()
56
            ->getApplicationByName($this->environmentManager->getSelectedApplication());
57
58
        $tagEntity = $this->getFilesystemTagStorage()
59
            ->getFilesystemTagByApplicationAndName(
60
                $applicationEntity->getApplicationId(),
61
                $category
62
            );
63
64
        if (!$tagEntity) {
65
            throw new RuntimeException('Not Found', 404);
66
        }
67
68
        /** @var Entity\Filesystem\FilesystemEntity[] $publications */
69
        $publications = $this->getFilesystemStorage()
70
            ->getFilesystemSetByApplicationAndTag(
71
                $applicationEntity->getApplicationId(),
72
                $tagEntity->getFilesystemTagId()
73
            );
74
75
        if (!$publications) {
76
            $this->templateName = 'website-post-list-empty';
77
        }
78
79
        /** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */
80
        foreach ($publications as $filesystemEntity) {
81
            $blogPosts[] = $this->getBlobPostData($applicationEntity, $filesystemEntity);
82
        }
83
84
        return [
85
            'page' => [
86
                'title' => $tagEntity->getTitle(),
87
                'type' => 'Tags',
88
            ],
89
            'activeMenu' => $category,
90
            'blogPosts' => $blogPosts,
91
        ];
92
    }
93
}
94