Completed
Push — master ( 3f7a4e...acc2f9 )
by Mikael
02:20
created

TTextUtilities::getUntilStop()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Mos\TextFilter;
4
5
/**
6
 * Utilities when working with text.
7
 *
8
 */
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)
19
    {
20 8
        $pos = stripos($text, "<!--stop-->");
21 8
        if ($pos) {
22 2
            $text = substr($text, 0, $pos);
23 2
        }
24 8
        return $text;
25
    }
26
27
28
    /**
29
     * Get text until <!--more--> or all text.
30
     *
31
     * @param string $text with content
32
     *
33
     * @return array with text and boolean if more was detected.
34
     */
35 8
    public function getUntilMore($text)
36
    {
37 8
        $pos = stripos($text, "<!--more-->");
38 8
        $hasMore = $pos;
39 8
        if ($pos) {
40 1
            $text = substr($text, 0, $pos);
41 1
        }
42 8
        return [$text, $hasMore];
43
    }
44
}
45