Completed
Push — master ( 45e66e...a2014d )
by Kacper
03:25
created

StringHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A positionToLine() 0 13 2
A pop() 0 7 1
A normalize() 0 3 1
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Utils;
17
18
class StringHelper
19
{
20 1
    public static function positionToLine($source, $pos)
21
    {
22 1
        $source = substr($source, 0, $pos);
23 1
        $last   = strripos($source, "\n"); // \n is both in UNIX and Windows
24 1
        if ($last !== false) {
25 1
            $last += strlen("\n");
26 1
        }
27
28
        return [
29 1
            'line' => substr_count($source, "\n") + 1,
30 1
            'pos'  => $pos - $last + 1,
31 1
        ];
32
    }
33
34 2
    public static function pop($string, $delimiter = '.')
35
    {
36 2
        $array = explode($delimiter, $string);
37 2
        array_pop($array);
38
39 2
        return implode($delimiter, $array);
40
    }
41
42 10
    public static function normalize($string) {
43 10
        return str_replace("\r\n", "\n", $string);
44
    }
45
}
46