Passed
Push — master ( 542bba...4c863a )
by Dev
13:56
created

PageExtendedTrait::getTitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiedWeb\CMSBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * Page extended: // I may cut this in multiple traits
9
 * - meta no-index
10
 * - Rich Content (meta desc, parentPage, h1, name [to do short link] )
11
 * - author (link)
12
 * - template.
13
 */
14
trait PageExtendedTrait
15
{
16
    /**
17
     * @ORM\Column(type="string", length=255, nullable=true)
18
     */
19
    protected $excrept;
20
21
    /**
22
     * @ORM\Column(type="string", length=50, nullable=true)
23
     */
24
    protected $metaRobots;
25
26
    /**
27
     * @ORM\ManyToOne(targetEntity="PiedWeb\CMSBundle\Entity\PageInterface", inversedBy="childrenPages")
28
     */
29
    protected $parentPage;
30
31
    /**
32
     * @ORM\OneToMany(targetEntity="PiedWeb\CMSBundle\Entity\PageInterface", mappedBy="parentPage")
33
     * @ORM\OrderBy({"id"                                                    = "ASC"})
34
     */
35
    protected $childrenPages;
36
37
    /**
38
     * @ORM\Column(type="string", length=150, nullable=true)
39
     */
40
    protected $name;
41
42
    /**
43
     * @ORM\Column(type="string", length=200, nullable=true)
44
     */
45
    protected $title;
46
47 3
    public function getTitle($elseReturnH1 = false): ?string
48
    {
49 3
        return $this->title ?? (true === $elseReturnH1 ? $this->h1 : null);
50
    }
51
52
    public function setTitle(?string $title): self
53
    {
54
        $this->title = $title;
55
56
        return $this;
57
    }
58
59
    public function __constructExtended()
60
    {
61
    }
62
63
    public function getExcrept(): ?string
64
    {
65
        return $this->excrept;
66
    }
67
68
    public function setExcrept(?string $excrept): self
69
    {
70
        $this->excrept = $excrept;
71
72
        return $this;
73
    }
74
75
    public function getMetaRobots(): ?string
76
    {
77
        return $this->metaRobots;
78
    }
79
80
    public function setMetaRobots(?string $metaRobots): self
81
    {
82
        $this->metaRobots = $metaRobots;
83
84
        return $this;
85
    }
86
87
    public function getParentPage(): ?self
88
    {
89
        return $this->parentPage;
90
    }
91
92
    public function setParentPage(?self $parentPage): self
93
    {
94
        $this->parentPage = $parentPage;
95
96
        return $this;
97
    }
98
99
    public function getChildrenPages()
100
    {
101
        return $this->childrenPages;
102
    }
103
104
    public function getName($firstOnly = false): ?string
105
    {
106
        if ($firstOnly) {
107
            return trim(explode(',', $this->name)[0]) ?? $this->name ?? $this->h1 ?? $this->title;
108
        }
109
        return $this->name;
110
    }
111
112
    public function setName(?string $name): self
113
    {
114
        $this->name = $name;
115
116
        return $this;
117
    }
118
}
119