Completed
Push — master ( c02fce...0001a8 )
by Johannes
03:23
created

TagArchiveAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 2
1
<?php
2
/**
3
 * Lichtenwallner  (https://lichtenwallner.at)
4
 *
5
 * @see https://github.com/jolicht/markdown-cms for the canonical source repository
6
 * @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT
7
 * @copyright Copyright (c) Johannes Lichtenwallner
8
 */
9
declare(strict_types = 1);
10
namespace Jolicht\MarkdownCms\Action;
11
12
use Psr\Http\Message\ServerRequestInterface;
13
use Psr\Http\Message\ResponseInterface;
14
use Zend\Diactoros\Response\HtmlResponse;
15
use Jolicht\MarkdownCms\Taxonomy\Tag;
16
17
class TagArchiveAction extends AbstractAction
18
{
19
    /**
20
     * {@inheritDoc}
21
     * @see \Jolicht\MarkdownCms\Action\AbstractAction::__invoke()
22
     */
23
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
24
    {
25
        $markdownCmsConfig = $this->getMarkdownCmsConfig();
26
        $tagId = $request->getAttribute('id');
27
28
        $entries = [];
29
        $entryParser = $this->getEntryParser();
30
        foreach ($markdownCmsConfig['content']['content_types']['blogEntry']['tags'][$tagId] as $id) {
31
            $entries[] = $entryParser($id);
32
        }
33
34
        $data = [
35
            'entries' => $entries,
36
            'tag' => new Tag($tagId)
37
        ];
38
        return new HtmlResponse($this->getTemplateRenderer()->render('app::tag-archive.twig', $data));
39
    }
40
}