Completed
Push — master ( 9b9083...4534a2 )
by Johannes
02:11
created

BlogEntry   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 1
dl 0
loc 88
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getExcerpt() 0 7 2
A getExtend() 0 7 2
A getTags() 0 4 1
A addTag() 0 4 1
A explodeContent() 0 11 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\ContentType;
11
12
use Jolicht\MarkdownCms\Taxonomy\Tag;
13
14
/**
15
 * Blog entry
16
 */
17
class BlogEntry extends Page
18
{
19
    /**
20
     * More separator
21
     *
22
     * @var string
23
     */
24
    const MORE_SEPARATOR = '<!--more-->';
25
26
    /**
27
     * Excerpt
28
     *
29
     * @var string
30
     */
31
    private $excerpt;
32
33
    /**
34
     * Exends
35
     *
36
     * @var string
37
     */
38
    private $extend;
39
40
    /**
41
     * Tags
42
     *
43
     * @var array
44
     */
45
    private $tags = [];
46
47
    /**
48
     * Get excerpt
49
     *
50
     * @return string
51
     */
52
    public function getExcerpt() : string
53
    {
54
        if (null === $this->excerpt) {
55
            $this->explodeContent($this->getContent());
56
        }
57
        return $this->excerpt;
58
    }
59
60
    /**
61
     * Get extend
62
     *
63
     * @return string
64
     */
65
    public function getExtend() : string
66
    {
67
        if (null === $this->excerpt) {
68
            $this->explodeContent($this->getContent());
69
        }
70
        return $this->extend;
71
    }
72
73
    /**
74
     * Get tags
75
     *
76
     * @return array
77
     */
78
    public function getTags() : array
79
    {
80
        return $this->tags;
81
    }
82
83
    /**
84
     * Add tag
85
     *
86
     * @param Tag $tag
87
     */
88
    public function addTag(Tag $tag)
89
    {
90
        $this->tags[] = $tag;
91
    }
92
93
    private function explodeContent(string $content)
94
    {
95
        if (false !== strpos($content, self::MORE_SEPARATOR)) {
96
            $parts = explode(self::MORE_SEPARATOR, $content, 2);
97
            $this->excerpt = trim($parts[0]);
98
            $this->extend = trim($parts[1]);
99
        } else {
100
            $this->excerpt = '';
101
            $this->extend = trim($content);
102
        }
103
    }
104
}