1 | <?php |
||
9 | trait TTextUtilities |
||
10 | { |
||
11 | /** |
||
12 | * Get text until <!--stop--> or all text. |
||
13 | * |
||
14 | * @param string $text with content |
||
15 | * |
||
16 | * @return string with text |
||
17 | */ |
||
18 | 8 | public function getUntilStop($text) |
|
26 | |||
27 | |||
28 | |||
29 | /** |
||
30 | * Get text until <!--more--> or all text. |
||
31 | * |
||
32 | * @param string $text with content |
||
33 | * |
||
34 | * @return array with text and boolean if more was detected. |
||
35 | */ |
||
36 | 8 | public function getUntilMore($text) |
|
45 | |||
46 | |||
47 | |||
48 | /** |
||
49 | * Wrap HTML element with with start and end. |
||
50 | * |
||
51 | * @param string $text with content |
||
52 | * @param string $tag HTML tag to search for |
||
53 | * @param string $start wrap start part |
||
54 | * @param string $end wrap end part |
||
55 | * @param number $count hits to search for |
||
56 | * |
||
57 | * @return array with text and boolean if more was detected. |
||
58 | */ |
||
59 | public function wrapElementWithStartEnd($text, $tag, $start, $end, $count) |
||
68 | |||
69 | |||
70 | |||
71 | /** |
||
72 | * Wrap content of a HTML element with start and end. |
||
73 | * |
||
74 | * @param string $text with content |
||
75 | * @param string $tag HTML tag to search for |
||
76 | * @param string $start wrap start part |
||
77 | * @param string $end wrap end part |
||
78 | * @param number $count hits to search for |
||
79 | * |
||
80 | * @return array with text and boolean if more was detected. |
||
81 | */ |
||
82 | public function wrapElementContentWithStartEnd($text, $tag, $start, $end, $count) |
||
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * Create a TOC of HTML headings from and to a certain level. |
||
96 | * |
||
97 | * @param string $text with content |
||
98 | * @param integer $start level of headings to use for toc. |
||
99 | * @param integer $stop level of headings to use for toc. |
||
100 | * |
||
101 | * @return array with entries to generate a TOC. |
||
102 | */ |
||
103 | public function createToc($text, $start = 2, $stop = 4) |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * Create a anchor for each header having an id. |
||
131 | * |
||
132 | * @param string $text with content |
||
133 | * @param integer $start level of headings to use. |
||
134 | * @param integer $stop level of headings to use. |
||
135 | * |
||
136 | * @return string with modified text. |
||
137 | */ |
||
138 | public function createAnchor4Header($text, $start = 1, $stop = 4) |
||
149 | |||
150 | |||
151 | |||
152 | /** |
||
153 | * Add baseurl to all relative links. |
||
154 | * |
||
155 | * @param string $text with content. |
||
156 | * @param string $baseurl as string to prepend relative link. |
||
157 | * @param callable $callback Use to create url from route. |
||
158 | * |
||
159 | * @return string with modified text. |
||
160 | */ |
||
161 | public function addBaseurlToRelativeLinks($text, $baseurl, $callback) |
||
174 | |||
175 | |||
176 | |||
177 | /** |
||
178 | * Get content as pure text. |
||
179 | * |
||
180 | * @return string with the pure text. |
||
181 | */ |
||
182 | /* public function GetPureText() { |
||
183 | return preg_replace('/\s+/', ' ', strip_tags($this->GetFilteredData())); |
||
184 | } |
||
185 | */ |
||
186 | |||
187 | |||
188 | |||
189 | /** |
||
190 | * Returns the excerpt of the text with at most the specified amount of characters. |
||
191 | * |
||
192 | * @param int $chars the number of characters to return. |
||
193 | * @param boolean $hard do a hard break at exactly $chars characters or find closest space. |
||
194 | * @return string as the excerpt. |
||
195 | */ |
||
196 | /* public function GetExcerpt($chars=139, $hard=false) { |
||
197 | if(!isset($this->data['data_filtered'])) { |
||
198 | return null; |
||
199 | } |
||
200 | $excerpt = strip_tags($this->data['data_filtered']); |
||
201 | |||
202 | if(strlen($excerpt) > $chars) { |
||
203 | $excerpt = substr($excerpt, 0, $chars-1); |
||
204 | } |
||
205 | |||
206 | if(!$hard) { |
||
207 | $lastSpace = strrpos($excerpt, ' '); |
||
208 | $excerpt = substr($excerpt, 0, $lastSpace); |
||
209 | } |
||
210 | |||
211 | return $excerpt; |
||
212 | } |
||
213 | |||
214 | |||
215 | /** |
||
216 | * Returns the first paragraph ot the text. |
||
217 | * |
||
218 | * @return string as the first paragraph. |
||
219 | */ |
||
220 | /* public function GetFirstParagraph() { |
||
221 | if(!isset($this->data['data_filtered'])) { |
||
222 | return null; |
||
223 | } |
||
224 | $excerpt = $this->data['data_filtered']; |
||
225 | |||
226 | $firstPara = strpos($excerpt, '</p>'); |
||
227 | $excerpt = substr($excerpt, 0, $firstPara + 4); |
||
228 | |||
229 | return $excerpt; |
||
230 | } |
||
231 | */ |
||
232 | } |
||
233 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.