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

StringHelper::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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