Completed
Push — master ( 46409b...3f7a4e )
by Mikael
02:13
created

TTextUtilities::getUntilStop()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Anax\Content;
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
    public function getUntilStop($text)
19
    {
20
        $pos = stripos($text, "<!--stop-->");
21
        if ($pos) {
22
            $text = substr($text, 0, $pos);
23
        }
24
        return $text;
25
    }
26
27
28
    /**
29
     * Get text until <!--more--> or all text.
30
     *
31
     * @param string $text with content
32
     *
33
     * @return string with text
34
     */
35
    public function getUntilMore($text)
36
    {
37
        $pos = stripos($text, "<!--more-->");
38
        $hasMore = $pos;
0 ignored issues
show
Unused Code introduced by
$hasMore is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
        if ($pos) {
40
            $text = substr($text, 0, $pos);
41
        }
42
        return $text;
43
    }
44
}
45