GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c96d56...4452ac )
by Chris
02:20
created

PageTitle::getDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 4
cp 0.5
crap 1.125
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Rephlux\PageTitle;
4
5
use Countable;
6
7
/**
8
 * Class PageTitle.
9
 *
10
 * @author Chris van Daele <[email protected]>
11
 */
12
class PageTitle implements Countable
13
{
14
    /**
15
     * Collection of page title parts.
16
     *
17
     * @var array
18
     */
19
    protected $collection = [];
20
21
    /**
22
     * Delimeter string for seperate the page title parts.
23
     *
24
     * @var string
25
     */
26
    protected $delimeter;
27
28
    /**
29
     * The page name to append or prepend to the page title parts.
30
     *
31
     * @var string
32
     */
33
    protected $page_name;
34
35
    /**
36
     * The default text when no page title is set.
37
     *
38
     * @var string
39
     */
40
    protected $default;
41
42
    /**
43
     * @param string $delimeter
44
     * @param string $page_name
45
     * @param string $default
46
     */
47 10
    public function __construct($delimeter = ' | ', $page_name = '', $default = '')
48
    {
49 10
        $this->delimeter = $delimeter;
50 10
        $this->page_name = $page_name;
51 10
        $this->default   = $default;
52 10
    }
53
54
    /**
55
     * @return string
56
     */
57 6
    public function getDelimeter()
58
    {
59 6
        return $this->delimeter;
60
    }
61
62
    /**
63
     * @param string $delimeter
64
     *
65
     * @return $this
66
     */
67 1
    public function setDelimeter($delimeter)
68
    {
69 1
        $this->delimeter = $delimeter;
70
71 1
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 6
    public function getPageName()
78
    {
79 6
        return $this->page_name;
80
    }
81
82
    /**
83
     * @param string $page_name
84
     *
85
     * @return $this
86
     */
87 1
    public function setPageName($page_name)
88
    {
89 1
        $this->page_name = $page_name;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * @return string
96
     */
97 1
    public function getDefault()
98
    {
99 1
        return $this->default;
100
    }
101
102
    /**
103
     * @param string $default
104
     *
105
     * @return $this
106
     */
107 1
    public function setDefault($default)
108
    {
109 1
        $this->default = $default;
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * Add an item to the collection.
116
     *
117
     * @param $item
118
     *
119
     * @return mixed
120
     */
121 6
    public function add($item)
122
    {
123 6
        if (is_array($item)) {
124 3
            return array_map([$this, 'add'], $item);
125
        }
126
127 6
        if (! $item | strlen(trim($item)) === 0) {
128 1
            return false;
129
        }
130
131 5
        $this->collection[] = trim(strip_tags($item));
132 5
    }
133
134
    /**
135
     * Count the collection.
136
     *
137
     * @return int
138
     */
139 7
    public function count()
140
    {
141 7
        return count($this->collection);
142
    }
143
144
    /**
145
     * Get the page title.
146
     *
147
     * @param bool|string $direction
148
     *
149
     * @return string
150
     */
151 6
    public function get($direction = 'regular')
152
    {
153 6
        if ($this->count() == 0) {
154 1
            return $this->default;
155
        }
156
157 5
        if ($direction === 'downward') {
158 1
            $this->collection = array_reverse($this->collection);
159 1
        }
160
161 5
        $this->addPageName();
162
163 5
        if ($direction === 'reverse') {
164 1
            $this->collection = array_reverse($this->collection);
165 1
        }
166
167 5
        return implode($this->getDelimeter(), $this->collection);
168
    }
169
170
    /**
171
     * Add the page name to the collection.
172
     */
173 5
    protected function addPageName()
174
    {
175 5
        if (! empty($this->getPageName()) && ! in_array($this->getPageName(), $this->collection)) {
176 5
            $this->add($this->getPageName());
177 5
        }
178 5
    }
179
}
180