PageExtendedTrait::getName()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 4
nc 3
nop 1
dl 0
loc 9
ccs 0
cts 4
cp 0
crap 30
rs 9.6111
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
            $names = explode(',', $this->name);
108
109
            return $names[0] ? trim($names[0]) : ($this->name ?: ($this->h1 ?: $this->title));
110
        }
111
112
        return $this->name;
113
    }
114
115
    public function setName(?string $name): self
116
    {
117
        $this->name = $name;
118
119
        return $this;
120
    }
121
}
122